Skip to content

Commit

Permalink
Add flag to create parent directories in files cp command
Browse files Browse the repository at this point in the history
Closes ipfs#8289
  • Loading branch information
Jesse Bouwman committed Aug 12, 2021
1 parent 9398d80 commit 155435c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,14 @@ GC'ed.
cmds.StringArg("source", true, false, "Source IPFS or MFS path to copy."),
cmds.StringArg("dest", true, false, "Destination within MFS."),
},
Options: []cmds.Option{
cmds.BoolOption(filesParentsOptionName, "p", "Make parent directories as needed."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
mkParents, _ := req.Options[filesParentsOptionName].(bool)
nd, err := cmdenv.GetNode(env)

prefix, err := getPrefixNew(req)
if err != nil {
return err
}
Expand Down Expand Up @@ -389,6 +395,13 @@ GC'ed.
return fmt.Errorf("cp: cannot get node from path %s: %s", src, err)
}

if mkParents {
err := ensureContainingDirectoryExists(nd.FilesRoot, dst, prefix)
if err != nil {
return err
}
}

err = mfs.PutNode(nd.FilesRoot, dst, node)
if err != nil {
return fmt.Errorf("cp: cannot put node in path %s: %s", dst, err)
Expand Down

0 comments on commit 155435c

Please sign in to comment.