mirror of
https://github.com/restic/restic.git
synced 2025-12-12 05:42:28 +00:00
ui: restore --delete indicates number of deleted files (#5100)
* ui: restore --delete indicates number of deleted files * adds new field `FilesDeleted` to the State struct, JSON and text progress updaters * increment FilesDeleted count when ReportedDeletedFile * ui: collect the files to be deleted, delete, then update the count post deletion * docs: update scripting output fields for restore command ui: report deleted directories and refactor function name to ReportDeletion
This commit is contained in:
@@ -511,12 +511,30 @@ func (res *Restorer) removeUnexpectedFiles(ctx context.Context, target, location
|
||||
selectedForRestore, _ := res.SelectFilter(nodeLocation, false)
|
||||
// only delete files that were selected for restore
|
||||
if selectedForRestore {
|
||||
res.opts.Progress.ReportDeletedFile(nodeLocation)
|
||||
// First collect all files that will be deleted
|
||||
var filesToDelete []string
|
||||
err := filepath.Walk(nodeTarget, func(path string, _ os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filesToDelete = append(filesToDelete, path)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !res.opts.DryRun {
|
||||
// Perform the deletion
|
||||
if err := fs.RemoveAll(nodeTarget); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Report paths as deleted only after successful removal
|
||||
for i := len(filesToDelete) - 1; i >= 0; i-- {
|
||||
res.opts.Progress.ReportDeletion(filesToDelete[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user