fix(files): isSharing always return true
This commit is contained in:
parent
f91723eab7
commit
e462c349a5
4 changed files with 22 additions and 17 deletions
|
@ -102,10 +102,11 @@ func (fi *FileInfoStore) DelSharing(dirPath string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fi *FileInfoStore) GetSharing(dirPath string) (bool, bool) {
|
func (fi *FileInfoStore) GetSharing(dirPath string) (bool, bool) {
|
||||||
// TODO: add lock
|
fi.mtx.Lock()
|
||||||
|
defer fi.mtx.Unlock()
|
||||||
|
|
||||||
info, err := fi.GetInfo(dirPath)
|
info, err := fi.GetInfo(dirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: error is ignored
|
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
return info.IsDir && info.Shared, true
|
return info.IsDir && info.Shared, true
|
||||||
|
|
|
@ -839,8 +839,8 @@ func (h *FileHandlers) IsSharing(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := h.deps.FileInfos().GetSharing(dirPath)
|
exist, ok := h.deps.FileInfos().GetSharing(dirPath)
|
||||||
if ok {
|
if exist && ok {
|
||||||
c.JSON(q.Resp(200))
|
c.JSON(q.Resp(200))
|
||||||
} else {
|
} else {
|
||||||
c.JSON(q.Resp(404))
|
c.JSON(q.Resp(404))
|
||||||
|
|
|
@ -131,7 +131,6 @@ func initDeps(cfg gocfg.ICfg) *depidx.Deps {
|
||||||
queueSize := cfg.GrabInt("Workers.QueueSize")
|
queueSize := cfg.GrabInt("Workers.QueueSize")
|
||||||
sleepCyc := cfg.GrabInt("Workers.SleepCyc")
|
sleepCyc := cfg.GrabInt("Workers.SleepCyc")
|
||||||
workerCount := cfg.GrabInt("Workers.WorkerCount")
|
workerCount := cfg.GrabInt("Workers.WorkerCount")
|
||||||
fmt.Println(queueSize, sleepCyc, workerCount)
|
|
||||||
|
|
||||||
workers := localworker.NewWorkerPool(queueSize, sleepCyc, workerCount, logger)
|
workers := localworker.NewWorkerPool(queueSize, sleepCyc, workerCount, logger)
|
||||||
workers.Start()
|
workers.Start()
|
||||||
|
|
|
@ -423,11 +423,8 @@ func TestFileHandlers(t *testing.T) {
|
||||||
assertDownloadOK(t, filePath, content, addr, token)
|
assertDownloadOK(t, filePath, content, addr, token)
|
||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
|
||||||
for filePath := range files {
|
for filePath := range files {
|
||||||
if i++; i%2 == 0 {
|
|
||||||
dirPath := filepath.Dir(filePath)
|
dirPath := filepath.Dir(filePath)
|
||||||
delete(sharedPaths, dirPath)
|
|
||||||
|
|
||||||
res, _, errs := cl.DelSharing(dirPath)
|
res, _, errs := cl.DelSharing(dirPath)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
@ -436,7 +433,6 @@ func TestFileHandlers(t *testing.T) {
|
||||||
t.Fatal(res.StatusCode)
|
t.Fatal(res.StatusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// check listSharings
|
// check listSharings
|
||||||
res, shRes, errs = cl.ListSharings()
|
res, shRes, errs = cl.ListSharings()
|
||||||
|
@ -446,8 +442,17 @@ func TestFileHandlers(t *testing.T) {
|
||||||
t.Fatal(res.StatusCode)
|
t.Fatal(res.StatusCode)
|
||||||
}
|
}
|
||||||
for _, dirPath := range shRes.SharingDirs {
|
for _, dirPath := range shRes.SharingDirs {
|
||||||
if !sharedPaths[dirPath] {
|
if sharedPaths[dirPath] {
|
||||||
t.Fatalf("sharing %s not found", 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue