mirror of
https://github.com/restic/restic.git
synced 2025-12-14 01:11:49 +00:00
restore: do not delete target if it is a file
This is implicitly achieved by creating the target directory as the first step, which will fail if a file already exist in its place.
This commit is contained in:
@@ -347,6 +347,14 @@ func (res *Restorer) RestoreTo(ctx context.Context, dst string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if !res.opts.DryRun {
|
||||
// ensure that the target directory exists and is actually a directory
|
||||
// Using ensureDir is too aggressive here as it also removes unexpected files
|
||||
if err := fs.MkdirAll(dst, 0700); err != nil {
|
||||
return fmt.Errorf("cannot create target directory: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
idx := NewHardlinkIndex[string]()
|
||||
filerestorer := newFileRestorer(dst, res.repo.LoadBlobsFromPack, res.repo.LookupBlob,
|
||||
res.repo.Connections(), res.opts.Sparse, res.opts.Delete, res.opts.Progress)
|
||||
|
||||
Reference in New Issue
Block a user