// Dir returns a Case channel from a given directory.
//
// See ChannelSize for the channel size to be used.
// Any errors while walking the file system will fail and are not ignored.
351184
func Dir(t *testing.T, path string) <-chan Case {
	path = filepath.Join(BasePath, path)
	ch := make(chan Case)
	walker := func(path string, info os.FileInfo, err error) error {
		must(t, err)
		if info.Mode().IsRegular() && !strings.HasSuffix(path, Extension) {
			ch <- NewCase(t, path)
		}
		return nil
	}
	go func() {
		must(t, filepath.Walk(path, walker))
		close(ch)
	}()
	return ch
}
524822
func (c *Client) ListDirectory(directory string, opts ListDirectoryOpts) ([]Entry, error) {
	var resp []Entry
	requestHeaders := make(http.Header)
	requestHeaders.Set("Accept", "*/*")
	req := request{
		method:    client.GET,
		url:       makeURL(apiStorage, directory),
		reqHeader: requestHeaders,
		resp:      &resp,
		reqValue:  opts,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to list directory %s", directory)
	}
	return resp, nil
}
887569
func readDir(dirname string) (fi []os.FileInfo, err error) {
	f, err := os.Open(dirname)
	if err == nil {
		defer f.Close()
		if fi, err = f.Readdir(-1); fi != nil {
			sort.Sort(byName(fi))
		}
	}

	return
}
1022935
func Dir(appName string) (string, error) {
	dir := os.Getenv("XDG_CONFIG_HOME")
	if dir != "" {
		return dir, nil
	}
	usr, err := user.Current()
	if err != nil {
		return "", err
	}
	if appName == "" {
		return "", fmt.Errorf("No app name for dir")
	}
	return filepath.Join(usr.HomeDir, ".config", appName), nil
}
636818
func (wfe *WebFrontEndImpl) Directory(
	ctx context.Context,
	logEvent *web.RequestEvent,
	response http.ResponseWriter,
	request *http.Request) {
	directoryEndpoints := map[string]interface{}{
		"newAccount": newAcctPath,
		"newNonce":   newNoncePath,
		"revokeCert": revokeCertPath,
		"newOrder":   newOrderPath,
		"keyChange":  rolloverPath,
	}

	// Add a random key to the directory in order to make sure that clients don't hardcode an
	// expected set of keys. This ensures that we can properly extend the directory when we
	// need to add a new endpoint or meta element.
	directoryEndpoints[core.RandomString(8)] = randomDirKeyExplanationLink

	// ACME since draft-02 describes an optional "meta" directory entry. The
	// meta entry may optionally contain a "termsOfService" URI for the
	// current ToS.
	metaMap := map[string]interface{}{
		"termsOfService": wfe.SubscriberAgreementURL,
	}
	// The "meta" directory entry may also include a []string of CAA identities
	if wfe.DirectoryCAAIdentity != "" {
		// The specification says caaIdentities is an array of strings. In
		// practice Boulder's VA only allows configuring ONE CAA identity. Given
		// that constraint it doesn't make sense to allow multiple directory CAA
		// identities so we use just the `wfe.DirectoryCAAIdentity` alone.
		metaMap["caaIdentities"] = []string{
			wfe.DirectoryCAAIdentity,
		}
	}
	// The "meta" directory entry may also include a string with a website URL
	if wfe.DirectoryWebsite != "" {
		metaMap["website"] = wfe.DirectoryWebsite
	}
	directoryEndpoints["meta"] = metaMap

	response.Header().Set("Content-Type", "application/json")

	relDir, err := wfe.relativeDirectory(request, directoryEndpoints)
	if err != nil {
		marshalProb := probs.ServerInternal("unable to marshal JSON directory")
		wfe.sendError(response, logEvent, marshalProb, nil)
		return
	}

	response.Write(relDir)
}
518098
func (f *File) Readdir() ([]*File, error) {
	if !f.IsDir() {
		return nil, errors.New("not a directory")
	}
	return f.img.readdir(f.subdirOffset)
}
592963
func Size(ctx context.Context, dir string) (size int64, err error) {
	data := make(map[uint64]struct{})
	err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, err error) error {
		if err != nil {
			// if dir does not exist, Size() returns the error.
			// if dir/x disappeared while walking, Size() ignores dir/x.
			if os.IsNotExist(err) && d != dir {
				return nil
			}
			return err
		}
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}

		// Ignore directory sizes
		if fileInfo == nil {
			return nil
		}

		s := fileInfo.Size()
		if fileInfo.IsDir() || s == 0 {
			return nil
		}

		// Check inode to handle hard links correctly
		inode := fileInfo.Sys().(*syscall.Stat_t).Ino
		// inode is not a uint64 on all platforms. Cast it to avoid issues.
		if _, exists := data[inode]; exists {
			return nil
		}
		// inode is not a uint64 on all platforms. Cast it to avoid issues.
		data[inode] = struct{}{}

		size += s

		return nil
	})
	return
}
1278783
func (spec DirectorySpec) Initialize() (*Directory, error) {
	if err := spec.Deps.MkdirAll(spec.Dirname); err != nil {
		return nil, errors.Annotate(err, "could not create resource dir")
	}

	return NewDirectory(&spec, spec.Deps), nil
}
471386
func (fs *fakeFs) ReadDir(dirname string) ([]os.FileInfo, error) {
	return fs.a.ReadDir(dirname)
}
880478
func MkDir(dirpath string) error {
	if PathExists(dirpath) {
		return nil
	}

	err := os.MkdirAll(dirpath, 0755)
	if err != nil {
		log.Println("Error creating directory")
		log.Println(err)
		return err
	}

	return nil
}
370297
func (in *inode) ReadDir(p []byte, offset int) (n int) {
	if !in.isDir() {
		panic("ReadDir called on non-directory.")
	}

	for i := offset; i < len(in.entries); i++ {
		e := in.entries[i]

		// Skip unused entries.
		if e.Type == fuseutil.DT_Unknown {
			continue
		}

		tmp := fuseutil.WriteDirent(p[n:], in.entries[i])
		if tmp == 0 {
			break
		}

		n += tmp
	}

	return
}
1100884
func homeDir() string {
	if runtime.GOOS == "windows" {
		return os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
	}
	return os.Getenv("HOME")
}
432469
func (s *FolderStorage) Dir(key string) (d string, e bool, err error) {
	d = s.dir(key)
	_, err = os.Stat(d)
	if err == nil {
		// Directory exists
		e = true
		return
	}
	if os.IsNotExist(err) {
		// Directory doesn't exist
		d = ""
		e = false
		err = nil
		return
	}

	// An error
	d = ""
	e = false
	return
}
945885
func (l *httpFileSystem) MkDir(path string, mode int) error {
	return trace.BadParameter("directories are not supported in http file transfer")
}
124125
func (c *Static) processDir(fullPath, basePath string) (args map[string]interface{}, err error) {
	dirName := fpath.Base(fullPath)
	args = map[string]interface{}{"dirName": dirName}
	// Walk the folder showing up and down links
	dirFiles := []model.FileInformation{}
	symLinkPath, e := fpath.EvalSymlinks(fullPath)
	if e != nil {
		return args, e
	}

	// Get directory contents
	files, e := ioutil.ReadDir(fullPath)
	if e != nil {
		return nil, e
	}

	if fullPath != basePath {
		fileInfo := model.FileInformation{Icon: UP_DIR_ICON, Name: c.Message("static\\parent directory"), Relative: "../"}
		dirFiles = append(dirFiles, fileInfo)
	}
	for _, f := range files {
		fileInfo := model.FileInformation{Name: f.Name()}
		if f.IsDir() {
			fileInfo.Icon = DIR_ICON
			// Check that it is not a symnlink
			realFullPath, _ := fpath.EvalSymlinks(fpath.Join(fullPath, f.Name()))
			if strings.HasPrefix(realFullPath, symLinkPath) {
				// Valid to drill into
				fileInfo.Relative = f.Name() + "/"
			}
		} else {
			fileInfo.Icon = FILE_ICON
			size := "bytes"
			divider := int64(1)
			fileInfo.Size = f.Size()
			for x := 0; fileInfo.Size > byteSizeList[x][1].(int64); x++ {
				size = byteSizeList[x][0].(string)
				divider = byteSizeList[x][1].(int64)
			}
			fileInfo.Size = fileInfo.Size / divider
			fileInfo.SizeType = size
			fileInfo.NiceSize = fmt.Sprintf("%0.1d %s", fileInfo.Size, size)
			fileInfo.Relative = fileInfo.Name
		}
		modified := f.ModTime()
		fileInfo.Modified = &modified
		dirFiles = append(dirFiles, fileInfo)
	}
	args["content"] = dirFiles
	args["count"] = len(dirFiles)
	args["dateformat"] = revel.Config.StringDefault("static.dateformat", "2006-01-02 15:04:05 MST")
	return
}
791233
func Size(dir string) (size int64, err error) {
	err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, err error) error {
		if err != nil {
			// if dir does not exist, Size() returns the error.
			// if dir/x disappeared while walking, Size() ignores dir/x.
			if os.IsNotExist(err) && d != dir {
				return nil
			}
			return err
		}

		// Ignore directory sizes
		if fileInfo == nil {
			return nil
		}

		s := fileInfo.Size()
		if fileInfo.IsDir() || s == 0 {
			return nil
		}

		size += s

		return nil
	})
	return
}
697345
func dir(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error) {
	if len(kwargs) > 0 {
		return nil, fmt.Errorf("dir does not accept keyword arguments")
	}
	if len(args) != 1 {
		return nil, fmt.Errorf("dir: got %d arguments, want 1", len(args))
	}

	var names []string
	if x, ok := args[0].(HasAttrs); ok {
		names = x.AttrNames()
	}
	elems := make([]Value, len(names))
	for i, name := range names {
		elems[i] = String(name)
	}
	return NewList(elems), nil
}