mirror of
https://github.com/restic/restic.git
synced 2025-12-12 06:01:50 +00:00
restorer: fix overwriting of special file types
An attempt to replace an existing file with a hardlink previously ended with a missing file. Remove an existing file before trying to restore a special node. This generalizes the existing behavior for symlinks to all special node types.
This commit is contained in:
@@ -221,6 +221,9 @@ func (res *Restorer) traverseTree(ctx context.Context, target, location string,
|
||||
|
||||
func (res *Restorer) restoreNodeTo(ctx context.Context, node *restic.Node, target, location string) error {
|
||||
debug.Log("restoreNode %v %v %v", node.Name, target, location)
|
||||
if err := fs.Remove(target); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return errors.Wrap(err, "RemoveNode")
|
||||
}
|
||||
|
||||
err := node.CreateAt(ctx, target, res.repo)
|
||||
if err != nil {
|
||||
@@ -242,7 +245,7 @@ func (res *Restorer) restoreNodeMetadataTo(node *restic.Node, target, location s
|
||||
}
|
||||
|
||||
func (res *Restorer) restoreHardlinkAt(node *restic.Node, target, path, location string) error {
|
||||
if err := fs.Remove(path); !os.IsNotExist(err) {
|
||||
if err := fs.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return errors.Wrap(err, "RemoveCreateHardlink")
|
||||
}
|
||||
err := fs.Link(target, path)
|
||||
|
||||
Reference in New Issue
Block a user