Browse Source

First LS version

master
Quentin 1 year ago
parent
commit
dff728baea
Signed by: quentin GPG Key ID: A98E9B769E4FF428
  1. 15
      command.go
  2. 4
      commit.go
  3. 34
      fs.go
  4. 6
      seafile_recovery.go

15
command.go

@ -4,7 +4,7 @@ import(
"log"
)
func cmdHead(config configCollect) {
func cmdHead(config *configCollect) {
rc := NewRepoCommits(config)
rc.CollectDescs()
@ -28,5 +28,16 @@ func cmdHead(config configCollect) {
func cmdLs(config *configCollect) {
rf := NewRepoFs(config)
log.Println(rf.EntryNode.String())
rf.EntryNode.Walk(ExpandOnlyDirectory, -1)
stackFolders := []*DirNode{rf.EntryNode}
for len(stackFolders) > 0 {
fold := stackFolders[0]
stackFolders = append(stackFolders[1:], fold.Folders...)
log.Println(fold.String())
for _, file := range fold.Files {
log.Println(file.String())
}
}
}

4
commit.go

@ -13,7 +13,7 @@ type Empty struct{}
var empty Empty
type RepoCommits struct {
Config configCollect
Config *configCollect
CommitDesc map[string]string
CommitContent map[string]*CommitNode
Root map[*CommitNode]Empty
@ -64,7 +64,7 @@ RepoDesc: %v
`, nilable(c.RootId), nilable(c.CreatorName), nilable(c.Creator), nilable(c.Description), time.Unix(c.Ctime, 0), nilable(c.RepoName), nilable(c.RepoDesc))
}
func NewRepoCommits (config configCollect) *RepoCommits {
func NewRepoCommits (config *configCollect) *RepoCommits {
rc := new(RepoCommits)
rc.Config = config
rc.CommitDesc = make(map[string]string)

34
fs.go

@ -53,6 +53,7 @@ type FileNode struct {
Config *configCollect
Ent *DirEnt
Elem FileElem
AbsolutePath string
}
type RepoFs struct {
@ -70,6 +71,7 @@ func NewRepoFs(config *configCollect) *RepoFs {
rf.EntryNode.AbsolutePath = "/"
rf.EntryNode.Files = make([]*FileNode,0)
rf.EntryNode.Folders = make([]*DirNode,0)
rf.EntryNode.Config = config
return rf
}
@ -90,10 +92,15 @@ func (dn* DirNode) String() string {
return fmt.Sprintf("%v %v", dn.Ent.Id[:6], dn.AbsolutePath)
}
func (fn* FileNode) String() string {
return fmt.Sprintf("%v %v", fn.Ent.Id[:6], fn.AbsolutePath)
}
func NewFileNode(parent *DirNode, ent *DirEnt) *FileNode {
fn := new (FileNode)
fn.Ent = ent
fn.Config = parent.Config
fn.AbsolutePath = parent.AbsolutePath + ent.Name
return fn
}
@ -144,20 +151,25 @@ const (
ExpandAll
)
func (dn* DirNode) Expand(strat ExpandStrat) {
for _, cdn := range dn.Folders {
cdn.Parse()
}
func (dn* DirNode) Walk(strat ExpandStrat, depth int) {
qNode := []*DirNode{dn}
for len(qNode) > 0 && depth != 0{
if depth > 0 { depth = depth - 1 }
if strat == ExpandAll {
for _, cfn := range dn.Files {
cfn.Parse()
}
}
}
cursor := qNode[0]
qNode = qNode[1:]
cursor.Parse()
func (dn* DirNode) Walk(strat ExpandStrat) {
for _, ndn := range dn.Folders {
qNode = append(qNode, ndn)
}
if ExpandAll == strat {
for _, nfn := range dn.Files {
nfn.Parse()
}
}
}
}
/*func (rf* RepoFs) Walk() {

6
seafile_recovery.go

@ -19,10 +19,10 @@ Options:
-h --help Show this screen
--storage=<sto> Set Seafile storage path [default: ./storage]`
var config configCollect
config := new(configCollect)
opts, err := docopt.ParseDoc(usage)
if err != nil { log.Fatal(err) }
opts.Bind(&config)
opts.Bind(config)
checkRootFolder(config.Storage)
rexists := repoExistsIn(config.Storage, config.RepoId)
@ -32,7 +32,7 @@ Options:
cmdHead(config)
} else if config.Ls {
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
cmdLs(&config)
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) }

Loading…
Cancel
Save