Add support for multiple sources

This commit is contained in:
Quentin 2021-04-22 12:38:52 +02:00
parent 0844490d79
commit bb9d9c16eb
Signed by: quentin
GPG key ID: A98E9B769E4FF428
4 changed files with 31 additions and 10 deletions

View file

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

View file

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

View file

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

View file

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