fix(files): isSharing always return true

This commit is contained in:
hexxa 2021-09-12 17:05:28 +08:00 committed by Hexxa
parent f91723eab7
commit e462c349a5
4 changed files with 22 additions and 17 deletions

View file

@ -102,10 +102,11 @@ func (fi *FileInfoStore) DelSharing(dirPath string) error {
}
func (fi *FileInfoStore) GetSharing(dirPath string) (bool, bool) {
// TODO: add lock
fi.mtx.Lock()
defer fi.mtx.Unlock()
info, err := fi.GetInfo(dirPath)
if err != nil {
// TODO: error is ignored
return false, false
}
return info.IsDir && info.Shared, true

View file

@ -839,8 +839,8 @@ func (h *FileHandlers) IsSharing(c *gin.Context) {
return
}
_, ok := h.deps.FileInfos().GetSharing(dirPath)
if ok {
exist, ok := h.deps.FileInfos().GetSharing(dirPath)
if exist && ok {
c.JSON(q.Resp(200))
} else {
c.JSON(q.Resp(404))

View file

@ -131,7 +131,6 @@ func initDeps(cfg gocfg.ICfg) *depidx.Deps {
queueSize := cfg.GrabInt("Workers.QueueSize")
sleepCyc := cfg.GrabInt("Workers.SleepCyc")
workerCount := cfg.GrabInt("Workers.WorkerCount")
fmt.Println(queueSize, sleepCyc, workerCount)
workers := localworker.NewWorkerPool(queueSize, sleepCyc, workerCount, logger)
workers.Start()

View file

@ -423,18 +423,14 @@ func TestFileHandlers(t *testing.T) {
assertDownloadOK(t, filePath, content, addr, token)
}
i := 0
for filePath := range files {
if i++; i%2 == 0 {
dirPath := filepath.Dir(filePath)
delete(sharedPaths, dirPath)
dirPath := filepath.Dir(filePath)
res, _, errs := cl.DelSharing(dirPath)
if len(errs) > 0 {
t.Fatal(errs)
} else if res.StatusCode != 200 {
t.Fatal(res.StatusCode)
}
res, _, errs := cl.DelSharing(dirPath)
if len(errs) > 0 {
t.Fatal(errs)
} else if res.StatusCode != 200 {
t.Fatal(res.StatusCode)
}
}
@ -446,8 +442,17 @@ func TestFileHandlers(t *testing.T) {
t.Fatal(res.StatusCode)
}
for _, dirPath := range shRes.SharingDirs {
if !sharedPaths[dirPath] {
t.Fatalf("sharing %s not found", dirPath)
if sharedPaths[dirPath] {
t.Fatalf("sharing %s should be deleted", dirPath)
}
}
for dirPath := range sharedPaths {
res, _, errs := cl.IsSharing(dirPath)
if len(errs) > 0 {
t.Fatal(errs)
} else if res.StatusCode != 404 {
t.Fatal(res.StatusCode)
}
}
})