Skip to content

Commit

Permalink
Fix -removeLocal being broken
Browse files Browse the repository at this point in the history
  • Loading branch information
wilriker committed Jul 30, 2019
1 parent e33fc4f commit 611c228
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions commands/backup.go
Expand Up @@ -221,9 +221,9 @@ func (b *backup) isManagedDirectory(basePath string, f os.FileInfo) bool {
func (b *backup) removeDeletedFiles(fl *librfm.Filelist, outDir string) error {

// Pseudo hash-set of known remote filenames
existingFiles := make(map[string]struct{})
existingFiles := make(map[string]bool)
for _, f := range fl.Files {
existingFiles[f.Name] = struct{}{}
existingFiles[f.Name] = true
}

files, err := ioutil.ReadDir(outDir)
Expand All @@ -232,17 +232,21 @@ func (b *backup) removeDeletedFiles(fl *librfm.Filelist, outDir string) error {
}

for _, f := range files {
if _, exists := existingFiles[f.Name()]; !exists {
if !existingFiles[f.Name()] {

// Skip directories not managed by us as well as our marker file
if !b.isManagedDirectory(outDir, f) || f.Name() == managedDirMarker {
if (f.IsDir() && !b.isManagedDirectory(outDir, f)) || f.Name() == managedDirMarker {
continue
}
if err := os.RemoveAll(filepath.Join(outDir, f.Name())); err != nil {
return err
}
if b.o.verbose {
log.Println(" Removed: ", f.Name())
marker := fileMarker
if f.IsDir() {
marker = dirMarker
}
log.Println(" Removed: ", marker, f.Name())
}
}
}
Expand Down

0 comments on commit 611c228

Please sign in to comment.