From bb9d9c16eb085877b20bbba5de429c44824af661 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 22 Apr 2021 12:38:52 +0200 Subject: [PATCH] Add support for multiple sources --- command.go | 4 +++- commit.go | 18 +++++++++--------- config.go | 5 +++++ seafile_recovery.go | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/command.go b/command.go index 6aa52e8..3fd0827 100644 --- a/command.go +++ b/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()) diff --git a/commit.go b/commit.go index 416ee83..a59c1db 100644 --- a/commit.go +++ b/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) diff --git a/config.go b/config.go index e2e47de..604c538 100644 --- a/config.go +++ b/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:""` + PathId string `docopt:""` + Bucket string `docopt:""` } diff --git a/seafile_recovery.go b/seafile_recovery.go index d498426..275950e 100644 --- a/seafile_recovery.go +++ b/seafile_recovery.go @@ -10,6 +10,9 @@ func main() { Usage: seafile_recovery [--storage=] head + seafile_recovery [--storage=] ls + seafile_recovery [--storage=] dump + seafile_recovery [--storage=] s3 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") }