MCPcopy
hub / github.com/caddyserver/caddy / strictFileExists

Method strictFileExists

modules/caddyhttp/fileserver/matcher.go:550–571  ·  view source on GitHub ↗

strictFileExists returns true if file exists and matches the convention of the given file path. If the path ends in a forward slash, the file must also be a directory; if it does NOT end in a forward slash, the file must NOT be a directory.

(fileSystem fs.FS, file string)

Source from the content-addressed store, hash-verified

548// NOT end in a forward slash, the file must NOT
549// be a directory.
550func (m MatchFile) strictFileExists(fileSystem fs.FS, file string) (os.FileInfo, bool) {
551 info, err := fs.Stat(fileSystem, file)
552 if err != nil {
553 // in reality, this can be any error
554 // such as permission or even obscure
555 // ones like "is not a directory" (when
556 // trying to stat a file within a file);
557 // in those cases we can't be sure if
558 // the file exists, so we just treat any
559 // error as if it does not exist; see
560 // https://stackoverflow.com/a/12518877/1048862
561 return nil, false
562 }
563 if strings.HasSuffix(file, separator) {
564 // by convention, file paths ending
565 // in a path separator must be a directory
566 return info, info.IsDir()
567 }
568 // by convention, file paths NOT ending
569 // in a path separator must NOT be a directory
570 return info, !info.IsDir()
571}
572
573// firstSplit returns the first result where the path
574// can be split in two by a value in m.SplitPath. The

Callers 1

selectFileMethod · 0.95

Calls 1

StatMethod · 0.80

Tested by

no test coverage detected