First LS version
This commit is contained in:
parent
c09c5406e9
commit
dff728baea
4 changed files with 41 additions and 18 deletions
15
command.go
15
command.go
|
@ -4,7 +4,7 @@ import(
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cmdHead(config configCollect) {
|
func cmdHead(config *configCollect) {
|
||||||
rc := NewRepoCommits(config)
|
rc := NewRepoCommits(config)
|
||||||
|
|
||||||
rc.CollectDescs()
|
rc.CollectDescs()
|
||||||
|
@ -28,5 +28,16 @@ func cmdHead(config configCollect) {
|
||||||
|
|
||||||
func cmdLs(config *configCollect) {
|
func cmdLs(config *configCollect) {
|
||||||
rf := NewRepoFs(config)
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ type Empty struct{}
|
||||||
var empty Empty
|
var empty Empty
|
||||||
|
|
||||||
type RepoCommits struct {
|
type RepoCommits struct {
|
||||||
Config configCollect
|
Config *configCollect
|
||||||
CommitDesc map[string]string
|
CommitDesc map[string]string
|
||||||
CommitContent map[string]*CommitNode
|
CommitContent map[string]*CommitNode
|
||||||
Root map[*CommitNode]Empty
|
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))
|
`, 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 := new(RepoCommits)
|
||||||
rc.Config = config
|
rc.Config = config
|
||||||
rc.CommitDesc = make(map[string]string)
|
rc.CommitDesc = make(map[string]string)
|
||||||
|
|
34
fs.go
34
fs.go
|
@ -53,6 +53,7 @@ type FileNode struct {
|
||||||
Config *configCollect
|
Config *configCollect
|
||||||
Ent *DirEnt
|
Ent *DirEnt
|
||||||
Elem FileElem
|
Elem FileElem
|
||||||
|
AbsolutePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RepoFs struct {
|
type RepoFs struct {
|
||||||
|
@ -70,6 +71,7 @@ func NewRepoFs(config *configCollect) *RepoFs {
|
||||||
rf.EntryNode.AbsolutePath = "/"
|
rf.EntryNode.AbsolutePath = "/"
|
||||||
rf.EntryNode.Files = make([]*FileNode,0)
|
rf.EntryNode.Files = make([]*FileNode,0)
|
||||||
rf.EntryNode.Folders = make([]*DirNode,0)
|
rf.EntryNode.Folders = make([]*DirNode,0)
|
||||||
|
rf.EntryNode.Config = config
|
||||||
|
|
||||||
return rf
|
return rf
|
||||||
}
|
}
|
||||||
|
@ -90,10 +92,15 @@ func (dn* DirNode) String() string {
|
||||||
return fmt.Sprintf("%v %v", dn.Ent.Id[:6], dn.AbsolutePath)
|
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 {
|
func NewFileNode(parent *DirNode, ent *DirEnt) *FileNode {
|
||||||
fn := new (FileNode)
|
fn := new (FileNode)
|
||||||
fn.Ent = ent
|
fn.Ent = ent
|
||||||
fn.Config = parent.Config
|
fn.Config = parent.Config
|
||||||
|
fn.AbsolutePath = parent.AbsolutePath + ent.Name
|
||||||
|
|
||||||
return fn
|
return fn
|
||||||
}
|
}
|
||||||
|
@ -144,22 +151,27 @@ const (
|
||||||
ExpandAll
|
ExpandAll
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dn* DirNode) Expand(strat ExpandStrat) {
|
func (dn* DirNode) Walk(strat ExpandStrat, depth int) {
|
||||||
for _, cdn := range dn.Folders {
|
qNode := []*DirNode{dn}
|
||||||
cdn.Parse()
|
for len(qNode) > 0 && depth != 0{
|
||||||
}
|
if depth > 0 { depth = depth - 1 }
|
||||||
|
|
||||||
if strat == ExpandAll {
|
cursor := qNode[0]
|
||||||
for _, cfn := range dn.Files {
|
qNode = qNode[1:]
|
||||||
cfn.Parse()
|
cursor.Parse()
|
||||||
|
|
||||||
|
for _, ndn := range dn.Folders {
|
||||||
|
qNode = append(qNode, ndn)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ExpandAll == strat {
|
||||||
|
for _, nfn := range dn.Files {
|
||||||
|
nfn.Parse()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dn* DirNode) Walk(strat ExpandStrat) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*func (rf* RepoFs) Walk() {
|
/*func (rf* RepoFs) Walk() {
|
||||||
qPathIds := make([]string, 0)
|
qPathIds := make([]string, 0)
|
||||||
qPathIds = append(qPathIds, rf.PathId)
|
qPathIds = append(qPathIds, rf.PathId)
|
||||||
|
|
|
@ -19,10 +19,10 @@ Options:
|
||||||
-h --help Show this screen
|
-h --help Show this screen
|
||||||
--storage=<sto> Set Seafile storage path [default: ./storage]`
|
--storage=<sto> Set Seafile storage path [default: ./storage]`
|
||||||
|
|
||||||
var config configCollect
|
config := new(configCollect)
|
||||||
opts, err := docopt.ParseDoc(usage)
|
opts, err := docopt.ParseDoc(usage)
|
||||||
if err != nil { log.Fatal(err) }
|
if err != nil { log.Fatal(err) }
|
||||||
opts.Bind(&config)
|
opts.Bind(config)
|
||||||
|
|
||||||
checkRootFolder(config.Storage)
|
checkRootFolder(config.Storage)
|
||||||
rexists := repoExistsIn(config.Storage, config.RepoId)
|
rexists := repoExistsIn(config.Storage, config.RepoId)
|
||||||
|
@ -32,7 +32,7 @@ Options:
|
||||||
cmdHead(config)
|
cmdHead(config)
|
||||||
} else if config.Ls {
|
} else if config.Ls {
|
||||||
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
||||||
cmdLs(&config)
|
cmdLs(config)
|
||||||
} else if config.Dump {
|
} else if config.Dump {
|
||||||
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
|
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) }
|
if !rexists["blocks"] { log.Fatal("No blocks folder found for repo ",config.RepoId) }
|
||||||
|
|
Loading…
Reference in a new issue