// shouldWriteFile returns whether a new version of a file should be written to disk.
345244
func shouldWriteFile(path string, content []byte) (bool, error) {
	_, err := os.Lstat(path)
	if os.IsNotExist(err) {
		return true, nil
	}

	contentOnFs, err := ioutil.ReadFile(path)
	if err != nil {
		return false, err
	}

	return (bytes.Compare(content, contentOnFs) != 0), nil
}
648289
func (mock *Mock) WriteFile(file string, data []byte) error {
	items := mock.getReturnValues("WriteFile")
	return items[0].(error)
}
1267976
func (n SkipCompressedFilter) ShouldCompress(w http.ResponseWriter) bool {
	switch w.Header().Get("Content-Encoding") {
	case "gzip", "compress", "deflate", "br":
		return false
	default:
		return true
	}
}
1107235
func ShouldRecord(cmd *cobra.Command, info *resource.Info) bool {
	return GetRecordFlag(cmd) || ContainsChangeCause(info)
}
354159
func (pdfg *PDFGenerator) WriteFile(filename string) error {
	return ioutil.WriteFile(filename, pdfg.Bytes(), 0666)
}
472368
func (b *Builder) shouldParseFile(path string) bool {
	configFormat := b.stringVal(b.Flags.ConfigFormat)
	srcFormat := FormatFrom(path)

	// If config-format is not set, only read files with supported extensions
	if configFormat == "" && srcFormat != "hcl" && srcFormat != "json" {
		return false
	}
	return true
}
392777
func WriteToFile(filename, content string) {
	f, err := os.Create(filename)
	MustCheck(err)
	defer CloseFile(f)
	_, err = f.WriteString(content)
	MustCheck(err)
}
1150247
func NewWFile(f *File, read bool, write bool) (WFile, error) {
	data, err := fileData(f)
	if err != nil {
		return nil, err
	}
	w := &file{f: f, data: data, readable: read, writable: write}
	runtime.SetFinalizer(w, closeFile)
	return w, nil
}
994931
func NewFile(filename string, opts ...FileConfig) (*File, error) {
	var (
		path string
		f    *os.File
		err  error
	)

	if path, err = filepath.Abs(filename); err != nil {
		return nil, err
	}

	if f, err = os.OpenFile(filename, os.O_RDONLY, 0); err != nil {
		return nil, err
	}

	if _, err = f.Seek(0, os.SEEK_END); err != nil {
		_ = f.Close()
		return nil, err
	}

	t := &File{
		filename: path,
		file:     f,

		ring: rbuf.NewFixedSizeRingBuf(4096),

		errc: make(chan error),
	}

	for _, opt := range opts {
		err := opt(t)
		if err != nil {
			return nil, err
		}
	}

	switch t.rotationStrat {
	case "notify":
		if err := t.notifyOnChanges(); err != nil {
			return nil, err
		}
	default:
		go t.pollForUpdates(PollIntervalFast)
		go t.pollForRotations(PollIntervalSlow)
	}

	return t, nil
}
831816
func isValidFile(file *os.File) error {
	finfo, err := file.Stat()
	if err != nil {
		return err
	}
	if mode := finfo.Mode(); mode.IsDir() {
		return fmt.Errorf("A directory is not a valid file")
	}
	return nil
}
633214
func (writer *NsenterWriter) WriteFile(filename string, data []byte, perm os.FileMode) error {
	cmd := "nsenter"
	base_args := []string{
		"--mount=/rootfs/proc/1/ns/mnt",
		"--",
	}

	echo_args := append(base_args, "sh", "-c", fmt.Sprintf("cat > %s", filename))
	glog.V(5).Infof("Command to write data to file: %v %v", cmd, echo_args)
	command := exec.Command(cmd, echo_args...)
	command.Stdin = bytes.NewBuffer(data)
	outputBytes, err := command.CombinedOutput()
	if err != nil {
		glog.Errorf("Output from writing to %q: %v", filename, string(outputBytes))
		return err
	}

	chmod_args := append(base_args, "chmod", fmt.Sprintf("%o", perm), filename)
	glog.V(5).Infof("Command to change permissions to file: %v %v", cmd, chmod_args)
	outputBytes, err = exec.Command(cmd, chmod_args...).CombinedOutput()
	if err != nil {
		glog.Errorf("Output from chmod command: %v", string(outputBytes))
		return err
	}

	return nil
}
1265488
func NewSplitFile(outpath, errpath string, overwrite bool) (*File, error) {
	fl := new(File)

	var err error

	if overwrite {
		fl.fo, err = os.Create(outpath)
	} else {
		fl.fo, err = os.OpenFile(outpath, os.O_WRONLY|os.O_APPEND, 0644)
	}

	if err != nil {
		return nil, err
	}

	if overwrite {
		fl.fe, err = os.Create(errpath)
	} else {
		fl.fe, err = os.OpenFile(errpath, os.O_WRONLY|os.O_APPEND, 0644)
	}

	if err != nil {
		fl.Close()
		return nil, err
	}

	fl.LogWriter = NewLogWriter(fl.fo, fl.fe)
	return fl, nil
}
144508
func (d *Dir) WriteFile(subPath string, data []byte, perm os.FileMode) error {
	dirPath := path.Dir(subPath)
	d.MkdirAll(dirPath, perm)
	node, err := d.GetByPath(subPath)
	if err != nil {
		//create new file if not exist
		node, err = d.GetByPath(dirPath)
		if err != nil {
			return err
		}
		if !node.IsDir() {
			return fmt.Errorf("There is a file on path " + dirPath)
		}
		var baseDir = node.(*Dir)
		baseDir.AddNode(&File{
			name:     path.Base(subPath),
			filemode: perm,
			time:     time.Now(),
			data:     data,
		})
		return nil
	}
	//overwrite file
	if node.IsDir() {
		return fmt.Errorf("Use WriteFile on directory")
	}
	var file = node.(*File)
	file.SetData(data)
	return nil
}
640060
func UpdateFile(filename string, filedata string) bool {
	f, err := os.Create(filename)
	if err != nil {
		fmt.Println(err)
		return false
	}
	n, err := io.WriteString(f, filedata)
	if err != nil {
		fmt.Println(n, err)
		return false
	}
	f.Close()
	return true
}
10249
func NewFile(path string, overwrite bool) (*File, error) {
	fl := new(File)

	var err error

	if overwrite {
		fl.fo, err = os.Create(path)
	} else {
		fl.fo, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0644)
	}

	if err != nil {
		return nil, err
	}

	fl.LogWriter = NewLogWriter(fl.fo, fl.fo)
	return fl, nil
}
862696
func (f *StandaloneFile) WriteFile(data []byte, perm os.FileMode) error {
	return f.filespace.WriteFile(f.path, data, perm)
}
1371703
func CreateFile(filename string, opts *BlockOption) (*os.File, error) {
	image, err := os.Create(filename)
	if err != nil {
		return nil, err
	}

	return image, nil
}