add flush option to mkdir
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Dec 18, 2015 at 22:00 UTC
e3769dfb5a7a030a7a053c84f4871d12f182a1a0
1 file changed
+26
-11
core/commands/files/files.go
+26
-11
@@ -29,6 +29,9 @@ var FilesCmd = &cmds.Command{
29
Files is an API for manipulating ipfs objects as if they were a unix filesystem.
30
`,
31
},
32
+ Options: []cmds.Option{
33
+ cmds.BoolOption("f", "flush", "flush target and ancestors after write (default: true)"),
34
+ },
35
Subcommands: map[string]*cmds.Command{
36
"read": FilesReadCmd,
37
"write": FilesWriteCmd,
@@ -460,7 +463,6 @@ Warning:
463
cmds.BoolOption("e", "create", "create the file if it does not exist"),
464
cmds.BoolOption("t", "truncate", "truncate the file before writing"),
465
cmds.IntOption("n", "count", "maximum number of bytes to read"),
463
- cmds.BoolOption("f", "flush", "flush file and ancestors after write (default: true)"),
466
},
467
Run: func(req cmds.Request, res cmds.Response) {
468
path, err := checkPath(req.Arguments()[0])
@@ -482,6 +484,16 @@ Warning:
484
return
485
}
486
487
+ offset, _, err := req.Option("offset").Int()
488
+ if err != nil {
489
+ res.SetError(err, cmds.ErrNormal)
490
+ return
491
+ }
492
+ if offset < 0 {
493
+ res.SetError(fmt.Errorf("cannot have negative write offset"), cmds.ErrNormal)
494
+ return
495
+ }
496
+
497
fi, err := getFileHandle(nd.FilesRoot, path, create)
498
if err != nil {
499
res.SetError(err, cmds.ErrNormal)
@@ -501,16 +513,6 @@ Warning:
513
}
514
}
515
504
- offset, _, err := req.Option("offset").Int()
505
- if err != nil {
506
- res.SetError(err, cmds.ErrNormal)
507
- return
508
- }
509
- if offset < 0 {
510
- res.SetError(fmt.Errorf("cannot have negative write offset"), cmds.ErrNormal)
511
- return
512
- }
513
-
516
count, countfound, err := req.Option("count").Int()
517
if err != nil {
518
res.SetError(err, cmds.ErrNormal)
@@ -589,6 +591,19 @@ Examples:
591
res.SetError(err, cmds.ErrNormal)
592
return
593
}
594
+
595
+ flush, found, _ := req.Option("flush").Bool()
596
+ if !found {
597
+ flush = true
598
+ }
599
+
600
+ if flush {
601
+ err := n.FilesRoot.Flush()
602
+ if err != nil {
603
+ res.SetError(err, cmds.ErrNormal)
604
+ return
605
+ }
606
+ }
607
},
608
}
609