// FileChecker checks the existence of a file and returns an error
// if the file exists.
325865
func FileChecker(f string) health.Checker {
	return health.CheckFunc(func() error {
		if _, err := os.Stat(f); err == nil {
			return errors.New("file exists")
		}
		return nil
	})
}
611765
func FileChecksum(filepath string, hsh hash.Hash) (string, error) {
	src, err := os.Open(filepath)
	if err != nil {
		return "", err
	}
	defer src.Close()

	_, err = io.Copy(hsh, src)
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%x", hsh.Sum(nil)), nil
}
1207119
func FileExists(t TestingT, path string, msgAndArgs ...interface{}) bool {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	info, err := os.Lstat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return Fail(t, fmt.Sprintf("unable to find file %q", path), msgAndArgs...)
		}
		return Fail(t, fmt.Sprintf("error when running os.Lstat(%q): %s", path, err), msgAndArgs...)
	}
	if info.IsDir() {
		return Fail(t, fmt.Sprintf("%q is a directory", path), msgAndArgs...)
	}
	return true
}
41223
func NewFileChecksumGenerator(blocksize uint) *FileChecksumGenerator {
	return &FileChecksumGenerator{
		BlockSize:       blocksize,
		WeakRollingHash: rollsum.NewRollsum32Base(blocksize),
		//WeakRollingHash:  rollsum.NewRollsum16Base(blocksize),
		StrongHash:       DefaultStrongHashGenerator(),
		FileChecksumHash: DefaultFileHashGenerator(),
	}
}
261166
func (daemon *Daemon) checkContainer(container *container.Container, conditions ...func(*container.Container) error) error {
	for _, condition := range conditions {
		if err := condition(container); err != nil {
			return err
		}
	}
	return nil
}
994187
func (check *FileChecksumGenerator) Reset() {
	check.WeakRollingHash.Reset()
	check.StrongHash.Reset()
	check.FileChecksumHash.Reset()
}
970797
func (f *File) Check() {
	// TODO
	typs := make(map[ast.Expr]types.TypeAndValue)
	defs := make(map[*ast.Ident]types.Object)
	uses := make(map[*ast.Ident]types.Object)
	config := types.Config{FakeImportC: true}
	config.Importer = importer.Default()
	info := &types.Info{Types: typs, Defs: defs, Uses: uses}
	astFiles := []*ast.File{f.ast}
	typesPkg, err := config.Check(fileDir(f), f.fs, astFiles, info)
	if err != nil {
		log.Fatalf("checking package: %s", err)
	}
	f.Info = info
	f.Pkg = typesPkg
}
989399
func DirChecksum(expected map[string]string, dir string) *Result {
	actual, err := checkDir(dir, false)
	if err != nil {
		return &Result{err: err.Error()}
	}
	return Interface(expected, actual)
}
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
	}
}
1070105
func (ns *Namespace) FileExists(i interface{}) (bool, error) {
	path, err := cast.ToStringE(i)
	if err != nil {
		return false, err
	}

	if path == "" {
		return false, errors.New("fileExists needs a path to a file")
	}

	status, err := afero.Exists(ns.readFileFs, path)
	if err != nil {
		return false, err
	}

	return status, nil
}
1060268
func DirCheck(filePath string) error {
	dir := filepath.Dir(filePath)
	if !FileExists(dir) {
		return os.MkdirAll(dir, 0777)
	}
	return nil
}
383132
func checkFile(filename string) error {
	info, err := os.Stat(filename)
	if err != nil {
		return fmt.Errorf("failed stat on %s: %v", filename, err)
	}
	// Check the unix permission bits
	if info.Mode().Perm()&0377 != 0 {
		return fmt.Errorf("file (%v) has insecure file permissions (%v)", filename, info.Mode().String())
	}
	return nil
}
1298933
func CheckEOF(in IndexInput) error {
	if in.FilePointer() != in.Length() {
		return errors.New(fmt.Sprintf(
			"did not read all bytes from file: read %v vs size %v (resources: %v)",
			in.FilePointer(), in.Length(), in))
	}
	return nil
}
781657
func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) {
	if h, ok := a.t.(tHelper); ok {
		h.Helper()
	}
	FileExistsf(a.t, path, msg, args...)
}
808109
func (nrt *NRTCachingDirectory) FileExists(name string) bool {
	nrt.Lock() // synchronized
	defer nrt.Unlock()
	return nrt._fileExists(name)
}
763423
func NewChecker(policy *audit.Policy) Checker {
	for i, rule := range policy.Rules {
		policy.Rules[i].OmitStages = unionStages(policy.OmitStages, rule.OmitStages)
	}
	return &policyChecker{*policy}
}
917164
func (ds *DiskStorage) checkFS() (ret error) {
	tempdir, err := ioutil.TempDir(ds.root, "")
	if err != nil {
		return fmt.Errorf("localdisk check: unable to create tempdir in %s, err=%v", ds.root, err)
	}
	defer func() {
		err := os.RemoveAll(tempdir)
		if err != nil {
			cleanErr := fmt.Errorf("localdisk check: unable to clean temp dir: %v", err)
			if ret == nil {
				ret = cleanErr
			} else {
				log.Printf("WARNING: %v", cleanErr)
			}
		}
	}()

	tempfile := filepath.Join(tempdir, "FILE.tmp")
	filename := filepath.Join(tempdir, "FILE")
	data := []byte("perkeep rocks")
	err = ioutil.WriteFile(tempfile, data, 0644)
	if err != nil {
		return fmt.Errorf("localdisk check: unable to write into %s, err=%v", ds.root, err)
	}

	out, err := ioutil.ReadFile(tempfile)
	if err != nil {
		return fmt.Errorf("localdisk check: unable to read from %s, err=%v", tempfile, err)
	}
	if bytes.Compare(out, data) != 0 {
		return fmt.Errorf("localdisk check: tempfile contents didn't match, got=%q", out)
	}
	if _, err := os.Lstat(filename); !os.IsNotExist(err) {
		return fmt.Errorf("localdisk check: didn't expect file to exist, Lstat had other error, err=%v", err)
	}
	if err := os.Rename(tempfile, filename); err != nil {
		return fmt.Errorf("localdisk check: rename failed, err=%v", err)
	}
	if _, err := os.Lstat(filename); err != nil {
		return fmt.Errorf("localdisk check: after rename passed Lstat had error, err=%v", err)
	}
	return nil
}