Fix locking around deleteFile (fixes #64)
This commit is contained in:
parent
fc6eabea28
commit
b6814241cc
|
@ -199,7 +199,7 @@ func (q *FileQueue) QueuedFiles() (files []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *FileQueue) deleteAt(i int) {
|
func (q *FileQueue) deleteAt(i int) {
|
||||||
q.files = q.files[:i+copy(q.files[i:], q.files[i+1:])]
|
q.files = append(q.files[:i], q.files[i+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *FileQueue) deleteFile(n string) {
|
func (q *FileQueue) deleteFile(n string) {
|
||||||
|
@ -228,7 +228,9 @@ func (q *FileQueue) RemoveAvailable(toRemove string) {
|
||||||
if node == toRemove {
|
if node == toRemove {
|
||||||
q.availability[file] = nodes[:i+copy(nodes[i:], nodes[i+1:])]
|
q.availability[file] = nodes[:i+copy(nodes[i:], nodes[i+1:])]
|
||||||
if len(q.availability[file]) == 0 {
|
if len(q.availability[file]) == 0 {
|
||||||
|
q.fmut.Lock()
|
||||||
q.deleteFile(file)
|
q.deleteFile(file)
|
||||||
|
q.fmut.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -275,3 +275,21 @@ func TestFileQueueThreadHandling(t *testing.T) {
|
||||||
t.Error("Total mismatch; %d != %d", gotTot, total)
|
t.Error("Total mismatch; %d != %d", gotTot, total)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDeleteAt(t *testing.T) {
|
||||||
|
q := FileQueue{}
|
||||||
|
|
||||||
|
for i := 0; i < 4; i++ {
|
||||||
|
q.files = queuedFileList{{name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}}
|
||||||
|
q.deleteAt(i)
|
||||||
|
if l := len(q.files); l != 3 {
|
||||||
|
t.Fatal("deleteAt(%d) failed; %d != 3", i, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
q.files = queuedFileList{{name: "a"}}
|
||||||
|
q.deleteAt(0)
|
||||||
|
if l := len(q.files); l != 0 {
|
||||||
|
t.Fatal("deleteAt(only) failed; %d != 0", l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue