Refactor command line utility
This commit is contained in:
parent
dff728baea
commit
2089b0e809
3 changed files with 21 additions and 24 deletions
|
@ -3,10 +3,12 @@ package main
|
||||||
type configCollect struct {
|
type configCollect struct {
|
||||||
Head bool `docopt:"head"`
|
Head bool `docopt:"head"`
|
||||||
Ls bool `docopt:"ls"`
|
Ls bool `docopt:"ls"`
|
||||||
Dump bool `docopt:"dump"`
|
Info bool `docopt:"info"`
|
||||||
|
Cp bool `docopt:"cp"`
|
||||||
S3 bool `docopt:"s3"`
|
S3 bool `docopt:"s3"`
|
||||||
Storage string `docopt:"--storage"`
|
Storage string `docopt:"--storage"`
|
||||||
|
DirId string `docopt:"--dir"`
|
||||||
|
FileId string `docopt:"--file"`
|
||||||
RepoId string `docopt:"<repoid>"`
|
RepoId string `docopt:"<repoid>"`
|
||||||
PathId string `docopt:"<pathid>"`
|
S3Url string `docopt:"<s3url>"`
|
||||||
Bucket string `docopt:"<bucket>"`
|
|
||||||
}
|
}
|
||||||
|
|
15
fs.go
15
fs.go
|
@ -66,7 +66,7 @@ func NewRepoFs(config *configCollect) *RepoFs {
|
||||||
rf.Config = config
|
rf.Config = config
|
||||||
rf.EntryNode = new(DirNode)
|
rf.EntryNode = new(DirNode)
|
||||||
rf.EntryNode.Ent = new(DirEnt)
|
rf.EntryNode.Ent = new(DirEnt)
|
||||||
rf.EntryNode.Ent.Id = config.PathId
|
rf.EntryNode.Ent.Id = config.DirId
|
||||||
rf.EntryNode.Ent.Name = ""
|
rf.EntryNode.Ent.Name = ""
|
||||||
rf.EntryNode.AbsolutePath = "/"
|
rf.EntryNode.AbsolutePath = "/"
|
||||||
rf.EntryNode.Files = make([]*FileNode,0)
|
rf.EntryNode.Files = make([]*FileNode,0)
|
||||||
|
@ -172,19 +172,6 @@ func (dn* DirNode) Walk(strat ExpandStrat, depth int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func (rf* RepoFs) Walk() {
|
|
||||||
qPathIds := make([]string, 0)
|
|
||||||
qPathIds = append(qPathIds, rf.PathId)
|
|
||||||
|
|
||||||
for limit := 0 ; limit < 20000 && len(pathIds) > 0 ; limit++ {
|
|
||||||
pathId := qPathIds[0]
|
|
||||||
qPathIds = qPathIds[1:]
|
|
||||||
NewDirNode(filepath.Join(rf.Config.Storage, "fs", rf.Config.RepoId), pathId)
|
|
||||||
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
// IsDir check if the mode is dir.
|
// IsDir check if the mode is dir.
|
||||||
func IsDir(m uint32) bool {
|
func IsDir(m uint32) bool {
|
||||||
return (m & syscall.S_IFMT) == syscall.S_IFDIR
|
return (m & syscall.S_IFMT) == syscall.S_IFDIR
|
||||||
|
|
|
@ -10,14 +10,17 @@ func main() {
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
seafile_recovery [--storage=<sto>] head <repoid>
|
seafile_recovery [--storage=<sto>] head <repoid>
|
||||||
seafile_recovery [--storage=<sto>] ls <repoid> <pathid>
|
seafile_recovery [--storage=<sto>] ls <repoid> (--dir=<dirid> | --file=<fileid>)
|
||||||
seafile_recovery [--storage=<sto>] dump <repoid> <pathid>
|
seafile_recovery [--storage=<sto>] cp <repoid> (--dir=<dirid> | --file=<fileid>)
|
||||||
seafile_recovery [--storage=<sto>] s3 <repoid> <pathid> <bucket>
|
seafile_recovery [--storage=<sto>] s3 <repoid> (--dir=<dirid> | --file=<pathid>) <s3url>
|
||||||
seafile_recovery (-h | --help)
|
seafile_recovery (-h | --help)
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h --help Show this screen
|
-h --help Show this screen
|
||||||
--storage=<sto> Set Seafile storage path [default: ./storage]`
|
--storage=<sto> Set Seafile storage path [default: ./storage]
|
||||||
|
--dir=<dirid> Seafile Directory ID, can be obtained from commits as RootID
|
||||||
|
--file=<fileid> Seafile File ID, can be obtained through ls
|
||||||
|
`
|
||||||
|
|
||||||
config := new(configCollect)
|
config := new(configCollect)
|
||||||
opts, err := docopt.ParseDoc(usage)
|
opts, err := docopt.ParseDoc(usage)
|
||||||
|
@ -32,8 +35,13 @@ Options:
|
||||||
cmdHead(config)
|
cmdHead(config)
|
||||||
} else if config.Ls {
|
} else if config.Ls {
|
||||||
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
||||||
|
|
||||||
|
if len(config.DirId) > 0 {
|
||||||
cmdLs(config)
|
cmdLs(config)
|
||||||
} else if config.Dump {
|
} else {
|
||||||
|
//cmdInfo(config)
|
||||||
|
}
|
||||||
|
} else if config.Cp {
|
||||||
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
||||||
if !rexists["blocks"] { log.Fatal("No blocks folder found for repo ",config.RepoId) }
|
if !rexists["blocks"] { log.Fatal("No blocks folder found for repo ",config.RepoId) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue