2020-07-17 22:14:46 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-10-31 23:08:13 +01:00
|
|
|
"context"
|
|
|
|
|
2020-07-17 22:14:46 +02:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2024-04-06 00:51:20 +02:00
|
|
|
"github.com/restic/restic/internal/ui/progress"
|
2020-07-17 22:14:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeleteFiles deletes the given fileList of fileType in parallel
|
|
|
|
// it will print a warning if there is an error, but continue deleting the remaining files
|
2024-04-06 00:51:20 +02:00
|
|
|
func DeleteFiles(ctx context.Context, repo restic.Repository, fileList restic.IDSet, fileType restic.FileType, printer progress.Printer) {
|
|
|
|
_ = deleteFiles(ctx, true, repo, fileList, fileType, printer)
|
2020-07-17 22:14:46 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 22:24:43 +02:00
|
|
|
// DeleteFilesChecked deletes the given fileList of fileType in parallel
|
2020-07-17 22:14:46 +02:00
|
|
|
// if an error occurs, it will cancel and return this error
|
2024-04-06 00:51:20 +02:00
|
|
|
func DeleteFilesChecked(ctx context.Context, repo restic.Repository, fileList restic.IDSet, fileType restic.FileType, printer progress.Printer) error {
|
|
|
|
return deleteFiles(ctx, false, repo, fileList, fileType, printer)
|
2020-07-17 22:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// deleteFiles deletes the given fileList of fileType in parallel
|
|
|
|
// if ignoreError=true, it will print a warning if there was an error, else it will abort.
|
2024-04-06 00:51:20 +02:00
|
|
|
func deleteFiles(ctx context.Context, ignoreError bool, repo restic.Repository, fileList restic.IDSet, fileType restic.FileType, printer progress.Printer) error {
|
|
|
|
bar := printer.NewCounter("files deleted")
|
2024-01-20 15:40:09 +01:00
|
|
|
defer bar.Done()
|
|
|
|
|
|
|
|
return restic.ParallelRemove(ctx, repo, fileList, fileType, func(id restic.ID, err error) error {
|
|
|
|
if err != nil {
|
2024-04-06 00:51:20 +02:00
|
|
|
printer.E("unable to remove %v/%v from the repository\n", fileType, id)
|
2024-01-20 15:40:09 +01:00
|
|
|
if !ignoreError {
|
|
|
|
return err
|
2020-08-02 12:16:03 +02:00
|
|
|
}
|
2020-07-17 22:14:46 +02:00
|
|
|
}
|
2024-04-06 00:51:20 +02:00
|
|
|
printer.VV("removed %v/%v\n", fileType, id)
|
2020-08-02 12:16:03 +02:00
|
|
|
return nil
|
2024-01-20 15:40:09 +01:00
|
|
|
}, bar)
|
2020-07-17 22:14:46 +02:00
|
|
|
}
|