// Create three folders for each id
// mnt, layers, and diff
503990
func (a *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {

	if opts != nil && len(opts.StorageOpt) != 0 {
		return fmt.Errorf("--storage-opt is not supported for aufs")
	}

	if err := a.createDirsFor(id); err != nil {
		return err
	}
	// Write the layers metadata
	f, err := os.Create(path.Join(a.rootPath(), "layers", id))
	if err != nil {
		return err
	}
	defer f.Close()

	if parent != "" {
		ids, err := getParentIDs(a.rootPath(), parent)
		if err != nil {
			return err
		}

		if _, err := fmt.Fprintln(f, parent); err != nil {
			return err
		}
		for _, i := range ids {
			if _, err := fmt.Fprintln(f, i); err != nil {
				return err
			}
		}
	}

	return nil
}
456270
func (c oauthClient) CreateFolder(
	title string,
	listIDs []uint,
) (wl.Folder, error) {
	if title == "" {
		return wl.Folder{}, errors.New("title must be non-empty")
	}

	if listIDs == nil || len(listIDs) == 0 {
		return wl.Folder{}, errors.New("listIDs must be non-nil and non-empty")
	}

	fcc := folderCreateConfig{
		Title:   title,
		ListIDs: listIDs,
	}

	body, err := json.Marshal(fcc)
	if err != nil {
		return wl.Folder{}, err
	}

	reqURL := fmt.Sprintf("%s/folders", c.apiURL)

	req, err := c.newPostRequest(reqURL, body)
	if err != nil {
		return wl.Folder{}, err
	}

	resp, err := c.do(req)
	if err != nil {
		return wl.Folder{}, err
	}

	if resp.StatusCode != http.StatusCreated {
		return wl.Folder{}, fmt.Errorf("Unexpected response code %d - expected %d", resp.StatusCode, http.StatusCreated)
	}

	folder := wl.Folder{}
	err = json.NewDecoder(resp.Body).Decode(&folder)
	if err != nil {
		return wl.Folder{}, err
	}
	return folder, nil
}
281183
func Create() *MemFS {
	root := &fileInfo{
		name: "/",
		dir:  true,
	}
	return &MemFS{
		root: root,
		wd:   root,
		lock: &sync.RWMutex{},
	}
}
676352
func (d Dir) Create(name string) (*os.File, error) {
	if d.env == "" {
		return nil, errors.New("xdgdir: Create on zero Dir")
	}
	p := d.Path()
	if p == "" {
		return nil, fmt.Errorf("xdgdir: create %s: %s is invalid or not set", name, d.env)
	}
	fp := filepath.Join(p, name)
	if err := os.MkdirAll(filepath.Dir(fp), 0700); err != nil {
		return nil, err
	}
	return os.Create(fp)
}
484759
func CreateNativeZeroLengthFiles(info *metainfo.Info, dir string) (err error) {
	for _, fi := range info.UpvertedFiles() {
		if fi.Length != 0 {
			continue
		}
		name := filepath.Join(append([]string{dir, info.Name}, fi.Path...)...)
		os.MkdirAll(filepath.Dir(name), 0777)
		var f io.Closer
		f, err = os.Create(name)
		if err != nil {
			break
		}
		f.Close()
	}
	return
}
700505
func (d *Driver) DiffSize(id, parent string) (size int64, err error) {
	rPId, err := d.resolveID(parent)
	if err != nil {
		return
	}

	changes, err := d.Changes(id, rPId)
	if err != nil {
		return
	}

	layerFs, err := d.Get(id, "")
	if err != nil {
		return
	}
	defer d.Put(id)

	return archive.ChangesSize(layerFs.Path(), changes), nil
}
1324563
func (l *Layer0) Create(id string, parent string, mountLabel string, storageOpts map[string]string) error {
	id, vol, err := l.create(id, parent)
	if err != nil {
		return err
	}
	err = l.Driver.Create(id, parent, mountLabel, storageOpts)
	if err != nil || vol == nil {
		return err
	}
	// This is layer0. Restore saved upper dir, if one exists.
	savedUpper := path.Join(vol.path, "upper")
	if _, err := os.Stat(savedUpper); err != nil {
		// It's not an error if didn't have a saved upper
		return nil
	}
	// We found a saved upper, restore to newly created upper.
	upperDir := path.Join(path.Join(l.home, id), "upper")
	os.RemoveAll(upperDir)
	return os.Rename(savedUpper, upperDir)
}
313121
func CreateTopLevelDirectories(config *srvconfig.Config) error {
	switch {
	case config.Root == "":
		return errors.New("root must be specified")
	case config.State == "":
		return errors.New("state must be specified")
	case config.Root == config.State:
		return errors.New("root and state must be different paths")
	}

	if err := sys.MkdirAllWithACL(config.Root, 0711); err != nil {
		return err
	}
	if err := sys.MkdirAllWithACL(config.State, 0711); err != nil {
		return err
	}
	return nil
}
14788
func folderFromTeamID(ctx context.Context, g *libkb.GlobalContext, teamID keybase1.TeamID, isImplicit bool) (keybase1.Folder, error) {
	if isImplicit {
		return folderFromTeamIDImplicit(ctx, g, teamID)
	}
	return folderFromTeamIDNamed(ctx, g, teamID)
}
1194049
func (p IndexFiles) IDs() []int {
	a := make([]int, len(p))
	for i, f := range p {
		a[i] = f.ID()
	}
	return a
}
1262425
func CopyDirs(src, dest string) error {
	if err := os.MkdirAll(dest, 0777); err != nil {
		return err
	}
	files, err := readDirs(src)
	if err != nil {
		return err
	}

	for _, f := range files {
		dp := filepath.Join(dest, f)
		sp := filepath.Join(src, f)

		stat, err := os.Stat(sp)
		if err != nil {
			return err
		}

		// Empty directories are also created.
		if stat.IsDir() {
			if err := os.MkdirAll(dp, 0777); err != nil {
				return err
			}
			continue
		}

		if err := copyFile(sp, dp); err != nil {
			return err
		}
	}
	return nil
}
907579
func (a FileLayerAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) {
	var dirDiffs []util.DirDiff

	// Go through each layer of the first image...
	for index, layer := range image1.Layers {
		if index >= len(image2.Layers) {
			continue
		}
		// ...else, diff as usual
		layer2 := image2.Layers[index]
		diff, err := diffImageFiles(layer.FSPath, layer2.FSPath)
		if err != nil {
			return &util.MultipleDirDiffResult{}, err
		}
		dirDiffs = append(dirDiffs, diff)
	}

	// check if there are any additional layers in either image
	if len(image1.Layers) != len(image2.Layers) {
		if len(image1.Layers) > len(image2.Layers) {
			logrus.Infof("%s has additional layers, please use container-diff analyze to view the files in these layers", image1.Source)
		} else {
			logrus.Infof("%s has additional layers, please use container-diff analyze to view the files in these layers", image2.Source)
		}
	}
	return &util.MultipleDirDiffResult{
		Image1:   image1.Source,
		Image2:   image2.Source,
		DiffType: "FileLayer",
		Diff: util.MultipleDirDiff{
			DirDiffs: dirDiffs,
		},
	}, nil
}
260547
func (c *Client) LinodeDiskCreate(linodeID int, label string, dType string,
	size int) (jobID int, diskID int, err error) {

	args := make(map[string]interface{})
	args["LinodeID"] = linodeID
	args["Label"] = label
	args["Type"] = dType
	args["Size"] = size

	data, err := c.apiCall("linode.disk.create", args)
	if err != nil {
		return 0, 0, err
	}

	out := struct {
		JobID  int `json:"JobID"`
		DiskID int `json:"DiskID"`
	}{}

	err = json.Unmarshal(data, &out)
	if err != nil {
		return 0, 0, err
	}

	return out.JobID, out.DiskID, err
}
729254
func (gdw *NaiveDiffDriver) Diff(id string, idMappings *idtools.IDMappings, parent string, parentMappings *idtools.IDMappings, mountLabel string) (arch io.ReadCloser, err error) {
	startTime := time.Now()
	driver := gdw.ProtoDriver

	if idMappings == nil {
		idMappings = &idtools.IDMappings{}
	}
	if parentMappings == nil {
		parentMappings = &idtools.IDMappings{}
	}

	options := MountOpts{
		MountLabel: mountLabel,
	}
	layerFs, err := driver.Get(id, options)
	if err != nil {
		return nil, err
	}

	defer func() {
		if err != nil {
			driver.Put(id)
		}
	}()

	if parent == "" {
		archive, err := archive.TarWithOptions(layerFs, &archive.TarOptions{
			Compression: archive.Uncompressed,
			UIDMaps:     idMappings.UIDs(),
			GIDMaps:     idMappings.GIDs(),
		})
		if err != nil {
			return nil, err
		}
		return ioutils.NewReadCloserWrapper(archive, func() error {
			err := archive.Close()
			driver.Put(id)
			return err
		}), nil
	}

	parentFs, err := driver.Get(parent, options)
	if err != nil {
		return nil, err
	}
	defer driver.Put(parent)

	changes, err := archive.ChangesDirs(layerFs, idMappings, parentFs, parentMappings)
	if err != nil {
		return nil, err
	}

	archive, err := archive.ExportChanges(layerFs, changes, idMappings.UIDs(), idMappings.GIDs())
	if err != nil {
		return nil, err
	}

	return ioutils.NewReadCloserWrapper(archive, func() error {
		err := archive.Close()
		driver.Put(id)

		// NaiveDiffDriver compares file metadata with parent layers. Parent layers
		// are extracted from tar's with full second precision on modified time.
		// We need this hack here to make sure calls within same second receive
		// correct result.
		time.Sleep(startTime.Truncate(time.Second).Add(time.Second).Sub(time.Now()))
		return err
	}), nil
}
1206305
func (c oauthClient) Folder(folderID uint) (wl.Folder, error) {
	if folderID == 0 {
		return wl.Folder{}, errors.New("folderID must be > 0")
	}

	url := fmt.Sprintf(
		"%s/folders/%d",
		c.apiURL,
		folderID,
	)

	req, err := c.newGetRequest(url)
	if err != nil {
		return wl.Folder{}, err
	}

	resp, err := c.do(req)
	if err != nil {
		return wl.Folder{}, err
	}

	if resp.StatusCode != http.StatusOK {
		return wl.Folder{}, fmt.Errorf("Unexpected response code %d - expected %d", resp.StatusCode, http.StatusOK)
	}

	folder := wl.Folder{}
	err = json.NewDecoder(resp.Body).Decode(&folder)
	if err != nil {
		return wl.Folder{}, err
	}
	return folder, nil
}
665787
func NewCreateFolderArg(Path string) *CreateFolderArg {
	s := new(CreateFolderArg)
	s.Path = Path
	s.Autorename = false
	return s
}
855011
func (c *rankCache) IDs() []uint64 {
	c.mu.Lock()
	defer c.mu.Unlock()
	a := make([]uint64, 0, len(c.entries))
	for id := range c.entries {
		a = append(a, id)
	}
	sort.Sort(uint64Slice(a))
	return a
}