// FromDir creates a new Store by loading entity files from a given directory path. Any files
// contained in the directory with names matching <group>.entities.csv will be imported,
// and the entities added to the group <group>.
961168
func FromDir(dir string) (*Store, error) {
	dir = strings.TrimRight(dir, "/")
	files, err := ioutil.ReadDir(dir)
	if err != nil {
		return nil, err
	}

	s := New()
	var wg sync.WaitGroup
	count := struct {
		sync.Mutex
		n int
	}{}

	errCh := make(chan error, len(files))
	for _, stat := range files {
		if strings.HasSuffix(stat.Name(), entityFileSuffix) {
			wg.Add(1)
			go func(path string, group string) {
				defer wg.Done()
				f, err := os.Open(path)
				if err != nil {
					errCh <- fmt.Errorf("error opening %v: %v\n", path, err)
					return
				}
				defer f.Close()

				err = AddFromReader(f, s, group)
				if err != nil {
					errCh <- fmt.Errorf("error reading from %v: %v\n", path, err)
					return
				}
				count.Lock()
				count.n++
				count.Unlock()
			}(fmt.Sprintf("%s/%s", dir, stat.Name()), strings.TrimSuffix(stat.Name(), entityFileSuffix))
		}
	}
	wg.Wait()
	close(errCh)

	for e := range errCh {
		if err == nil {
			err = e
		}
	}
	if err != nil {
		return nil, err
	}

	if count.n == 0 {
		return nil, errors.New("no entity files found")
	}
	return s, nil
}
189796
func (lfs localFileSystem) Mkdir(path string, perm os.FileMode) error {
	return villa.Path(path).MkdirAll(perm)
}
40245
func (lfs localFileSystem) ReadDir(dir string) ([]os.FileInfo, error) {
	return villa.Path(dir).ReadDir()
}
5668
func (s *Store) IsDir(ctx context.Context, name string) bool {
	path := filepath.Join(s.path, filepath.Clean(name))
	isDir := fsutil.IsDir(path)
	out.Debug(ctx, "fs.Isdir(%s) - %s -> %t", name, path, isDir)
	return isDir
}
1267464
func (u *FakeVolumeUtil) ReadDir(fullPath string) ([]string, error) {
	fileNames := []string{}
	files, found := u.directoryFiles[fullPath]
	if !found {
		return nil, fmt.Errorf("Directory %q not found", fullPath)
	}
	for _, file := range files {
		fileNames = append(fileNames, file.Name)
	}
	return fileNames, nil
}
1052008
func (fs OsFS) ReadDir(path string) ([]os.FileInfo, error) {
	return ioutil.ReadDir(path)
}
263261
func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) {
	var merge DirsMerger = f.Merger
	if merge == nil {
		merge = defaultUnionMergeDirsFn
	}

	if f.off == 0 {
		var lfi []os.FileInfo
		if f.Layer != nil {
			lfi, err = f.Layer.Readdir(-1)
			if err != nil {
				return nil, err
			}
		}

		var bfi []os.FileInfo
		if f.Base != nil {
			bfi, err = f.Base.Readdir(-1)
			if err != nil {
				return nil, err
			}

		}
		merged, err := merge(lfi, bfi)
		if err != nil {
			return nil, err
		}
		f.files = append(f.files, merged...)
	}

	if c <= 0 && len(f.files) == 0 {
		return f.files, nil
	}

	if f.off >= len(f.files) {
		return nil, io.EOF
	}

	if c <= 0 {
		return f.files[f.off:], nil
	}

	if c > len(f.files) {
		c = len(f.files)
	}

	defer func() { f.off += c }()
	return f.files[f.off:c], nil
}
233399
func BuildDir(path string) option {
	return func(c *sass) error {
		c.ctx.BuildDir = path
		return nil
	}
}
471386
func (fs *fakeFs) ReadDir(dirname string) ([]os.FileInfo, error) {
	return fs.a.ReadDir(dirname)
}
1111370
func CopyDir(source string, dest string) error {
	// Get properties of source.
	srcinfo, err := os.Stat(source)
	if err != nil {
		return err
	}

	// Create the destination directory.
	err = os.MkdirAll(dest, srcinfo.Mode())
	if err != nil {
		return err
	}

	dir, _ := os.Open(source)
	obs, err := dir.Readdir(-1)
	if err != nil {
		return err
	}

	var errs []error

	for _, obj := range obs {
		fsource := source + "/" + obj.Name()
		fdest := dest + "/" + obj.Name()

		if obj.IsDir() {
			// Create sub-directories, recursively.
			err = CopyDir(fsource, fdest)
			if err != nil {
				errs = append(errs, err)
			}
		} else {
			// Perform the file copy.
			err = CopyFile(fsource, fdest)
			if err != nil {
				errs = append(errs, err)
			}
		}
	}

	var errString string
	for _, err := range errs {
		errString += err.Error() + "\n"
	}

	if errString != "" {
		return errors.New(errString)
	}

	return nil
}
1192043
func FromPath(path string) *URL {
	return &URL{
		Crypto:  GPGCLI,
		RCS:     GitCLI,
		Storage: FS,
		Scheme:  "file",
		Path:    path,
	}
}
1170276
func (m *metadataTracker) fromDB(db *instance, folder []byte) error {
	key := db.keyer.GenerateFolderMetaKey(nil, folder)
	bs, err := db.Get(key, nil)
	if err != nil {
		return err
	}
	return m.Unmarshal(bs)
}
769710
func (s *SearchService) From(from int) *SearchService {
	s.searchSource = s.searchSource.From(from)
	return s
}
145504
func (n node) From(addend ...string) Node {
	n.rootBucket = append(n.rootBucket, addend...)
	return &n
}
1309706
func NewDir(dir, def string) Dir {
	return Dir{
		Default: def,
		dir:     http.Dir(dir),
	}
}
242594
func CopyDir(source string, dest string) (err error) {

	// get properties of source dir
	fi, err := os.Stat(source)
	if err != nil {
		return err
	}

	if !fi.IsDir() {
		return errNotDir.Format(source)
	}

	// create dest dir

	err = os.MkdirAll(dest, fi.Mode())
	if err != nil {
		return err
	}

	entries, err := ioutil.ReadDir(source)

	for _, entry := range entries {

		sfp := source + PathSeparator + entry.Name()
		dfp := dest + PathSeparator + entry.Name()
		if entry.IsDir() {
			err = CopyDir(sfp, dfp)
			if err != nil {
				return
			}
		} else {
			// perform copy
			err = CopyFile(sfp, dfp)
			if err != nil {
				return
			}
		}

	}
	return
}
896812
func (p *DatastorePath) FromString(s string) bool {
	if s == "" {
		return false
	}

	s = strings.TrimSpace(s)

	if !strings.HasPrefix(s, "[") {
		return false
	}

	s = s[1:]

	ix := strings.Index(s, "]")
	if ix < 0 {
		return false
	}

	p.Datastore = s[:ix]
	p.Path = strings.TrimSpace(s[ix+1:])

	return true
}