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
f7b6ee3c
Commit
f7b6ee3c
authored
Oct 27, 2018
by
chenminjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refact(cmd/repo): repo fsck and repo version uses new cmd lib
License: MIT Signed-off-by:
chenminjian
<
727180553@qq.com
>
parent
3f7668bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
40 deletions
+28
-40
core/commands/repo.go
core/commands/repo.go
+28
-40
No files found.
core/commands/repo.go
View file @
f7b6ee3c
...
...
@@ -42,8 +42,8 @@ var RepoCmd = &cmds.Command{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"stat"
:
repoStatCmd
,
"gc"
:
repoGcCmd
,
"fsck"
:
lgc
.
NewCommand
(
RepoFsckCmd
)
,
"version"
:
lgc
.
NewCommand
(
repoVersionCmd
)
,
"fsck"
:
RepoFsckCmd
,
"version"
:
repoVersionCmd
,
"verify"
:
lgc
.
NewCommand
(
repoVerifyCmd
),
},
}
...
...
@@ -224,7 +224,7 @@ Version string The repo version.
},
}
var
RepoFsckCmd
=
&
old
cmds
.
Command
{
var
RepoFsckCmd
=
&
cmds
.
Command
{
Helptext
:
cmdkit
.
HelpText
{
Tagline
:
"Remove repo lockfiles."
,
ShortDescription
:
`
...
...
@@ -233,13 +233,15 @@ lockfiles, as well as the api file. This command can only run when no ipfs
daemons are running.
`
,
},
Run
:
func
(
req
oldcmds
.
Request
,
res
oldcmds
.
Response
)
{
configRoot
:=
req
.
InvocContext
()
.
ConfigRoot
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
configRoot
,
err
:=
cmdenv
.
GetConfigRoot
(
env
)
if
err
!=
nil
{
return
err
}
dsPath
,
err
:=
config
.
DataStorePath
(
configRoot
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
dsLockFile
:=
filepath
.
Join
(
dsPath
,
"LOCK"
)
// TODO: get this lockfile programmatically
...
...
@@ -252,25 +254,25 @@ daemons are running.
err
=
os
.
Remove
(
repoLockFile
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
err
=
os
.
Remove
(
dsLockFile
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
err
=
os
.
Remove
(
apiFile
)
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
re
s
.
SetOutput
(
&
MessageOutput
{
"Lockfiles have been removed.
\n
"
})
re
turn
cmds
.
EmitOnce
(
res
,
&
MessageOutput
{
"Lockfiles have been removed.
\n
"
})
},
Type
:
MessageOutput
{},
Marshalers
:
oldcmds
.
MarshalerMap
{
oldcmds
.
Text
:
MessageTextMarshaler
,
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
MessageOutput
)
error
{
fmt
.
Fprintf
(
w
,
out
.
Message
)
return
nil
}),
},
}
...
...
@@ -409,7 +411,7 @@ var repoVerifyCmd = &oldcmds.Command{
},
}
var
repoVersionCmd
=
&
old
cmds
.
Command
{
var
repoVersionCmd
=
&
cmds
.
Command
{
Helptext
:
cmdkit
.
HelpText
{
Tagline
:
"Show the repo version."
,
ShortDescription
:
`
...
...
@@ -420,36 +422,22 @@ var repoVersionCmd = &oldcmds.Command{
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
BoolOption
(
repoQuietOptionName
,
"q"
,
"Write minimal output."
),
},
Run
:
func
(
req
old
cmds
.
Request
,
res
old
cmds
.
Response
)
{
re
s
.
SetOutput
(
&
RepoVersion
{
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
Response
Emitter
,
env
cmds
.
Environment
)
error
{
re
turn
cmds
.
EmitOnce
(
res
,
&
RepoVersion
{
Version
:
fmt
.
Sprint
(
fsrepo
.
RepoVersion
),
})
},
Type
:
RepoVersion
{},
Marshalers
:
oldcmds
.
MarshalerMap
{
oldcmds
.
Text
:
func
(
res
oldcmds
.
Response
)
(
io
.
Reader
,
error
)
{
v
,
err
:=
unwrapOutput
(
res
.
Output
())
if
err
!=
nil
{
return
nil
,
err
}
response
,
ok
:=
v
.
(
*
RepoVersion
)
if
!
ok
{
return
nil
,
e
.
TypeErr
(
response
,
v
)
}
quiet
,
_
,
err
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
if
err
!=
nil
{
return
nil
,
err
}
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
RepoVersion
)
error
{
quiet
,
_
:=
req
.
Options
[
repoQuietOptionName
]
.
(
bool
)
buf
:=
new
(
bytes
.
Buffer
)
if
quiet
{
buf
=
bytes
.
NewBufferString
(
fmt
.
Sprintf
(
"fs-repo@%s
\n
"
,
response
.
Version
))
fmt
.
Fprintf
(
w
,
fmt
.
Sprintf
(
"fs-repo@%s
\n
"
,
out
.
Version
))
}
else
{
buf
=
bytes
.
NewBufferString
(
fmt
.
Sprintf
(
"ipfs repo version fs-repo@%s
\n
"
,
response
.
Version
))
fmt
.
Fprintf
(
w
,
fmt
.
Sprintf
(
"ipfs repo version fs-repo@%s
\n
"
,
out
.
Version
))
}
return
buf
,
nil
},
return
nil
}),
},
}
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