예제 #1
0
func (fs StdFileSystem) FileTree(file filesystem.File) *filesystem.FileTree {
	if !file.IsDir() {
		return nil
	}
	tree := &filesystem.FileTree{}
	tree.StdFile = file
	return fs.readDir(file, tree)
}
예제 #2
0
func (fs StdFileSystem) FileMap(file filesystem.File) filesystem.FileMap {
	if !file.IsDir() {
		return nil
	}
	tree := &filesystem.FileTree{}

	tree.StdFile = file
	fileMap, _ := filesystem.FileTreeToMap(*fs.FileTree(file), file.Path())
	return fileMap
}
예제 #3
0
// Recursively read a directory structure and create a tree structure out of it
// TODO: fix symlinks/cyclic dependencies etc.
func (fs StdFileSystem) readDir(curFile filesystem.File, parent *filesystem.FileTree) *filesystem.FileTree {
	tree := &filesystem.FileTree{}
	tree.StdFile = curFile
	tree.StdParentNode = parent

	// TODO: Symlink check not working...
	if curFile.IsDir() || curFile.Mode() == os.ModeSymlink {

		tree.StdChildNodes = make([]*filesystem.FileTree, 0)
		dirListing, _ := fs.Dir(curFile.Path())
		if dirListing != nil && len(dirListing) > 0 {
			for _, file := range dirListing {
				tree.StdChildNodes = append(tree.StdChildNodes, fs.readDir(file, tree))
			}
		}
	}

	return tree
}