diff options
author | Matthew Holt <[email protected]> | 2019-09-06 12:57:12 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2019-09-06 12:57:12 -0600 |
commit | 4bd949652564eff8ccfc50f105f0d35f0af26402 (patch) | |
tree | f8ffe2a0fb300a5aa0c4337f70314d45b0e817f5 /modules/caddyhttp/fileserver/matcher.go | |
parent | 14f9662f9cc0f93e88d5efbbaf10de79070bea93 (diff) | |
download | caddy-4bd949652564eff8ccfc50f105f0d35f0af26402.tar.gz caddy-4bd949652564eff8ccfc50f105f0d35f0af26402.zip |
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.
Diffstat (limited to 'modules/caddyhttp/fileserver/matcher.go')
-rw-r--r-- | modules/caddyhttp/fileserver/matcher.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/modules/caddyhttp/fileserver/matcher.go b/modules/caddyhttp/fileserver/matcher.go index 99e217ed6..88ce1d026 100644 --- a/modules/caddyhttp/fileserver/matcher.go +++ b/modules/caddyhttp/fileserver/matcher.go @@ -207,10 +207,22 @@ func (m MatchFile) selectFile(r *http.Request) (rel, abs string, matched bool) { 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 { _, 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 ( |