Browse Source

Add support for multiple sources

master
Quentin 1 year ago
parent
commit
bb9d9c16eb
Signed by: quentin GPG Key ID: A98E9B769E4FF428
  1. 4
      command.go
  2. 18
      commit.go
  3. 5
      config.go
  4. 14
      seafile_recovery.go

4
command.go

@ -12,8 +12,10 @@ func cmdHead(config configCollect) {
rc.CollectContent()
rc.BuildGraph()
log.Println("Repo has", len(rc.Root), "sources")
rc.FindLeafs()
log.Println("Repo has", len(rc.Leafs), "leafs")
log.Println("Repo has", len(rc.Leafs), "sinks")
rc.ChooseHead()
log.Println("Proposing following HEAD:\n"+rc.Head.Content.String())

18
commit.go

@ -16,7 +16,7 @@ type RepoCommits struct {
Config configCollect
CommitDesc map[string]string
CommitContent map[string]*CommitNode
Root *CommitNode
Root map[*CommitNode]Empty
Leafs map[*CommitNode]Empty
Head *CommitNode
}
@ -60,6 +60,7 @@ func NewRepoCommits (config configCollect) *RepoCommits {
rc.Config = config
rc.CommitDesc = make(map[string]string)
rc.CommitContent = make(map[string]*CommitNode)
rc.Root = make(map[*CommitNode]Empty)
rc.Leafs = make(map[*CommitNode]Empty)
return rc
}
@ -100,14 +101,10 @@ func (rc* RepoCommits) CollectContent() {
}
}
func (rc* RepoCommits) BuildGraph() *CommitNode {
func (rc* RepoCommits) BuildGraph() map[*CommitNode]Empty {
for _, cn := range rc.CommitContent {
if cn.Content.ParentId == nil && cn.Content.SecondParentId == nil {
if rc.Root == nil {
rc.Root = cn
} else {
log.Fatal("More than one root commit has been found")
}
rc.Root[cn] = empty
}
if cn.Content.ParentId != nil {
@ -123,7 +120,7 @@ func (rc* RepoCommits) BuildGraph() *CommitNode {
}
}
if rc.Root == nil {
if len(rc.Root) == 0 {
log.Fatal("Root commit has not been found")
}
@ -132,7 +129,10 @@ func (rc* RepoCommits) BuildGraph() *CommitNode {
func (rc* RepoCommits) FindLeafs() map[*CommitNode]Empty {
toProcess := make(map[*CommitNode]Empty)
toProcess[rc.Root] = empty
for cn, _ := range rc.Root {
toProcess[cn] = empty
}
for i := 0; i < len(rc.CommitContent) && len(toProcess) > 0; i++ {
nextToProcess := make(map[*CommitNode]Empty)

5
config.go

@ -2,6 +2,11 @@ package main
type configCollect struct {
Head bool `docopt:"head"`
Ls bool `docopt:"ls"`
Dump bool `docopt:"dump"`
S3 bool `docopt:"s3"`
Storage string `docopt:"--storage"`
RepoId string `docopt:"<repoid>"`
PathId string `docopt:"<pathid>"`
Bucket string `docopt:"<bucket>"`
}

14
seafile_recovery.go

@ -10,6 +10,9 @@ 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 (-h | --help)
Options:
@ -27,6 +30,17 @@ Options:
if config.Head {
if !rexists["commits"] { log.Fatal("No commits folder found for repo ",config.RepoId) }
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 !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) }
} else if config.S3 {
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) }
} else {
log.Fatal("This command is not implemented")
}

Loading…
Cancel
Save