// OpenOrCreateDataDirectory opens a data directory, creating the directory
// if it doesn't not already exist.
346333
func OpenOrCreateDataDirectory(path string) (*DataDirectory, error) {
	exists, err := exists(path)
	if err != nil {
		return nil, err
	}
	if !exists {
		klog.Infof("data directory '%s' does not exist, creating it", path)
		err := os.MkdirAll(path, 0777)
		if err != nil {
			return nil, fmt.Errorf("failed to create data directory %s: %v", path, err)
		}
	}
	versionFile := &VersionFile{
		path: filepath.Join(path, versionFilename),
	}
	return &DataDirectory{path, versionFile}, nil
}
665787
func NewCreateFolderArg(Path string) *CreateFolderArg {
	s := new(CreateFolderArg)
	s.Path = Path
	s.Autorename = false
	return s
}
647303
func (nm DatastoreNamespaceManager) CreateDirectory(ctx context.Context, ds *Datastore, displayName string, policy string) (string, error) {

	req := &types.CreateDirectory{
		This:        nm.Reference(),
		Datastore:   ds.Reference(),
		DisplayName: displayName,
		Policy:      policy,
	}

	resp, err := methods.CreateDirectory(ctx, nm.c, req)
	if err != nil {
		return "", err
	}

	return resp.Returnval, nil
}
180215
func (t *stiTar) CreateTarFile(base, dir string) (string, error) {
	tarFile, err := ioutil.TempFile(base, "tar")
	defer tarFile.Close()
	if err != nil {
		return "", err
	}
	if err = t.CreateTarStream(dir, false, tarFile); err != nil {
		return "", err
	}
	return tarFile.Name(), nil
}
768726
func MakeDirs(path string) error {
	if err := os.MkdirAll(path, 0755); err != nil {
		return errors.Annotate(err, "").Err()
	}
	return nil
}
1325484
func createTree(tarw *tar.Writer, dst string, created map[string]bool) error {
	for _, path := range pathsToCreate(dst) {
		if created[path] {
			// skipping dir that was previously created inside the archive
			// (eg: usr/)
			continue
		}
		if err := tarw.WriteHeader(&tar.Header{
			Name:     filepath.ToSlash(path + "/"),
			Mode:     0755,
			Typeflag: tar.TypeDir,
			Format:   tar.FormatGNU,
			ModTime:  time.Now(),
		}); err != nil {
			return errors.Wrap(err, "failed to create folder")
		}
		created[path] = true
	}
	return nil
}
1135886
func (pb *PackageBuilder) AddDirectory(fpath string) (namePaths map[string]string, badPaths []string, err error) {
	namePaths = make(map[string]string)

	files, err := ioutil.ReadDir(fpath)
	if err != nil {
		badPaths = append(badPaths, fpath)
		return
	}

	for _, f := range files {
		dirOrFilePath := fpath + "/" + f.Name()
		if f.IsDir() {
			dirNamePaths, dirBadPath, err := pb.AddDirectory(dirOrFilePath)
			if err != nil {
				badPaths = append(badPaths, dirBadPath...)
			} else {
				for dirContentName, dirContentPath := range dirNamePaths {
					namePaths[dirContentName] = dirContentPath
				}
			}
		}

		name, err := pb.AddFile(dirOrFilePath)

		if (err != nil) || (name == "") {
			badPaths = append(badPaths, dirOrFilePath)
		} else {
			namePaths[name] = dirOrFilePath
		}
	}
	return
}
563624
func (r *Client) CreateDatasource(ds Datasource) (StatusMessage, error) {
	var (
		raw  []byte
		resp StatusMessage
		err  error
	)
	if raw, err = json.Marshal(ds); err != nil {
		return StatusMessage{}, err
	}
	if raw, _, err = r.post("api/datasources", nil, raw); err != nil {
		return StatusMessage{}, err
	}
	if err = json.Unmarshal(raw, &resp); err != nil {
		return StatusMessage{}, err
	}
	return resp, nil
}
1912
func createFile(name string, isDir bool) (syscall.Handle, error) {
	namep := syscall.StringToUTF16(name)
	da := uint32(desiredAccessReadControl | desiredAccessWriteDac)
	sm := uint32(shareModeRead | shareModeWrite)
	fa := uint32(syscall.FILE_ATTRIBUTE_NORMAL)
	if isDir {
		fa = uint32(fa | syscall.FILE_FLAG_BACKUP_SEMANTICS)
	}
	fd, err := syscall.CreateFile(&namep[0], da, sm, nil, syscall.OPEN_EXISTING, fa, 0)
	if err != nil {
		return 0, errors.Wrapf(err, "%s syscall.CreateFile %s", gvmga, name)
	}
	return fd, nil
}
467940
func MakeDirs(dir string, mode os.FileMode, log Log) error {
	exists, err := FileExists(dir)
	if err != nil {
		return err
	}

	if !exists {
		log.Debugf("Creating: %s\n", dir)
		err = os.MkdirAll(dir, mode)
		if err != nil {
			return err
		}
	}
	return nil
}
1123372
func OpenDB(databaser Databaser, dirpath string) (*Database, error) {
	err := databaser.Open(dirpath)
	if err != nil {
		simlog.Errorf("failed to open database. err = %s", err)
		return nil, err
	}
	return &Database{databaser}, nil
}
856270
func (l *SingleFileStore) openNew() error {
	err := os.MkdirAll(l.dir(), 0744)
	if err != nil {
		return fmt.Errorf("can't make directories for new logfile: %s", err)
	}

	name := l.filename()
	mode := os.FileMode(0644)

	// we use truncate here because this should only get called when we've moved
	// the file ourselves. if someone else creates the file in the meantime,
	// just wipe out the contents.
	f, err := os.OpenFile(name, os.O_CREATE|os.O_RDWR|os.O_TRUNC, mode)
	if err != nil {
		return fmt.Errorf("can't open new logfile: %s", err)
	}

	l.file = f
	l.size = 0
	return nil
}
1029665
func NewDatastore(path string) (ds.Datastore, error) {
	if !isDir(path) {
		return nil, fmt.Errorf("Failed to find directory at: %v (file? perms?)", path)
	}

	return &Datastore{path: path}, nil
}
1169159
func NewDirectory(containerName string) (directory string, err error) {
	directory = dirForName(containerName)
	logger.Tracef("create directory: %s", directory)
	if err = os.MkdirAll(directory, 0755); err != nil {
		logger.Errorf("failed to create container directory: %v", err)
		return "", err
	}
	return directory, nil
}
340697
func OpenQueue(dataDir string) (*Queue, error) {
	var err error

	// Create a new Queue.
	q := &Queue{
		DataDir: dataDir,
		db:      &leveldb.DB{},
		head:    0,
		tail:    0,
		isOpen:  false,
	}

	// Open database for the queue.
	q.db, err = leveldb.OpenFile(dataDir, nil)
	if err != nil {
		return q, err
	}

	// Check if this Goque type can open the requested data directory.
	ok, err := checkGoqueType(dataDir, goqueQueue)
	if err != nil {
		return q, err
	}
	if !ok {
		return q, ErrIncompatibleType
	}

	// Set isOpen and return.
	q.isOpen = true
	return q, q.init()
}
1125535
func MakeParentDirs(path string, mode os.FileMode, log Log) error {
	// 2nd return value here is filename (not an error), which is not needed
	dir, _ := filepath.Split(path)
	if dir == "" {
		return fmt.Errorf("No base directory")
	}
	return MakeDirs(dir, mode, log)
}
538717
func (c *Cache) ReadOrCreate(id string,
	read func(info ItemInfo, r io.Reader) error,
	create func(info ItemInfo, w io.WriteCloser) error) (info ItemInfo, err error) {
	id = cleanID(id)

	c.nlocker.Lock(id)
	defer c.nlocker.Unlock(id)

	info = ItemInfo{Name: id}

	if r := c.getOrRemove(id); r != nil {
		err = read(info, r)
		defer r.Close()
		return
	}

	f, err := helpers.OpenFileForWriting(c.Fs, id)
	if err != nil {
		return
	}

	err = create(info, f)

	return

}