commands/files: use new cmds
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
Overbool committed
Oct 27, 2018 at 03:22 UTC
b80589f98e79e50be1c3fe602e6e161a1aecc85b
1 file changed
+128
-231
core/commands/files.go
+128
-231
@@ -1,7 +1,6 @@
1
package commands
2
3
import (
4
- "bytes"
4
"context"
5
"errors"
6
"fmt"
@@ -11,8 +10,6 @@ import (
10
"sort"
11
"strings"
12
14
- oldcmds "github.com/ipfs/go-ipfs/commands"
15
- lgc "github.com/ipfs/go-ipfs/commands/legacy"
13
core "github.com/ipfs/go-ipfs/core"
14
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
15
e "github.com/ipfs/go-ipfs/core/commands/e"
@@ -56,16 +53,16 @@ operations.
53
cmdkit.BoolOption("f", "flush", "Flush target and ancestors after write.").WithDefault(true),
54
},
55
Subcommands: map[string]*cmds.Command{
59
- "read": lgc.NewCommand(filesReadCmd),
56
+ "read": filesReadCmd,
57
"write": filesWriteCmd,
61
- "mv": lgc.NewCommand(filesMvCmd),
62
- "cp": lgc.NewCommand(filesCpCmd),
63
- "ls": lgc.NewCommand(filesLsCmd),
64
- "mkdir": lgc.NewCommand(filesMkdirCmd),
58
+ "mv": filesMvCmd,
59
+ "cp": filesCpCmd,
60
+ "ls": filesLsCmd,
61
+ "mkdir": filesMkdirCmd,
62
"stat": filesStatCmd,
66
- "rm": lgc.NewCommand(filesRmCmd),
67
- "flush": lgc.NewCommand(filesFlushCmd),
68
- "chcid": lgc.NewCommand(filesChcidCmd),
63
+ "rm": filesRmCmd,
64
+ "flush": filesFlushCmd,
65
+ "chcid": filesChcidCmd,
66
},
67
}
68
@@ -303,7 +300,7 @@ func walkBlock(ctx context.Context, dagserv ipld.DAGService, nd ipld.Node) (bool
300
return local, sizeLocal, nil
301
}
302
306
-var filesCpCmd = &oldcmds.Command{
303
+var filesCpCmd = &cmds.Command{
304
Helptext: cmdkit.HelpText{
305
Tagline: "Copy files into mfs.",
306
},
@@ -311,59 +308,52 @@ var filesCpCmd = &oldcmds.Command{
308
cmdkit.StringArg("source", true, false, "Source object to copy."),
309
cmdkit.StringArg("dest", true, false, "Destination to copy object to."),
310
},
314
- Run: func(req oldcmds.Request, res oldcmds.Response) {
315
- node, err := req.InvocContext().GetNode()
311
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
312
+ nd, err := cmdenv.GetNode(env)
313
if err != nil {
317
- res.SetError(err, cmdkit.ErrNormal)
318
- return
314
+ return err
315
}
316
321
- api, err := req.InvocContext().GetApi()
317
+ api, err := cmdenv.GetApi(env)
318
if err != nil {
323
- res.SetError(err, cmdkit.ErrNormal)
324
- return
319
+ return err
320
}
321
327
- flush, _, _ := req.Option("flush").Bool()
322
+ flush, _ := req.Options["flush"].(bool)
323
329
- src, err := checkPath(req.Arguments()[0])
324
+ src, err := checkPath(req.Arguments[0])
325
if err != nil {
331
- res.SetError(err, cmdkit.ErrNormal)
332
- return
326
+ return err
327
}
328
src = strings.TrimRight(src, "/")
329
336
- dst, err := checkPath(req.Arguments()[1])
330
+ dst, err := checkPath(req.Arguments[1])
331
if err != nil {
338
- res.SetError(err, cmdkit.ErrNormal)
339
- return
332
+ return err
333
}
334
335
if dst[len(dst)-1] == '/' {
336
dst += gopath.Base(src)
337
}
338
346
- nd, err := getNodeFromPath(req.Context(), node, api, src)
339
+ node, err := getNodeFromPath(req.Context, nd, api, src)
340
if err != nil {
348
- res.SetError(fmt.Errorf("cp: cannot get node from path %s: %s", src, err), cmdkit.ErrNormal)
349
- return
341
+ return fmt.Errorf("cp: cannot get node from path %s: %s", src, err)
342
}
343
352
- err = mfs.PutNode(node.FilesRoot, dst, nd)
344
+ err = mfs.PutNode(nd.FilesRoot, dst, node)
345
if err != nil {
354
- res.SetError(fmt.Errorf("cp: cannot put node in path %s: %s", dst, err), cmdkit.ErrNormal)
355
- return
346
+ return fmt.Errorf("cp: cannot put node in path %s: %s", dst, err)
347
}
348
349
if flush {
359
- err := mfs.FlushPath(node.FilesRoot, dst)
350
+ err := mfs.FlushPath(nd.FilesRoot, dst)
351
if err != nil {
361
- res.SetError(fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err), cmdkit.ErrNormal)
362
- return
352
+ return fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err)
353
}
354
}
355
366
- res.SetOutput(nil)
356
+ return nil
357
},
358
}
359
@@ -395,7 +385,7 @@ const (
385
dontSortOptionName = "U"
386
)
387
398
-var filesLsCmd = &oldcmds.Command{
388
+var filesLsCmd = &cmds.Command{
389
Helptext: cmdkit.HelpText{
390
Tagline: "List directories in the local mutable namespace.",
391
ShortDescription: `
@@ -423,43 +413,39 @@ Examples:
413
cmdkit.BoolOption(longOptionName, "Use long listing format."),
414
cmdkit.BoolOption(dontSortOptionName, "Do not sort; list entries in directory order."),
415
},
426
- Run: func(req oldcmds.Request, res oldcmds.Response) {
416
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
417
var arg string
418
429
- if len(req.Arguments()) == 0 {
419
+ if len(req.Arguments) == 0 {
420
arg = "/"
421
} else {
432
- arg = req.Arguments()[0]
422
+ arg = req.Arguments[0]
423
}
424
425
path, err := checkPath(arg)
426
if err != nil {
437
- res.SetError(err, cmdkit.ErrNormal)
438
- return
427
+ return err
428
}
429
441
- nd, err := req.InvocContext().GetNode()
430
+ nd, err := cmdenv.GetNode(env)
431
if err != nil {
443
- res.SetError(err, cmdkit.ErrNormal)
444
- return
432
+ return err
433
}
434
435
fsn, err := mfs.Lookup(nd.FilesRoot, path)
436
if err != nil {
449
- res.SetError(err, cmdkit.ErrNormal)
450
- return
437
+ return err
438
}
439
453
- long, _, _ := req.Option(longOptionName).Bool()
440
+ long, _ := req.Options[longOptionName].(bool)
441
442
switch fsn := fsn.(type) {
443
case *mfs.Directory:
444
if !long {
445
var output []mfs.NodeListing
459
- names, err := fsn.ListNames(req.Context())
446
+ names, err := fsn.ListNames(req.Context)
447
if err != nil {
461
- res.SetError(err, cmdkit.ErrNormal)
462
- return
448
+ return err
449
}
450
451
for _, name := range names {
@@ -467,16 +453,14 @@ Examples:
453
Name: name,
454
})
455
}
470
- res.SetOutput(&filesLsOutput{output})
456
+ return res.Emit(&filesLsOutput{output})
457
} else {
472
- listing, err := fsn.List(req.Context())
458
+ listing, err := fsn.List(req.Context)
459
if err != nil {
474
- res.SetError(err, cmdkit.ErrNormal)
475
- return
460
+ return err
461
}
477
- res.SetOutput(&filesLsOutput{listing})
462
+ return res.Emit(&filesLsOutput{listing})
463
}
479
- return
464
case *mfs.File:
465
_, name := gopath.Split(path)
466
out := &filesLsOutput{[]mfs.NodeListing{{Name: name}}}
@@ -485,58 +469,44 @@ Examples:
469
470
size, err := fsn.Size()
471
if err != nil {
488
- res.SetError(err, cmdkit.ErrNormal)
489
- return
472
+ return err
473
}
474
out.Entries[0].Size = size
475
476
nd, err := fsn.GetNode()
477
if err != nil {
495
- res.SetError(err, cmdkit.ErrNormal)
496
- return
478
+ return err
479
}
480
out.Entries[0].Hash = nd.Cid().String()
481
}
500
- res.SetOutput(out)
501
- return
482
+ return res.Emit(out)
483
default:
503
- res.SetError(errors.New("unrecognized type"), cmdkit.ErrNormal)
484
+ return errors.New("unrecognized type")
485
}
486
},
506
- Marshalers: oldcmds.MarshalerMap{
507
- oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
508
- v, err := unwrapOutput(res.Output())
509
- if err != nil {
510
- return nil, err
511
- }
512
-
513
- out, ok := v.(*filesLsOutput)
514
- if !ok {
515
- return nil, e.TypeErr(out, v)
516
- }
517
-
518
- buf := new(bytes.Buffer)
519
-
520
- noSort, _, _ := res.Request().Option(dontSortOptionName).Bool()
487
+ Encoders: cmds.EncoderMap{
488
+ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *filesLsOutput) error {
489
+ noSort, _ := req.Options[dontSortOptionName].(bool)
490
if !noSort {
491
sort.Slice(out.Entries, func(i, j int) bool {
492
return strings.Compare(out.Entries[i].Name, out.Entries[j].Name) < 0
493
})
494
}
495
527
- long, _, _ := res.Request().Option(longOptionName).Bool()
496
+ long, _ := req.Options[longOptionName].(bool)
497
for _, o := range out.Entries {
498
if long {
499
if o.Type == int(mfs.TDir) {
500
o.Name += "/"
501
}
533
- fmt.Fprintf(buf, "%s\t%s\t%d\n", o.Name, o.Hash, o.Size)
502
+ fmt.Fprintf(w, "%s\t%s\t%d\n", o.Name, o.Hash, o.Size)
503
} else {
535
- fmt.Fprintf(buf, "%s\n", o.Name)
504
+ fmt.Fprintf(w, "%s\n", o.Name)
505
}
506
}
538
- return buf, nil
539
- },
507
+
508
+ return nil
509
+ }),
510
},
511
Type: filesLsOutput{},
512
}
@@ -546,7 +516,7 @@ const (
516
filesCountOptionName = "count"
517
)
518
549
-var filesReadCmd = &oldcmds.Command{
519
+var filesReadCmd = &cmds.Command{
520
Helptext: cmdkit.HelpText{
521
Tagline: "Read a file in a given mfs.",
522
ShortDescription: `
@@ -567,81 +537,62 @@ Examples:
537
cmdkit.Int64Option(filesOffsetOptionName, "o", "Byte offset to begin reading from."),
538
cmdkit.Int64Option(filesCountOptionName, "n", "Maximum number of bytes to read."),
539
},
570
- Run: func(req oldcmds.Request, res oldcmds.Response) {
571
- n, err := req.InvocContext().GetNode()
540
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
541
+ nd, err := cmdenv.GetNode(env)
542
if err != nil {
573
- res.SetError(err, cmdkit.ErrNormal)
574
- return
543
+ return err
544
}
545
577
- path, err := checkPath(req.Arguments()[0])
546
+ path, err := checkPath(req.Arguments[0])
547
if err != nil {
579
- res.SetError(err, cmdkit.ErrNormal)
580
- return
548
+ return err
549
}
550
583
- fsn, err := mfs.Lookup(n.FilesRoot, path)
551
+ fsn, err := mfs.Lookup(nd.FilesRoot, path)
552
if err != nil {
585
- res.SetError(err, cmdkit.ErrNormal)
586
- return
553
+ return err
554
}
555
556
fi, ok := fsn.(*mfs.File)
557
if !ok {
591
- res.SetError(fmt.Errorf("%s was not a file", path), cmdkit.ErrNormal)
592
- return
558
+ return fmt.Errorf("%s was not a file", path)
559
}
560
561
rfd, err := fi.Open(mfs.OpenReadOnly, false)
562
if err != nil {
597
- res.SetError(err, cmdkit.ErrNormal)
598
- return
563
+ return err
564
}
565
566
defer rfd.Close()
567
603
- offset, _, err := req.Option(offsetOptionName).Int64()
604
- if err != nil {
605
- res.SetError(err, cmdkit.ErrNormal)
606
- return
607
- }
568
+ offset, _ := req.Options[offsetOptionName].(int64)
569
if offset < 0 {
609
- res.SetError(fmt.Errorf("cannot specify negative offset"), cmdkit.ErrNormal)
610
- return
570
+ return fmt.Errorf("cannot specify negative offset")
571
}
572
573
filen, err := rfd.Size()
574
if err != nil {
615
- res.SetError(err, cmdkit.ErrNormal)
616
- return
575
+ return err
576
}
577
578
if int64(offset) > filen {
620
- res.SetError(fmt.Errorf("offset was past end of file (%d > %d)", offset, filen), cmdkit.ErrNormal)
621
- return
579
+ return fmt.Errorf("offset was past end of file (%d > %d)", offset, filen)
580
}
581
582
_, err = rfd.Seek(int64(offset), io.SeekStart)
583
if err != nil {
626
- res.SetError(err, cmdkit.ErrNormal)
627
- return
584
+ return err
585
}
586
630
- var r io.Reader = &contextReaderWrapper{R: rfd, ctx: req.Context()}
631
- count, found, err := req.Option(filesCountOptionName).Int64()
632
- if err != nil {
633
- res.SetError(err, cmdkit.ErrNormal)
634
- return
635
- }
587
+ var r io.Reader = &contextReaderWrapper{R: rfd, ctx: req.Context}
588
+ count, found := req.Options[filesCountOptionName].(int64)
589
if found {
590
if count < 0 {
638
- res.SetError(fmt.Errorf("cannot specify negative 'count'"), cmdkit.ErrNormal)
639
- return
591
+ return fmt.Errorf("cannot specify negative 'count'")
592
}
593
r = io.LimitReader(r, int64(count))
594
}
643
-
644
- res.SetOutput(r)
595
+ return res.Emit(r)
596
},
597
}
598
@@ -658,7 +609,7 @@ func (crw *contextReaderWrapper) Read(b []byte) (int, error) {
609
return crw.R.CtxReadFull(crw.ctx, b)
610
}
611
661
-var filesMvCmd = &oldcmds.Command{
612
+var filesMvCmd = &cmds.Command{
613
Helptext: cmdkit.HelpText{
614
Tagline: "Move files.",
615
ShortDescription: `
@@ -675,31 +626,22 @@ Example:
626
cmdkit.StringArg("source", true, false, "Source file to move."),
627
cmdkit.StringArg("dest", true, false, "Destination path for file to be moved to."),
628
},
678
- Run: func(req oldcmds.Request, res oldcmds.Response) {
679
- n, err := req.InvocContext().GetNode()
629
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
630
+ nd, err := cmdenv.GetNode(env)
631
if err != nil {
681
- res.SetError(err, cmdkit.ErrNormal)
682
- return
632
+ return err
633
}
634
685
- src, err := checkPath(req.Arguments()[0])
635
+ src, err := checkPath(req.Arguments[0])
636
if err != nil {
687
- res.SetError(err, cmdkit.ErrNormal)
688
- return
689
- }
690
- dst, err := checkPath(req.Arguments()[1])
691
- if err != nil {
692
- res.SetError(err, cmdkit.ErrNormal)
693
- return
637
+ return err
638
}
695
-
696
- err = mfs.Mv(n.FilesRoot, src, dst)
639
+ dst, err := checkPath(req.Arguments[1])
640
if err != nil {
698
- res.SetError(err, cmdkit.ErrNormal)
699
- return
641
+ return err
642
}
643
702
- res.SetOutput(nil)
644
+ return mfs.Mv(nd.FilesRoot, src, dst)
645
},
646
}
647
@@ -849,7 +791,7 @@ stat' on the file or any of its ancestors.
791
},
792
}
793
852
-var filesMkdirCmd = &oldcmds.Command{
794
+var filesMkdirCmd = &cmds.Command{
795
Helptext: cmdkit.HelpText{
796
Tagline: "Make directories.",
797
ShortDescription: `
@@ -875,26 +817,23 @@ Examples:
817
cidVersionOption,
818
hashOption,
819
},
878
- Run: func(req oldcmds.Request, res oldcmds.Response) {
879
- n, err := req.InvocContext().GetNode()
820
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
821
+ n, err := cmdenv.GetNode(env)
822
if err != nil {
881
- res.SetError(err, cmdkit.ErrNormal)
882
- return
823
+ return err
824
}
825
885
- dashp, _, _ := req.Option(filesParentsOptionName).Bool()
886
- dirtomake, err := checkPath(req.Arguments()[0])
826
+ dashp, _ := req.Options[filesParentsOptionName].(bool)
827
+ dirtomake, err := checkPath(req.Arguments[0])
828
if err != nil {
888
- res.SetError(err, cmdkit.ErrNormal)
889
- return
829
+ return err
830
}
831
892
- flush, _, _ := req.Option(filesFlushOptionName).Bool()
832
+ flush, _ := req.Options[filesFlushOptionName].(bool)
833
834
prefix, err := getPrefix(req)
835
if err != nil {
896
- res.SetError(err, cmdkit.ErrNormal)
897
- return
836
+ return err
837
}
838
root := n.FilesRoot
839
@@ -903,16 +842,12 @@ Examples:
842
Flush: flush,
843
CidBuilder: prefix,
844
})
906
- if err != nil {
907
- res.SetError(err, cmdkit.ErrNormal)
908
- return
909
- }
845
911
- res.SetOutput(nil)
846
+ return err
847
},
848
}
849
915
-var filesFlushCmd = &oldcmds.Command{
850
+var filesFlushCmd = &cmds.Command{
851
Helptext: cmdkit.HelpText{
852
Tagline: "Flush a given path's data to disk.",
853
ShortDescription: `
@@ -923,29 +858,22 @@ are run with the '--flush=false'.
858
Arguments: []cmdkit.Argument{
859
cmdkit.StringArg("path", false, false, "Path to flush. Default: '/'."),
860
},
926
- Run: func(req oldcmds.Request, res oldcmds.Response) {
927
- nd, err := req.InvocContext().GetNode()
861
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
862
+ nd, err := cmdenv.GetNode(env)
863
if err != nil {
929
- res.SetError(err, cmdkit.ErrNormal)
930
- return
864
+ return err
865
}
866
867
path := "/"
934
- if len(req.Arguments()) > 0 {
935
- path = req.Arguments()[0]
936
- }
937
-
938
- err = mfs.FlushPath(nd.FilesRoot, path)
939
- if err != nil {
940
- res.SetError(err, cmdkit.ErrNormal)
941
- return
868
+ if len(req.Arguments) > 0 {
869
+ path = req.Arguments[0]
870
}
871
944
- res.SetOutput(nil)
872
+ return mfs.FlushPath(nd.FilesRoot, path)
873
},
874
}
875
948
-var filesChcidCmd = &oldcmds.Command{
876
+var filesChcidCmd = &cmds.Command{
877
Helptext: cmdkit.HelpText{
878
Tagline: "Change the cid version or hash function of the root node of a given path.",
879
ShortDescription: `
@@ -959,33 +887,25 @@ Change the cid version or hash function of the root node of a given path.
887
cidVersionOption,
888
hashOption,
889
},
962
- Run: func(req oldcmds.Request, res oldcmds.Response) {
963
- nd, err := req.InvocContext().GetNode()
890
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
891
+ nd, err := cmdenv.GetNode(env)
892
if err != nil {
965
- res.SetError(err, cmdkit.ErrNormal)
966
- return
893
+ return err
894
}
895
896
path := "/"
970
- if len(req.Arguments()) > 0 {
971
- path = req.Arguments()[0]
897
+ if len(req.Arguments) > 0 {
898
+ path = req.Arguments[0]
899
}
900
974
- flush, _, _ := req.Option(filesFlushOptionName).Bool()
901
+ flush, _ := req.Options[filesFlushOptionName].(bool)
902
903
prefix, err := getPrefix(req)
904
if err != nil {
978
- res.SetError(err, cmdkit.ErrNormal)
979
- return
980
- }
981
-
982
- err = updatePath(nd.FilesRoot, path, prefix, flush)
983
- if err != nil {
984
- res.SetError(err, cmdkit.ErrNormal)
985
- return
905
+ return err
906
}
907
988
- res.SetOutput(nil)
908
+ return updatePath(nd.FilesRoot, path, prefix, flush)
909
},
910
}
911
@@ -1013,7 +933,7 @@ func updatePath(rt *mfs.Root, pth string, builder cid.Builder, flush bool) error
933
return nil
934
}
935
1016
-var filesRmCmd = &oldcmds.Command{
936
+var filesRmCmd = &cmds.Command{
937
Helptext: cmdkit.HelpText{
938
Tagline: "Remove a file.",
939
ShortDescription: `
@@ -1035,24 +955,19 @@ Remove files or directories.
955
cmdkit.BoolOption("recursive", "r", "Recursively remove directories."),
956
cmdkit.BoolOption("force", "Forcibly remove target at path; implies -r for directories"),
957
},
1038
- Run: func(req oldcmds.Request, res oldcmds.Response) {
1039
- defer res.SetOutput(nil)
1040
-
1041
- nd, err := req.InvocContext().GetNode()
958
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
959
+ nd, err :=cmdenv.GetNode(env)
960
if err != nil {
1043
- res.SetError(err, cmdkit.ErrNormal)
1044
- return
961
+ return err
962
}
963
1047
- path, err := checkPath(req.Arguments()[0])
964
+ path, err := checkPath(req.Arguments[0])
965
if err != nil {
1049
- res.SetError(err, cmdkit.ErrNormal)
1050
- return
966
+ return err
967
}
968
969
if path == "/" {
1054
- res.SetError(fmt.Errorf("cannot delete root"), cmdkit.ErrNormal)
1055
- return
970
+ return fmt.Errorf("cannot delete root")
971
}
972
973
// 'rm a/b/c/' will fail unless we trim the slash at the end
@@ -1063,66 +978,48 @@ Remove files or directories.
978
dir, name := gopath.Split(path)
979
parent, err := mfs.Lookup(nd.FilesRoot, dir)
980
if err != nil {
1066
- res.SetError(fmt.Errorf("parent lookup: %s", err), cmdkit.ErrNormal)
1067
- return
981
+ return fmt.Errorf("parent lookup: %s", err)
982
}
983
984
pdir, ok := parent.(*mfs.Directory)
985
if !ok {
1072
- res.SetError(fmt.Errorf("no such file or directory: %s", path), cmdkit.ErrNormal)
1073
- return
986
+ return fmt.Errorf("no such file or directory: %s", path)
987
}
988
1076
- var success bool
1077
- defer func() {
1078
- if success {
1079
- err := pdir.Flush()
1080
- if err != nil {
1081
- res.SetError(err, cmdkit.ErrNormal)
1082
- return
1083
- }
1084
- }
1085
- }()
1086
-
989
// if '--force' specified, it will remove anything else,
990
// including file, directory, corrupted node, etc
1089
- force, _, _ := req.Option("force").Bool()
991
+ force, _ := req.Options["force"].(bool)
992
if force {
993
err := pdir.Unlink(name)
994
if err != nil {
1093
- res.SetError(err, cmdkit.ErrNormal)
1094
- return
995
+ return err
996
}
997
1097
- success = true
1098
- return
998
+ return pdir.Flush()
999
}
1000
1001
// get child node by name, when the node is corrupted and nonexistent,
1002
// it will return specific error.
1003
child, err := pdir.Child(name)
1004
if err != nil {
1105
- res.SetError(err, cmdkit.ErrNormal)
1106
- return
1005
+ return err
1006
}
1007
1109
- dashr, _, _ := req.Option("r").Bool()
1008
+ dashr, _ := req.Options["r"].(bool)
1009
1010
switch child.(type) {
1011
case *mfs.Directory:
1012
if !dashr {
1114
- res.SetError(fmt.Errorf("%s is a directory, use -r to remove directories", path), cmdkit.ErrNormal)
1115
- return
1013
+ return fmt.Errorf("%s is a directory, use -r to remove directories", path)
1014
}
1015
}
1016
1017
err = pdir.Unlink(name)
1018
if err != nil {
1121
- res.SetError(err, cmdkit.ErrNormal)
1122
- return
1019
+ return err
1020
}
1021
1125
- success = true
1022
+ return pdir.Flush()
1023
},
1024
}
1025
@@ -1155,9 +1052,9 @@ func getPrefixNew(req *cmds.Request) (cid.Builder, error) {
1052
return &prefix, nil
1053
}
1054
1158
-func getPrefix(req oldcmds.Request) (cid.Builder, error) {
1159
- cidVer, cidVerSet, _ := req.Option(filesCidVersionOptionName).Int()
1160
- hashFunStr, hashFunSet, _ := req.Option(filesHashOptionName).String()
1055
+func getPrefix(req *cmds.Request) (cid.Builder, error) {
1056
+ cidVer, cidVerSet := req.Options[filesCidVersionOptionName].(int)
1057
+ hashFunStr, hashFunSet := req.Options[filesHashOptionName].(string)
1058
1059
if !cidVerSet && !hashFunSet {
1060
return nil, nil