// newIgnoreChecker uses ignoredFiles to build and return a func that returns whether the file path argument should be ignored. See IsIgnoredFile for the ignore rules.
519700
func newIgnoreChecker(ignoredFiles []string) func(path string) (shouldIgnore bool) {
	var fns []func(string) bool

	// copy of ignoredFiles for us to mutate
	ignFiles := append([]string(nil), ignoredFiles...)
	for k, v := range ignFiles {
		if strings.HasPrefix(v, filepath.FromSlash("~/")) {
			ignFiles[k] = filepath.Join(osutilHomeDir(), v[2:])
		}
	}
	// We cache the ignoredFiles patterns in 3 categories (not necessarily exclusive):
	// 1) shell patterns
	// 3) absolute paths
	// 4) paths components
	for _, pattern := range ignFiles {
		pattern := pattern
		_, err := filepath.Match(pattern, "whatever")
		if err == nil {
			fns = append(fns, func(v string) bool { return isShellPatternMatch(pattern, v) })
		}
	}
	for _, pattern := range ignFiles {
		pattern := pattern
		if filepath.IsAbs(pattern) {
			fns = append(fns, func(v string) bool { return hasDirPrefix(filepath.Clean(pattern), v) })
		} else {
			fns = append(fns, func(v string) bool { return hasComponent(filepath.Clean(pattern), v) })
		}
	}

	return func(path string) bool {
		for _, fn := range fns {
			if fn(path) {
				return true
			}
		}
		return false
	}
}
735828
func NewPlainFileLogger(name, file string, l LevelInfo) (Sender, error) {
	s, err := MakePlainFileLogger(file)
	if err != nil {
		return nil, err
	}

	return setup(s, name, l)
}
1331307
func OptImportOptionsIgnoreKeyCheck(b bool) ImportOption {
	return func(o *ImportOptions) error {
		o.IgnoreKeyCheck = b
		return nil
	}
}
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}
}
1310043
func NewVerifierFromFile(jwtcertPath string, redirectURI string, redirectOnFail, redirectOnNoToken bool) (*PKIJWTVerifier, error) {
	jwtCertPEM, err := ioutil.ReadFile(jwtcertPath)
	if err != nil {
		return nil, fmt.Errorf("failed to read JWT signing certificates or public keys from file: %s", err)
	}
	return NewVerifierFromPEM(jwtCertPEM, redirectURI, redirectOnFail, redirectOnNoToken)
}
161401
func fileBackedSigner(root *Root, policy *config.Signing) (signer.Signer, bool, error) {
	keyFile := root.Config["key-file"]
	certFile := root.Config["cert-file"]

	if keyFile == "" {
		return nil, false, nil
	}

	signer, err := local.NewSignerFromFile(certFile, keyFile, policy)
	return signer, true, err
}
380940
func NewFlagCheckOption(flag bool) Option {
	return &option{optionType: flagCheckOption, value: NewFlagCheckFilter(flag)}
}
296860
func IgnoreDefault() bool {
	b, _ := strconv.ParseBool(os.Getenv(IgnoreDefaultEnv))
	return b
}
429550
func NewGrantCheck(check GrantChecker, handler GrantHandler, errorHandler GrantErrorHandler) osinserver.AuthorizeHandler {
	return &GrantCheck{check, handler, errorHandler}
}
262193
func newDiskCertProvider(certPath, keyPath string, logf, errf func(string, ...interface{})) (*diskCertProvider, error) {
	dcp := &diskCertProvider{
		certPath: certPath,
		keyPath:  keyPath,
	}
	if err := dcp.loadCertAndKey(); err != nil {
		return nil, err
	}

	// create watcher
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return nil, err
	}
	// don't close, as it runs forever
	// defer watcher.Close()

	addWatch := func(path string) error {
		if err := watcher.Add(certPath); err != nil {
			return err
		}

		// if this is a valid symlink, watch its target too
		if path, err := filepath.EvalSymlinks(certPath); err == nil && path != certPath {
			if err := watcher.Add(path); err != nil {
				return err
			}
		}

		return nil
	}

	go func() {
		for {
			select {
			case <-watcher.Events:
				if err := dcp.loadCertAndKey(); err != nil {
					errf("could not load cert and key: %v", err)
				} else {
					logf("loaded updated certificate")
				}

				// in case we're dealing with symlinks and the target changed,
				// make sure we continue to watch properly
				if err := addWatch(certPath); err != nil {
					errf("could not add watch: %v", err)
				}

			case err := <-watcher.Errors:
				errf("%v", err)
			}
		}
	}()

	// watch the first certificate file
	if err := addWatch(certPath); err != nil {
		return nil, err
	}

	return dcp, nil
}
493845
func NewConstraintChecker(ctx Context, constraints []*structs.Constraint) *ConstraintChecker {
	return &ConstraintChecker{
		ctx:         ctx,
		constraints: constraints,
	}
}
696821
func (cmd *CheckCommand) checkCacheFile(path string) error {
	fmt.Fprintf(cmd.Stderr, "%s: ignoring cache file\n", path)
	return nil
}
611822
func newFileCompare(filename string) func(string) bool {
	fstat, fstatErr := os.Stat(filename)
	return func(compare string) bool {
		if filename == compare {
			return true
		}
		if fstatErr != nil {
			return false
		}
		if s, err := os.Stat(compare); err == nil {
			return os.SameFile(fstat, s)
		}
		return false
	}
}
622017
func newCheckWatcher(logger log.Logger, consul ChecksAPI) *checkWatcher {
	return &checkWatcher{
		consul:        consul,
		pollFreq:      defaultPollFreq,
		checkUpdateCh: make(chan checkWatchUpdate, 8),
		done:          make(chan struct{}),
		logger:        logger.ResetNamed("consul.health"),
	}
}
690409
func NewFileBlockWithPtrs(isInd bool) BlockWithPtrs {
	fb := NewFileBlock().(*FileBlock)
	fb.IsInd = isInd
	return fb
}
406963
func NewCheck() *Check {
	ch := &Check{}
	ch.manualOverride.Store(false)
	ch.manualHealthState.Store(false)
	return ch
}
1060268
func DirCheck(filePath string) error {
	dir := filepath.Dir(filePath)
	if !FileExists(dir) {
		return os.MkdirAll(dir, 0777)
	}
	return nil
}