// doAddFile create a new blob from path and update the index, added is true if
// the file added is different from the index.
764678
func (w *Worktree) doAddFile(idx *index.Index, s Status, path string) (added bool, h plumbing.Hash, err error) {
	if s.File(path).Worktree == Unmodified {
		return false, h, nil
	}

	h, err = w.copyFileToStorage(path)
	if err != nil {
		if os.IsNotExist(err) {
			added = true
			h, err = w.deleteFromIndex(idx, path)
		}

		return
	}

	if err := w.addOrUpdateFileToIndex(idx, path, h); err != nil {
		return false, h, err
	}

	return true, h, err
}
612947
func (tz *TzArchive) AddFile(fileName, absPath string) error {
	if cae.IsFilter(absPath) {
		return nil
	}

	si, err := os.Lstat(absPath)
	if err != nil {
		return err
	}

	target := ""
	if si.Mode()&os.ModeSymlink != 0 {
		target, err = os.Readlink(absPath)
		if err != nil {
			return err
		}
	}

	file := new(File)
	file.Header, err = tar.FileInfoHeader(si, target)
	if err != nil {
		return err
	}
	file.Name = fileName
	file.absPath = absPath

	tz.AddEmptyDir(path.Dir(fileName))

	isExist := false
	for _, f := range tz.files {
		if fileName == f.Name {
			f = file
			isExist = true
			break
		}
	}
	if !isExist {
		tz.files = append(tz.files, file)
	}

	tz.updateStat()
	return nil
}
636918
func (f *Folder) addFile(path []string, contentType string) error {
	if len(path) < 1 {
		return errors.Errorf("Path must not be empty")
	}
	name := path[0]
	if len(path) == 1 {
		if _, found := f.Files[name]; found {
			return errors.Errorf("File %s exists", name)
		}
		f.Files[name] = &File{
			Name: name,
			Metadata: map[string]string{
				"Content-Type": contentType,
			},
		}
		return nil
	}
	next := f.getFolder(name)
	return next.addFile(path[1:], contentType)
}
790500
func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), nil, cbool(force))
	runtime.KeepAlive(c)
	if ret < 0 {
		return MakeGitError(ret)
	}

	return nil
}
82834
func (bi *BinaryInfo) AddImage(path string, addr uint64) {
	if !strings.HasPrefix(path, "/") {
		return
	}
	for _, image := range bi.Images {
		if image.Path == path && image.addr == addr {
			return
		}
	}
	//TODO(aarzilli): actually load informations about the image here
	bi.Images = append(bi.Images, &Image{Path: path, addr: addr})
}
106352
func (src *Source) ParseFile(path string) error {
	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()

	s := bufio.NewScanner(file)
	for s.Scan() {
		t := trim(s.Text())
		if len(t) < 7 {
			continue
		}
		if !strings.HasPrefix(t, "//sys") {
			continue
		}
		t = t[5:]
		if !(t[0] == ' ' || t[0] == '\t') {
			continue
		}
		f, err := newFn(t[1:])
		if err != nil {
			return err
		}
		src.Funcs = append(src.Funcs, f)
	}
	if err := s.Err(); err != nil {
		return err
	}
	src.Files = append(src.Files, path)

	// get package name
	fset := token.NewFileSet()
	_, err = file.Seek(0, 0)
	if err != nil {
		return err
	}
	pkg, err := parser.ParseFile(fset, "", file, parser.PackageClauseOnly)
	if err != nil {
		return err
	}
	packageName = pkg.Name.Name

	return nil
}
505307
func (link *LinkState) AddFile(input JITInputType, path string, options ...JITOption) error {
	argcount, args, argvals := link.encodeArguments(options)

	cpath := C.CString(path)
	err := result(C.cuLinkAddFile(
		link.state, C.CUjitInputType(input),
		cpath,
		argcount, args, argvals,
	))
	C.free(unsafe.Pointer(cpath))
	return err
}
1290879
func (b *Bogus) AddPath(path string) *paths.Path {
	if _, ok := b.paths[path]; !ok {
		b.paths[path] = paths.New()
	}

	return b.paths[path]
}
181999
func (f *File) SetEndOfFile(ctx context.Context, fi *dokan.FileInfo, length int64) (err error) {
	f.folder.fs.logEnter(ctx, "File SetEndOfFile")
	defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()

	return f.folder.fs.config.KBFSOps().Truncate(ctx, f.node, uint64(length))
}
867614
func doPreallocFile(filename string, size int) (created bool, err error) {
	if size%preallocAlign != 0 {
		return false, fmt.Errorf("specified size %v for file %q is not a multiple of %d", size, filename, preallocAlign)
	}
	f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0700)
	if os.IsExist(err) {
		// already exists, don't overwrite
		return false, nil
	}
	if err != nil {
		return false, fmt.Errorf("failed to open mongo prealloc file %q: %v", filename, err)
	}
	defer f.Close()
	for written := 0; written < size; {
		n := len(zeroes)
		if n > (size - written) {
			n = size - written
		}
		n, err := f.Write(zeroes[:n])
		if err != nil {
			return true, fmt.Errorf("failed to write to mongo prealloc file %q: %v", filename, err)
		}
		written += n
	}
	return true, nil
}
268917
func (i IndexFile) Add(md *chart.Metadata, filename, baseURL, digest string) {
	u := filename
	if baseURL != "" {
		var err error
		_, file := filepath.Split(filename)
		u, err = urlutil.URLJoin(baseURL, file)
		if err != nil {
			u = path.Join(baseURL, file)
		}
	}
	cr := &ChartVersion{
		URLs:     []string{u},
		Metadata: md,
		Digest:   digest,
		Created:  time.Now(),
	}
	if ee, ok := i.Entries[md.Name]; !ok {
		i.Entries[md.Name] = ChartVersions{cr}
	} else {
		i.Entries[md.Name] = append(ee, cr)
	}
}
407993
func (z *ZipFile) AddAll(dir string, includeCurrentFolder bool) error {
	dir = path.Clean(dir)
	return addAll(dir, dir, includeCurrentFolder, func(info os.FileInfo, file io.Reader, entryName string) (err error) {
		// Create a header based off of the fileinfo
		header, err := zip.FileInfoHeader(info)
		if err != nil {
			return err
		}

		// If it's a file, set the compression method to deflate (leave directories uncompressed)
		if !info.IsDir() {
			header.Method = zip.Deflate
		}

		// Set the header's name to what we want--it may not include the top folder
		header.Name = entryName

		// Add a trailing slash if the entry is a directory
		if info.IsDir() {
			header.Name += "/"
		}

		// Get a writer in the archive based on our header
		writer, err := z.Writer.CreateHeader(header)
		if err != nil {
			return err
		}

		// If we have a file to write (i.e., not a directory) then pipe the file into the archive writer
		if file != nil {
			if _, err := io.Copy(writer, file); err != nil {
				return err
			}
		}

		return nil
	})
}
619303
func (z *Zip) AddFile(path string, file *os.File) error {
	path = strings.Replace(path, "\\", "/", -1)

	z.lock.Lock()
	defer z.lock.Unlock()

	info, err := file.Stat()
	if err != nil {
		return err
	}

	if !info.Mode().IsRegular() {
		return errors.New("Only regular files supported: " + path)
	}

	header, err := zip.FileInfoHeader(info)
	if err != nil {
		return err
	}
	header.Name = path
	header.Method = zip.Deflate
	header.SetModTime(time.Unix(0, 0))

	zippedFile, err := z.writer.CreateHeader(header)
	if err != nil {
		return err
	}

	_, err = io.Copy(zippedFile, file)
	return err
}
1179076
func (c *Client) DeleteFile(id, name string) error {
	res, err := c.doRequest("b2_delete_file_version", map[string]interface{}{
		"fileId": id, "fileName": name,
	})
	if err != nil {
		return err
	}
	drainAndClose(res.Body)
	return nil
}
255272
func (f *File) Append(source interface{}, others ...interface{}) error {
	ds, err := parseDataSource(source)
	if err != nil {
		return err
	}
	f.dataSources = append(f.dataSources, ds)
	for _, s := range others {
		ds, err = parseDataSource(s)
		if err != nil {
			return err
		}
		f.dataSources = append(f.dataSources, ds)
	}
	return f.Reload()
}
424470
func AppendToFile(srcFile, destFile string) error {
	if FileExists(destFile) {
		f, err := os.OpenFile(destFile, os.O_APPEND|os.O_WRONLY, 0666)
		if err != nil {
			return fmt.Errorf("Failed to open %s. %s \n", destFile, err.Error())
		}

		defer f.Close()

		srcFileContent, err := ReadFileContents(srcFile)
		if err != nil {
			return fmt.Errorf("Failed to read %s. %s \n", srcFile, err.Error())
		}
		srcFileContent = fmt.Sprintf("\n%s\n", srcFileContent)
		if _, err = f.WriteString(srcFileContent); err != nil {
			return fmt.Errorf("Failed to append from %s. %s \n", srcFile, err.Error())
		}
	} else {
		err := CopyFile(srcFile, destFile)
		if err != nil {
			return fmt.Errorf("Failed to copy %s. %s \n", srcFile, err.Error())
		}
	}
	return nil
}
239338
func addFormFile(writer *multipart.Writer, name, path string) error {
	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()
	part, err := writer.CreateFormFile(name, filepath.Base(path))
	if err != nil {
		return err
	}

	_, err = io.Copy(part, file)

	return err
}