restore: allow deleting a directory to replace it with a file

When the `--delete` option is specified, recursively delete directories
that should be replaced with a file.
This commit is contained in:
Michael Eischer
2024-06-29 20:23:28 +02:00
parent 168fc09d5f
commit f4b15fdd96
6 changed files with 95 additions and 23 deletions

View File

@@ -53,6 +53,8 @@ type fileRestorer struct {
sparse bool
progress *restore.Progress
allowRecursiveDelete bool
dst string
files []*fileInfo
Error func(string, error) error
@@ -63,21 +65,23 @@ func newFileRestorer(dst string,
idx func(restic.BlobType, restic.ID) []restic.PackedBlob,
connections uint,
sparse bool,
allowRecursiveDelete bool,
progress *restore.Progress) *fileRestorer {
// as packs are streamed the concurrency is limited by IO
workerCount := int(connections)
return &fileRestorer{
idx: idx,
blobsLoader: blobsLoader,
filesWriter: newFilesWriter(workerCount),
zeroChunk: repository.ZeroChunk(),
sparse: sparse,
progress: progress,
workerCount: workerCount,
dst: dst,
Error: restorerAbortOnAllErrors,
idx: idx,
blobsLoader: blobsLoader,
filesWriter: newFilesWriter(workerCount, allowRecursiveDelete),
zeroChunk: repository.ZeroChunk(),
sparse: sparse,
progress: progress,
allowRecursiveDelete: allowRecursiveDelete,
workerCount: workerCount,
dst: dst,
Error: restorerAbortOnAllErrors,
}
}
@@ -207,7 +211,7 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error {
}
func (r *fileRestorer) restoreEmptyFileAt(location string) error {
f, err := createFile(r.targetPath(location), 0, false)
f, err := createFile(r.targetPath(location), 0, false, r.allowRecursiveDelete)
if err != nil {
return err
}