// Show a navigable tree view of the current directory.
11203
func main() {
	rootDir := "."
	root := tview.NewTreeNode(rootDir).
		SetColor(tcell.ColorRed)
	tree := tview.NewTreeView().
		SetRoot(root).
		SetCurrentNode(root)

	// A helper function which adds the files and directories of the given path
	// to the given target node.
	add := func(target *tview.TreeNode, path string) {
		files, err := ioutil.ReadDir(path)
		if err != nil {
			panic(err)
		}
		for _, file := range files {
			node := tview.NewTreeNode(file.Name()).
				SetReference(filepath.Join(path, file.Name())).
				SetSelectable(file.IsDir())
			if file.IsDir() {
				node.SetColor(tcell.ColorGreen)
			}
			target.AddChild(node)
		}
	}

	// Add the current directory to the root node.
	add(root, rootDir)

	// If a directory was selected, open it.
	tree.SetSelectedFunc(func(node *tview.TreeNode) {
		reference := node.GetReference()
		if reference == nil {
			return // Selecting the root node does nothing.
		}
		children := node.GetChildren()
		if len(children) == 0 {
			// Load and show files in this directory.
			path := reference.(string)
			add(node, path)
		} else {
			// Collapse if visible, expand if collapsed.
			node.SetExpanded(!node.IsExpanded())
		}
	})

	if err := tview.NewApplication().SetRoot(tree, true).Run(); err != nil {
		panic(err)
	}
}
1123128
func isDirEntry(e mtree.Entry) bool {
	for _, kw := range e.Keywords {
		kv := mtree.KeyVal(kw)
		if kv.Keyword() == "type" {
			return kv.Value() == "dir"
		}
	}
	// Shouldn't be reached.
	return false
}
916937
func (c *DeploymentsController) ShowSpaceEnvironments(ctx *app.ShowSpaceEnvironmentsDeploymentsContext) error {

	kc, err := c.GetKubeClient(ctx)
	defer cleanup(kc)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	envs, err := kc.GetEnvironments()
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "error retrieving environments"))
	}
	if envs == nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("environments", ctx.SpaceID.String()))
	}

	res := &app.SimpleEnvironmentList{
		Data: envs,
	}

	return ctx.OK(res)
}
794693
func NewTree(e StorageEngine, c Config) *Tree {
	return &Tree{eng: e, cfg: c}
}
812430
func (s *Server) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error) {
	nodePath := path.Join(s.root, dirPath) + "/"
	if nodePath == "//" {
		// Special case where c.root is "/", dirPath is empty,
		// we would end up with "//". in that case, we want "/".
		nodePath = "/"
	}

	isRoot := false
	if dirPath == "" || dirPath == "/" {
		isRoot = true
	}

	keys, _, err := s.kv.Keys(nodePath, "", nil)
	if err != nil {
		return nil, err
	}
	if len(keys) == 0 {
		// No key starts with this prefix, means the directory
		// doesn't exist.
		return nil, topo.NewError(topo.NoNode, nodePath)
	}

	prefixLen := len(nodePath)
	var result []topo.DirEntry
	for _, p := range keys {
		// Remove the prefix, base path.
		if !strings.HasPrefix(p, nodePath) {
			return nil, ErrBadResponse
		}
		p = p[prefixLen:]

		// Keep only the part until the first '/'.
		t := topo.TypeFile
		if i := strings.Index(p, "/"); i >= 0 {
			p = p[:i]
			t = topo.TypeDirectory
		}

		// Remove duplicates, add to list.
		if len(result) == 0 || result[len(result)-1].Name != p {
			e := topo.DirEntry{
				Name: p,
			}
			if full {
				e.Type = t
				if isRoot && p == electionsPath {
					e.Ephemeral = true
				}
				if p == locksFilename && t == topo.TypeFile {
					// A file called 'Lock' is always ephemeral.
					// (A directory called 'Lock' could be a keyspace or
					// a shard named Lock).
					e.Ephemeral = true
				}
			}
			result = append(result, e)
		}
	}

	return result, nil
}
614583
func SharedToolsDir(dataDir string, vers version.Binary) string {
	return path.Join(dataDir, "tools", vers.String())
}
813402
func (l *localFileSystem) MkDir(path string, mode int) error {
	fileMode := os.FileMode(mode & int(os.ModePerm))
	err := os.MkdirAll(path, fileMode)
	if err != nil && !os.IsExist(err) {
		return trace.ConvertSystemError(err)
	}

	return nil
}
1067264
func displayProcessTree() {
	ps := goprocess.FindAll()
	pstree = make(map[int][]goprocess.P)
	for _, p := range ps {
		pstree[p.PPID] = append(pstree[p.PPID], p)
	}
	tree := treeprint.New()
	tree.SetValue("...")
	seen := map[int]bool{}
	for _, p := range ps {
		constructProcessTree(p.PPID, p, seen, tree)
	}
	fmt.Println(tree.String())
}
624165
func DataDir() string {
	dataHome := filepath.Join(os.Getenv("HOME"), DefaultDataDir)
	if xdg := os.Getenv("XDG_DATA_HOME"); len(xdg) > 0 {
		dataHome = xdg
	}

	return filepath.Join(dataHome, DataFolder)
}
714260
func (v StrVCS) ReadDir(revision, path string) (files []os.FileInfo, err error) {
	for file := range v.files[revision] {
		files = append(files, fileInfo{
			name: file,
		})
	}
	return files, nil
}
1343699
func (w *Watcher) traversePluginDir(dir string) error {
	return w.fs.Walk(dir, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			if path == dir {
				return fmt.Errorf("error accessing path: %s error: %v", path, err)
			}

			klog.Errorf("error accessing path: %s error: %v", path, err)
			return nil
		}

		switch mode := info.Mode(); {
		case mode.IsDir():
			if w.containsBlacklistedDir(path) {
				return filepath.SkipDir
			}

			if err := w.fsWatcher.Add(path); err != nil {
				return fmt.Errorf("failed to watch %s, err: %v", path, err)
			}
		case mode&os.ModeSocket != 0:
			event := fsnotify.Event{
				Name: path,
				Op:   fsnotify.Create,
			}
			//TODO: Handle errors by taking corrective measures
			if err := w.handleCreateEvent(event); err != nil {
				klog.Errorf("error %v when handling create event: %s", err, event)
			}
		default:
			klog.V(5).Infof("Ignoring file %s with mode %v", path, mode)
		}

		return nil
	})
}
1161441
func (ctxt *Context) AddDirectory(path string) (*types.Package, error) {
	return ctxt.builder.AddDirectoryTo(path, &ctxt.Universe)
}
1195979
func Dir() (dir string, err error) {
	if flg := flag.CommandLine.Lookup(DirFlag); flg != nil {
		val := flg.Value.String()
		if strings.HasPrefix(val, ".") {
			cwd, err := os.Getwd()
			if err != nil {
				return cwd, err
			}
			return filepath.Join(cwd, val), nil
		}
		return val, nil
	}
	return "", nil
}
804651
func (s *Application) RootDir() string {
	if len(s.rootDir) == 0 {
		ppath := os.Getenv(strings.ToUpper(s.Name) + `PATH`)
		if len(ppath) == 0 {
			ppath, _ = filepath.Abs(os.Args[0])
			ppath = filepath.Dir(ppath)
		}
		s.rootDir = ppath
	}
	return s.rootDir
}
1265087
func homeDirectory() string {
	var homeDir string
	switch {
	case os.Getenv("CF_HOME") != "":
		homeDir = os.Getenv("CF_HOME")
	case os.Getenv("HOMEDRIVE")+os.Getenv("HOMEPATH") != "":
		homeDir = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
	default:
		homeDir = os.Getenv("USERPROFILE")
	}
	return homeDir
}
1095748
func (zs *Server) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error) {
	zkPath := path.Join(zs.root, dirPath)

	isRoot := false
	if dirPath == "" || dirPath == "/" {
		isRoot = true
	}

	children, _, err := zs.conn.Children(ctx, zkPath)
	if err != nil {
		return nil, convertError(err, zkPath)
	}
	sort.Strings(children)

	result := make([]topo.DirEntry, len(children))
	for i, child := range children {
		result[i].Name = child
	}

	if full {
		var wg sync.WaitGroup
		for i := range result {
			if isRoot && result[i].Name == electionsPath {
				// Shortcut here: we know it's an ephemeral directory.
				result[i].Type = topo.TypeDirectory
				result[i].Ephemeral = true
				continue
			}

			wg.Add(1)
			go func(i int) {
				defer wg.Done()
				p := path.Join(zkPath, result[i].Name)
				_, stat, err := zs.conn.Get(ctx, p)
				if err != nil {
					return
				}
				if stat.NumChildren == 0 {
					result[i].Type = topo.TypeFile
				} else {
					result[i].Type = topo.TypeDirectory
				}
				if stat.EphemeralOwner != 0 {
					// This is an ephemeral node, we use this for locks.
					result[i].Ephemeral = true
				}
			}(i)
		}
		wg.Wait()
	}

	return result, nil
}
201952
func (tc *TreeCache) CurrentData(fullPath string) (*ChildData, error) {
	node, err := tc.findNode(fullPath)
	if err != nil {
		return nil, err
	}
	if node.state.Load() != NodeStateLIVE {
		return nil, ErrNodeNotLive
	}

	return node.ChildData(), nil
}