lib/model: Check dir before deletion when pulling (#6741)
This commit is contained in:
@@ -674,6 +674,8 @@ func TestIssue3164(t *testing.T) {
|
||||
Name: "issue3164",
|
||||
}
|
||||
|
||||
must(t, f.scanSubdirs(nil))
|
||||
|
||||
matcher := ignore.New(ffs)
|
||||
must(t, matcher.Parse(bytes.NewBufferString("(?d)oktodelete"), ""))
|
||||
f.ignores = matcher
|
||||
@@ -767,9 +769,10 @@ func TestDeleteIgnorePerms(t *testing.T) {
|
||||
must(t, err)
|
||||
ffs.Chmod(name, 0600)
|
||||
scanChan := make(chan string)
|
||||
dbUpdateChan := make(chan dbUpdateJob)
|
||||
finished := make(chan struct{})
|
||||
go func() {
|
||||
err = f.checkToBeDeleted(fi, scanChan)
|
||||
err = f.checkToBeDeleted(fi, fi, true, dbUpdateDeleteFile, dbUpdateChan, scanChan)
|
||||
close(finished)
|
||||
}()
|
||||
select {
|
||||
@@ -1055,6 +1058,35 @@ func TestPullCtxCancel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullDeleteUnscannedDir(t *testing.T) {
|
||||
m, f := setupSendReceiveFolder()
|
||||
defer cleanupSRFolder(f, m)
|
||||
ffs := f.Filesystem()
|
||||
|
||||
dir := "foobar"
|
||||
must(t, ffs.MkdirAll(dir, 0777))
|
||||
fi := protocol.FileInfo{
|
||||
Name: dir,
|
||||
}
|
||||
|
||||
scanChan := make(chan string, 1)
|
||||
dbUpdateChan := make(chan dbUpdateJob, 1)
|
||||
|
||||
f.deleteDir(fi, f.fset.Snapshot(), dbUpdateChan, scanChan)
|
||||
|
||||
if _, err := ffs.Stat(dir); fs.IsNotExist(err) {
|
||||
t.Error("directory has been deleted")
|
||||
}
|
||||
select {
|
||||
case toScan := <-scanChan:
|
||||
if toScan != dir {
|
||||
t.Errorf("expected %v to be scanned, got %v", dir, toScan)
|
||||
}
|
||||
default:
|
||||
t.Error("nothing was scheduled for scanning")
|
||||
}
|
||||
}
|
||||
|
||||
func cleanupSharedPullerState(s *sharedPullerState) {
|
||||
s.mut.Lock()
|
||||
defer s.mut.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user