From 2089b0e809f22843afc9f0d5b28de0ebab39b9bc Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 23 Apr 2021 17:33:32 +0200 Subject: [PATCH] Refactor command line utility --- config.go | 8 +++++--- fs.go | 15 +-------------- seafile_recovery.go | 22 +++++++++++++++------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/config.go b/config.go index 604c538..a59ee56 100644 --- a/config.go +++ b/config.go @@ -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:""` - PathId string `docopt:""` - Bucket string `docopt:""` + S3Url string `docopt:""` } diff --git a/fs.go b/fs.go index eb8d345..d0b654e 100644 --- a/fs.go +++ b/fs.go @@ -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 diff --git a/seafile_recovery.go b/seafile_recovery.go index 4f851f5..3425696 100644 --- a/seafile_recovery.go +++ b/seafile_recovery.go @@ -10,14 +10,17 @@ func main() { Usage: seafile_recovery [--storage=] head - seafile_recovery [--storage=] ls - seafile_recovery [--storage=] dump - seafile_recovery [--storage=] s3 + seafile_recovery [--storage=] ls (--dir= | --file=) + seafile_recovery [--storage=] cp (--dir= | --file=) + seafile_recovery [--storage=] s3 (--dir= | --file=) seafile_recovery (-h | --help) Options: - -h --help Show this screen - --storage= Set Seafile storage path [default: ./storage]` + -h --help Show this screen + --storage= Set Seafile storage path [default: ./storage] + --dir= Seafile Directory ID, can be obtained from commits as RootID + --file= 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) }