提交 e3769dfb 作者: Jeromy

add flush option to mkdir

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 56982b4b
......@@ -29,6 +29,9 @@ var FilesCmd = &cmds.Command{
Files is an API for manipulating ipfs objects as if they were a unix filesystem.
`,
},
Options: []cmds.Option{
cmds.BoolOption("f", "flush", "flush target and ancestors after write (default: true)"),
},
Subcommands: map[string]*cmds.Command{
"read": FilesReadCmd,
"write": FilesWriteCmd,
......@@ -460,7 +463,6 @@ Warning:
cmds.BoolOption("e", "create", "create the file if it does not exist"),
cmds.BoolOption("t", "truncate", "truncate the file before writing"),
cmds.IntOption("n", "count", "maximum number of bytes to read"),
cmds.BoolOption("f", "flush", "flush file and ancestors after write (default: true)"),
},
Run: func(req cmds.Request, res cmds.Response) {
path, err := checkPath(req.Arguments()[0])
......@@ -482,6 +484,16 @@ Warning:
return
}
offset, _, err := req.Option("offset").Int()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if offset < 0 {
res.SetError(fmt.Errorf("cannot have negative write offset"), cmds.ErrNormal)
return
}
fi, err := getFileHandle(nd.FilesRoot, path, create)
if err != nil {
res.SetError(err, cmds.ErrNormal)
......@@ -501,16 +513,6 @@ Warning:
}
}
offset, _, err := req.Option("offset").Int()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if offset < 0 {
res.SetError(fmt.Errorf("cannot have negative write offset"), cmds.ErrNormal)
return
}
count, countfound, err := req.Option("count").Int()
if err != nil {
res.SetError(err, cmds.ErrNormal)
......@@ -589,6 +591,19 @@ Examples:
res.SetError(err, cmds.ErrNormal)
return
}
flush, found, _ := req.Option("flush").Bool()
if !found {
flush = true
}
if flush {
err := n.FilesRoot.Flush()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
}
},
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论