// CreateTarFile creates a tar file from the given directory
// while excluding files that match the given exclusion pattern
// It returns the name of the created file
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
}
1032330
func CreateStateFile(stor storage.Storage) (string, error) {
	err := putState(stor, []byte{})
	if err != nil {
		return "", fmt.Errorf("cannot create initial state file: %v", err)
	}
	return stor.URL(StateFile)
}
236900
func createLogFile(logDir string, logFile string) (io.Writer, error) {
	if ok, err := dirExists(logDir); !ok {
		return nil, err
	}

	file, err := os.Create(path.Join(logDir, logFile))
	if err != nil {
		return nil, err
	}

	return file, nil
}
378577
func (c Config) CreateParentDir(fileName string) error {
	return os.MkdirAll(filepath.Dir(filepath.Join(c.Path, fileName)), 0755)
}
503311
func (s *noopFilesystemSource) CreateFilesystems(ctx environscontext.ProviderCallContext, args []storage.FilesystemParams) ([]storage.CreateFilesystemsResult, error) {
	return nil, nil
}
49170
func (DefaultFs) Create(name string) (File, error) {
	file, err := os.Create(name)
	if err != nil {
		return nil, err
	}
	return &defaultFile{file}, nil
}
306137
func CreateFilesystem(name string, opts *CreateFilesystemOpts) error {
	cmd := newCmd("create")
	if opts != nil {
		cmd = addOpt(cmd, opts.DontMount, "-u")
		cmd = addOpt(cmd, opts.CreateParents, "-p")
		cmd = addProperties(cmd, opts.SetProperties)
	}
	cmd = addNonEmpty(cmd, name)
	return zExecNoOut(cmd)
}
459988
func ExportDirectory(tarfile *tar.Writer, path, name string) error {
	dir, err := os.Open(path)
	if err != nil {
		glog.Errorf("Could not open %s: %s", path, err)
		return err
	}
	defer dir.Close()
	fstat, err := dir.Stat()
	if err != nil {
		glog.Errorf("Could not stat %s: %s", path, err)
		return err
	}
	header, err := getHeader(name, "", fstat)
	if err != nil {
		return err
	}
	if err := tarfile.WriteHeader(header); err != nil {
		glog.Errorf("Could not write header for directory %s: %s", path, err)
		return err
	}
	files, err := dir.Readdir(0)
	if err != nil {
		glog.Errorf("Could not list directory for %s: %s", path, err)
		return err
	}
	for _, finfo := range files {
		fullpath, relpath := filepath.Join(path, finfo.Name()), filepath.Join(name, finfo.Name())
		if finfo.IsDir() {
			if err := ExportDirectory(tarfile, fullpath, relpath); err != nil {
				return err
			}
		} else {
			if err := ExportFile(tarfile, fullpath, relpath); err != nil {
				return err
			}
		}
	}
	return nil
}
1144882
func (p *Package) CreateSourceFile(name string) (*SourceFile, error) {
	os.RemoveAll(filepath.Join(p.Abs(), name))
	return p.OpenSourceFile(name)
}
1253486
func (fs *memFS) createFile(
	parentID fuseops.InodeID,
	name string,
	mode os.FileMode) (entry fuseops.ChildInodeEntry, err error) {
	// Grab the parent, which we will update shortly.
	parent := fs.getInodeOrDie(parentID)

	// Ensure that the name doesn't already exist, so we don't wind up with a
	// duplicate.
	_, _, exists := parent.LookUpChild(name)
	if exists {
		err = fuse.EEXIST
		return
	}

	// Set up attributes for the child.
	now := time.Now()
	childAttrs := fuseops.InodeAttributes{
		Nlink:  1,
		Mode:   mode,
		Atime:  now,
		Mtime:  now,
		Ctime:  now,
		Crtime: now,
		Uid:    fs.uid,
		Gid:    fs.gid,
	}

	// Allocate a child.
	childID, child := fs.allocateInode(childAttrs)

	// Add an entry in the parent.
	parent.AddChild(childID, name, fuseutil.DT_File)

	// Fill in the response entry.
	entry.Child = childID
	entry.Attributes = child.attrs

	// We don't spontaneously mutate, so the kernel can cache as long as it wants
	// (since it also handles invalidation).
	entry.AttributesExpiration = time.Now().Add(365 * 24 * time.Hour)
	entry.EntryExpiration = entry.AttributesExpiration

	return
}
1033563
func (t *TemplateResource) createStageFile() error {
	log.Debug("Using source template " + t.Src)

	if !util.IsFileExist(t.Src) {
		return errors.New("Missing template: " + t.Src)
	}

	log.Debug("Compiling source template " + t.Src)

	tmpl, err := template.New(filepath.Base(t.Src)).Funcs(t.funcMap).ParseFiles(t.Src)
	if err != nil {
		return fmt.Errorf("Unable to process template %s, %s", t.Src, err)
	}

	// create TempFile in Dest directory to avoid cross-filesystem issues
	temp, err := ioutil.TempFile(filepath.Dir(t.Dest), "."+filepath.Base(t.Dest))
	if err != nil {
		return err
	}

	if err = tmpl.Execute(temp, nil); err != nil {
		temp.Close()
		os.Remove(temp.Name())
		return err
	}
	defer temp.Close()

	// Set the owner, group, and mode on the stage file now to make it easier to
	// compare against the destination configuration file later.
	os.Chmod(temp.Name(), t.FileMode)
	os.Chown(temp.Name(), t.Uid, t.Gid)
	t.StageFile = temp
	return nil
}
649150
func Create(fs Filesystem, name string) (File, error) {
	return fs.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
}
484461
func (k *kubeletClient) CreateArchive(containerID, sourcePath string) (*bytes.Buffer, error) {
	return k.getCommandOutput(containerID, fmt.Sprintf("command=tar&command=-cf&command=-&command=%s&output=1", sourcePath))
}
697848
func (s *lxdFilesystemSource) CreateFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemParams) (_ []storage.CreateFilesystemsResult, err error) {
	results := make([]storage.CreateFilesystemsResult, len(args))
	for i, arg := range args {
		if err := s.ValidateFilesystemParams(arg); err != nil {
			results[i].Error = err
			continue
		}
		filesystem, err := s.createFilesystem(arg)
		if err != nil {
			results[i].Error = err
			common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
			continue
		}
		results[i].Filesystem = filesystem
	}
	return results, nil
}
354720
func (c oauthClient) CreateFile(uploadID uint, taskID uint) (wl.File, error) {
	if uploadID == 0 {
		return wl.File{}, errors.New("uploadID must be > 0")
	}

	if taskID == 0 {
		return wl.File{}, errors.New("taskID must be > 0")
	}

	body := []byte(fmt.Sprintf(`{"upload_id":%d,"task_id":%d}`, uploadID, taskID))

	url := fmt.Sprintf("%s/files", c.apiURL)

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

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

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

	file := wl.File{}
	err = json.NewDecoder(resp.Body).Decode(&file)
	if err != nil {
		return wl.File{}, err
	}
	return file, nil
}
667736
func (fs *fakeFs) Create(name string) (File, error) {
	file, err := fs.a.Fs.Create(name)
	if err != nil {
		return nil, err
	}
	return &fakeFile{file}, nil
}
153727
func (api *ImagesAPI) CreateFromFile(imagePath string, options *ImageCreateOptions) (task *Task, err error) {
	params := imageCreateOptionsToMap(options)
	res, err := api.client.restClient.MultipartUploadFile(api.client.Endpoint+imageUrl, imagePath, params, api.client.options.TokenOptions)
	if err != nil {
		return
	}
	defer res.Body.Close()
	result, err := getTask(getError(res))
	return result, err
}