// checkWriteFiles checks to make sure that the target file can actually be
// written. Note that this check is approximate (it only checks to see if the file
// is under /usr).
196061
func checkWriteFiles(cfg node, report *Report) {
	for _, f := range cfg.Child("write_files").children {
		c := f.Child("path")
		if !c.IsValid() {
			continue
		}

		d := path.Dir(c.String())
		switch {
		case strings.HasPrefix(d, "/usr"):
			report.Error(c.line, "file cannot be written to a read-only filesystem")
		}
	}
}
417603
func (f *File) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
	f.folder.fs.logEnter(ctx, "WriteFile")
	defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()

	if offset == -1 {
		ei, err := f.folder.fs.config.KBFSOps().Stat(ctx, f.node)
		if err != nil {
			return 0, err
		}
		offset = int64(ei.Size)
	}

	err = f.folder.fs.config.KBFSOps().Write(ctx, f.node, bs, offset)
	return len(bs), err
}
399546
func (f *ResetCachesFile) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
	f.fs.logEnter(ctx, "ResetCachesFile Write")
	defer func() { f.fs.reportErr(ctx, libkbfs.WriteMode, err) }()
	if len(bs) == 0 {
		return 0, nil
	}
	f.fs.config.ResetCaches()
	return len(bs), nil
}
443256
func (r *realFS) WriteFile(filename string, data []byte, perm os.FileMode) (int, error) {
	return len(data), ioutil.WriteFile(filename, data, perm)
}
846735
func (l *LogFile) Write(b []byte) (n int, err error) {
	// Filter out log entries that do not match log level criteria
	if !l.logFilter.Check(b) {
		return 0, nil
	}

	l.acquire.Lock()
	defer l.acquire.Unlock()
	//Create a new file if we have no file to write to
	if l.FileInfo == nil {
		if err := l.openNew(); err != nil {
			return 0, err
		}
	}
	// Check for the last contact and rotate if necessary
	if err := l.rotate(); err != nil {
		return 0, err
	}
	l.BytesWritten += int64(len(b))
	return l.FileInfo.Write(b)
}
1016793
func (lz *Lz4) CheckExt(filename string) error {
	if filepath.Ext(filename) != ".lz4" {
		return fmt.Errorf("filename must have a .lz4 extension")
	}
	return nil
}
89163
func (fs *statFS) WriteFile(
	ctx context.Context,
	op *fuseops.WriteFileOp) (err error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	fs.mostRecentWriteSize = len(op.Data)
	return
}
1347943
func FileExists(fs utilfs.Filesystem, path string) (bool, error) {
	if info, err := fs.Stat(path); err == nil {
		if info.Mode().IsRegular() {
			return true, nil
		}
		return false, fmt.Errorf("expected regular file at %q, but mode is %q", path, info.Mode().String())
	} else if os.IsNotExist(err) {
		return false, nil
	} else {
		return false, err
	}
}
808109
func (nrt *NRTCachingDirectory) FileExists(name string) bool {
	nrt.Lock() // synchronized
	defer nrt.Unlock()
	return nrt._fileExists(name)
}
205251
func CheckHashes(payload []byte, name string, hashes Hashes) error {
	cnt := 0

	// k, v indicate the hash algorithm and the corresponding value
	for k, v := range hashes {
		switch k {
		case notary.SHA256:
			checksum := sha256.Sum256(payload)
			if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
				return ErrMismatchedChecksum{alg: notary.SHA256, name: name, expected: hex.EncodeToString(v)}
			}
			cnt++
		case notary.SHA512:
			checksum := sha512.Sum512(payload)
			if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
				return ErrMismatchedChecksum{alg: notary.SHA512, name: name, expected: hex.EncodeToString(v)}
			}
			cnt++
		}
	}

	if cnt == 0 {
		return ErrMissingMeta{Role: name}
	}

	return nil
}
1095150
func (s Store) WriteFile(filename string) error {
	buf, err := s.Bytes()
	if err != nil {
		return err
	}

	return ioutil.WriteFile(filename, buf, 0600)
}
1209481
func checkfile(fname string) bool {
  _, err := os.Stat(fname)
  return err == nil
}
681340
func (s *Snappy) CheckExt(filename string) error {
	if filepath.Ext(filename) != ".sz" {
		return fmt.Errorf("filename must have a .sz extension")
	}
	return nil
}
970527
func (file *File) Write(b []byte) (n int, err error) {
	if file.closed {
		err = errors.New("write on closed file")
		return
	}
	if file.aborted {
		err = errors.New("write on aborted file")
		return
	}

	defer func() {
		if err != nil {
			os.Remove(file.tmpfile.Name())
			file.aborted = true
		}
	}()

	n, err = file.tmpfile.Write(b)
	return
}
1364418
func writeFile(path string, contents []byte) {
	handleError(ioutil.WriteFile(path, contents, 0640))
}
812135
func SaveFileS(filePath string, s string) (int, error) {
	return SaveFile(filePath, []byte(s))
}
791764
func FileExists(filePath string) (bool, int64, error) {
	fileInfo, err := os.Stat(filePath)
	if os.IsNotExist(err) {
		return false, 0, nil
	}
	if err != nil {
		return false, 0, errors.Wrapf(err, "error checking if file [%s] exists", filePath)
	}
	return true, fileInfo.Size(), nil
}