Fix Schrodinger's file existence check in file matcher

See: https://stackoverflow.com/a/12518877/1048862

For example, trying to check the existence of "/www/index.php/index.php"
fails but not with an os.IsNotExist()-type error. So we have to assume
that a file that cannot be successfully stat'ed at all does not exist.
This commit is contained in:
Matthew Holt 2019-09-06 12:57:12 -06:00
parent 14f9662f9c
commit 4bd9496525
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
1 changed files with 14 additions and 2 deletions

View File

@ -207,10 +207,22 @@ func (m MatchFile) selectFile(r *http.Request) (rel, abs string, matched bool) {
return return
} }
// fileExists returns true if file exists. // fileExists returns true if file exists,
// false if it doesn't, or false if there
// was any other error.
func fileExists(file string) bool { func fileExists(file string) bool {
_, err := os.Stat(file) _, err := os.Stat(file)
return !os.IsNotExist(err) if err == nil {
return true
} else if os.IsNotExist(err) {
return false
} else {
// we don't know if it exists,
// so assume it doesn't, since
// there must have been some
// other error anyway
return false
}
} }
const ( const (