mirror of https://github.com/restic/restic.git
Merge pull request #1885 from restic/create-restore-target
restore: Make sure the target directory exists
This commit is contained in:
commit
73153dbd3f
|
@ -197,6 +197,12 @@ func (res *Restorer) RestoreTo(ctx context.Context, dst string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure the target directory exists
|
||||||
|
err = fs.MkdirAll(dst, 0777) // umask takes care of dir permissions
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "MkdirAll")
|
||||||
|
}
|
||||||
|
|
||||||
idx := restic.NewHardlinkIndex()
|
idx := restic.NewHardlinkIndex()
|
||||||
return res.traverseTree(ctx, dst, string(filepath.Separator), *res.sn.Tree, treeVisitor{
|
return res.traverseTree(ctx, dst, string(filepath.Separator), *res.sn.Tree, treeVisitor{
|
||||||
enterDir: func(node *restic.Node, target, location string) error {
|
enterDir: func(node *restic.Node, target, location string) error {
|
||||||
|
|
|
@ -202,6 +202,16 @@ func TestRestorer(t *testing.T) {
|
||||||
"dir/file": "file in dir",
|
"dir/file": "file in dir",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Snapshot: Snapshot{
|
||||||
|
Nodes: map[string]Node{
|
||||||
|
"topfile": File{"top-level file"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Files: map[string]string{
|
||||||
|
"topfile": "top-level file",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// test cases with invalid/constructed names
|
// test cases with invalid/constructed names
|
||||||
{
|
{
|
||||||
|
@ -273,6 +283,9 @@ func TestRestorer(t *testing.T) {
|
||||||
tempdir, cleanup := rtest.TempDir(t)
|
tempdir, cleanup := rtest.TempDir(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
|
// make sure we're creating a new subdir of the tempdir
|
||||||
|
tempdir = filepath.Join(tempdir, "target")
|
||||||
|
|
||||||
res.SelectFilter = func(item, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
res.SelectFilter = func(item, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
||||||
t.Logf("restore %v to %v", item, dstpath)
|
t.Logf("restore %v to %v", item, dstpath)
|
||||||
if !fs.HasPathPrefix(tempdir, dstpath) {
|
if !fs.HasPathPrefix(tempdir, dstpath) {
|
||||||
|
|
Loading…
Reference in New Issue