Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
63ddffdb
Commit
63ddffdb
authored
Aug 13, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add "files update" command.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
18a6344b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
9 deletions
+73
-9
core/commands/files/files.go
core/commands/files/files.go
+73
-9
No files found.
core/commands/files/files.go
View file @
63ddffdb
...
...
@@ -58,15 +58,16 @@ from the parent directory.
// that uses "hash"
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"read"
:
FilesReadCmd
,
"write"
:
FilesWriteCmd
,
"mv"
:
FilesMvCmd
,
"cp"
:
FilesCpCmd
,
"ls"
:
FilesLsCmd
,
"mkdir"
:
FilesMkdirCmd
,
"stat"
:
FilesStatCmd
,
"rm"
:
FilesRmCmd
,
"flush"
:
FilesFlushCmd
,
"read"
:
FilesReadCmd
,
"write"
:
FilesWriteCmd
,
"mv"
:
FilesMvCmd
,
"cp"
:
FilesCpCmd
,
"ls"
:
FilesLsCmd
,
"mkdir"
:
FilesMkdirCmd
,
"stat"
:
FilesStatCmd
,
"rm"
:
FilesRmCmd
,
"flush"
:
FilesFlushCmd
,
"update"
:
FilesUpdateCmd
,
},
}
...
...
@@ -793,6 +794,69 @@ are run with the '--flush=false'.
},
}
var
FilesUpdateCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Change the cid version of hash function of the root node of a given path."
,
ShortDescription
:
`
Flush a given path to disk. This is only useful when other commands
are run with the '--flush=false'.
`
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"path"
,
false
,
false
,
"Path to flush. Default: '/'."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
nd
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
path
:=
"/"
if
len
(
req
.
Arguments
())
>
0
{
path
=
req
.
Arguments
()[
0
]
}
flush
,
_
,
_
:=
req
.
Option
(
"flush"
)
.
Bool
()
prefix
,
err
:=
getPrefix
(
req
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
err
=
updatePath
(
nd
.
FilesRoot
,
path
,
prefix
,
flush
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
},
}
func
updatePath
(
rt
*
mfs
.
Root
,
pth
string
,
prefix
*
cid
.
Prefix
,
flush
bool
)
error
{
if
prefix
==
nil
{
return
nil
}
nd
,
err
:=
mfs
.
Lookup
(
rt
,
pth
)
if
err
!=
nil
{
return
err
}
switch
n
:=
nd
.
(
type
)
{
case
*
mfs
.
Directory
:
n
.
SetPrefix
(
prefix
)
default
:
return
fmt
.
Errorf
(
"can only update directories"
)
}
if
flush
{
nd
.
Flush
()
}
return
nil
}
var
FilesRmCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Remove a file."
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment