move: delete source directory after successful move - fixes #1642

This commit is contained in:
ishuah
2017-11-07 22:21:38 +00:00
committed by Nick Craig-Wood
parent 8c8abfd6dc
commit c65734ee69
3 changed files with 37 additions and 2 deletions
+24
View File
@@ -36,6 +36,8 @@ type syncCopyMove struct {
dstFilesResult chan error // error result of dst listing
dstEmptyDirsMu sync.Mutex // protect dstEmptyDirs
dstEmptyDirs []DirEntry // potentially empty directories
srcEmptyDirsMu sync.Mutex // protect srcEmptyDirs
srcEmptyDirs []DirEntry // potentially empty directories
checkerWg sync.WaitGroup // wait for checkers
toBeChecked ObjectPairChan // checkers channel
transfersWg sync.WaitGroup // wait for transfers
@@ -694,6 +696,20 @@ func (s *syncCopyMove) run() error {
s.processError(deleteEmptyDirectories(s.fdst, s.dstEmptyDirs))
}
}
// if DoMove, delete fsrc directory after
if s.DoMove {
//first delete any subdirectories in fsrc
s.processError(deleteEmptyDirectories(s.fsrc, s.srcEmptyDirs))
//delete fsrc dir
s.processError(func() error {
err := TryRmdir(s.fsrc, "")
if err != nil {
Debugf(logDirName(s.fsrc, ""), "Failed to Rmdir: %v", err)
}
return nil
}())
}
return s.currentError()
}
@@ -747,6 +763,10 @@ func (s *syncCopyMove) SrcOnly(src DirEntry) (recurse bool) {
}
case Directory:
// Do the same thing to the entire contents of the directory
// Record the directory for deletion
s.srcEmptyDirsMu.Lock()
s.srcEmptyDirs = append(s.srcEmptyDirs, src)
s.srcEmptyDirsMu.Unlock()
return true
default:
panic("Bad object in DirEntries")
@@ -774,6 +794,10 @@ func (s *syncCopyMove) Match(dst, src DirEntry) (recurse bool) {
// Do the same thing to the entire contents of the directory
_, ok := dst.(Directory)
if ok {
// Record the src directory for deletion
s.srcEmptyDirsMu.Lock()
s.srcEmptyDirs = append(s.srcEmptyDirs, src)
s.srcEmptyDirsMu.Unlock()
return true
}
// FIXME src is dir, dst is file
+2 -2
View File
@@ -824,7 +824,7 @@ func testServerSideMove(t *testing.T, r *fstest.Run, withFilter bool) {
if withFilter {
fstest.CheckItems(t, r.Fremote, file2)
} else {
fstest.CheckItems(t, r.Fremote)
fstest.CheckRootDir(t, r.Fremote, false)
}
fstest.CheckItems(t, FremoteMove, file2, file1, file3u)
@@ -843,7 +843,7 @@ func testServerSideMove(t *testing.T, r *fstest.Run, withFilter bool) {
fstest.CheckItems(t, FremoteMove, file2)
} else {
fstest.CheckItems(t, FremoteMove2, file2, file1, file3u)
fstest.CheckItems(t, FremoteMove)
fstest.CheckRootDir(t, FremoteMove, false)
}
}