@cryptotaxi247 / kubo / commits / 155435cb3

Add flag to create parent directories in files cp command

Closes #8289

Jesse Bouwman committed Aug 12, 2021 at 09:23 UTC 155435cb35aa783574c4c9b420fdd0ead8e85022
1 file changed +13
core/commands/files.go
+13
@@ -356,8 +356,14 @@ GC'ed.
356 cmds.StringArg("source", true, false, "Source IPFS or MFS path to copy."),
357 cmds.StringArg("dest", true, false, "Destination within MFS."),
358 },
359 + Options: []cmds.Option{
360 + cmds.BoolOption(filesParentsOptionName, "p", "Make parent directories as needed."),
361 + },
362 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
363 + mkParents, _ := req.Options[filesParentsOptionName].(bool)
364 nd, err := cmdenv.GetNode(env)
365 +
366 + prefix, err := getPrefixNew(req)
367 if err != nil {
368 return err
369 }
@@ -389,6 +395,13 @@ GC'ed.
395 return fmt.Errorf("cp: cannot get node from path %s: %s", src, err)
396 }
397
398 + if mkParents {
399 + err := ensureContainingDirectoryExists(nd.FilesRoot, dst, prefix)
400 + if err != nil {
401 + return err
402 + }
403 + }
404 +
405 err = mfs.PutNode(nd.FilesRoot, dst, node)
406 if err != nil {
407 return fmt.Errorf("cp: cannot put node in path %s: %s", dst, err)