seafile_recovery/command.go

66 lines
1.3 KiB
Go

package main
import(
"log"
"os"
"io"
)
func cmdHead(config *configCollect) {
rc := NewRepoCommits(config)
rc.CollectDescs()
log.Println("Repo contains", len(rc.CommitDesc), "commits")
rc.CollectContent()
rc.BuildGraph()
log.Println("Repo has", len(rc.Root), "sources")
if len(rc.Root) > 1 {
for cn, _ := range rc.Root {
log.Println("Commit "+cn.Id+"\n"+cn.Content.String())
}
}
rc.FindLeafs()
log.Println("Repo has", len(rc.Leafs), "sinks")
rc.ChooseHead()
log.Println("Proposing following HEAD:\n"+rc.Head.Content.String())
}
type LsWalker struct { }
func (lw* LsWalker) onDir(dn *DirNode) {
log.Println(dn.String())
}
func (lw* LsWalker) onFile(fn *FileNode) {
log.Println(fn.String())
}
func cmdLs(config *configCollect) {
en := NewEntryNode(config)
en.Walk(new(LsWalker))
}
func cmdInfo(config *configCollect) {
en := NewEntryFileNode(config)
en.Parse()
log.Println(en.Elem.String())
}
func cmdCpFile(config *configCollect) {
en := NewEntryFileNode(config)
en.Parse()
file, err := os.Create(config.Dest)
if err != nil { log.Fatal(err) }
written, err := io.Copy(file, en)
if err != nil { log.Fatal(err) }
if uint64(written) != en.Elem.FileSize {
log.Fatal(written, "bytes written,", en.Elem.FileSize, "bytes expected")
}
}
func cmdCpDir(config *configCollect) {
}