Refactor command line utility

This commit is contained in:
Quentin 2021-04-23 17:33:32 +02:00
parent dff728baea
commit 2089b0e809
Signed by: quentin
GPG Key ID: A98E9B769E4FF428
3 changed files with 21 additions and 24 deletions

View File

@ -3,10 +3,12 @@ package main
type configCollect struct {
Head bool `docopt:"head"`
Ls bool `docopt:"ls"`
Dump bool `docopt:"dump"`
Info bool `docopt:"info"`
Cp bool `docopt:"cp"`
S3 bool `docopt:"s3"`
Storage string `docopt:"--storage"`
DirId string `docopt:"--dir"`
FileId string `docopt:"--file"`
RepoId string `docopt:"<repoid>"`
PathId string `docopt:"<pathid>"`
Bucket string `docopt:"<bucket>"`
S3Url string `docopt:"<s3url>"`
}

15
fs.go
View File

@ -66,7 +66,7 @@ func NewRepoFs(config *configCollect) *RepoFs {
rf.Config = config
rf.EntryNode = new(DirNode)
rf.EntryNode.Ent = new(DirEnt)
rf.EntryNode.Ent.Id = config.PathId
rf.EntryNode.Ent.Id = config.DirId
rf.EntryNode.Ent.Name = ""
rf.EntryNode.AbsolutePath = "/"
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.
func IsDir(m uint32) bool {
return (m & syscall.S_IFMT) == syscall.S_IFDIR

View File

@ -10,14 +10,17 @@ func main() {
Usage:
seafile_recovery [--storage=<sto>] head <repoid>
seafile_recovery [--storage=<sto>] ls <repoid> <pathid>
seafile_recovery [--storage=<sto>] dump <repoid> <pathid>
seafile_recovery [--storage=<sto>] s3 <repoid> <pathid> <bucket>
seafile_recovery [--storage=<sto>] ls <repoid> (--dir=<dirid> | --file=<fileid>)
seafile_recovery [--storage=<sto>] cp <repoid> (--dir=<dirid> | --file=<fileid>)
seafile_recovery [--storage=<sto>] s3 <repoid> (--dir=<dirid> | --file=<pathid>) <s3url>
seafile_recovery (-h | --help)
Options:
-h --help Show this screen
--storage=<sto> Set Seafile storage path [default: ./storage]`
-h --help Show this screen
--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)
opts, err := docopt.ParseDoc(usage)
@ -32,8 +35,13 @@ Options:
cmdHead(config)
} else if config.Ls {
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
cmdLs(config)
} else if config.Dump {
if len(config.DirId) > 0 {
cmdLs(config)
} else {
//cmdInfo(config)
}
} else if config.Cp {
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) }