Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
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.
Matthew Holt committed
Sep 6, 2019 at 12:57 UTC
4bd949652564eff8ccfc50f105f0d35f0af26402
1 file changed
+14
-2
modules/caddyhttp/fileserver/matcher.go
+14
-2
@@ -207,10 +207,22 @@ func (m MatchFile) selectFile(r *http.Request) (rel, abs string, matched bool) {
207
return
208
}
209
210
-// fileExists returns true if file exists.
210
+// fileExists returns true if file exists,
211
+// false if it doesn't, or false if there
212
+// was any other error.
213
func fileExists(file string) bool {
214
_, err := os.Stat(file)
213
- return !os.IsNotExist(err)
215
+ if err == nil {
216
+ return true
217
+ } else if os.IsNotExist(err) {
218
+ return false
219
+ } else {
220
+ // we don't know if it exists,
221
+ // so assume it doesn't, since
222
+ // there must have been some
223
+ // other error anyway
224
+ return false
225
+ }
226
}
227
228
const (