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:
Srigovind Nayak
2024-12-01 19:59:11 +05:30
committed by GitHub
parent 2f0049cd6c
commit d7d9af4c9f
9 changed files with 64 additions and 21 deletions

View File

@@ -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])
}
}
}