Don't crash on stat error in ensureDir (fixes #2608)

I'm not really sure under what circumstances MkdirAll returns a nil
error but a subsequent stat fails, but apparently it can happen and we
need to handle it. The "mode >= 0" was a no-op, and we never call
ensureDir anyway without the intention of ensuring the mode, so removed
that.
This commit is contained in:
Jakob Borg
2015-12-21 08:35:24 +01:00
parent eb1a234a77
commit 4a97aa12d6

View File

@@ -1036,13 +1036,17 @@ func ensureDir(dir string, mode os.FileMode) {
l.Fatalln(err) l.Fatalln(err)
} }
fi, _ := os.Stat(dir) if fi, err := os.Stat(dir); err == nil {
currentMode := fi.Mode() & 0777 // Apprently the stat may fail even though the mkdirall passed. If it
if mode >= 0 && currentMode != mode { // does, we'll just assume things are in order and let other things
err := os.Chmod(dir, mode) // fail (like loading or creating the config...).
// This can fail on crappy filesystems, nothing we can do about it. currentMode := fi.Mode() & 0777
if err != nil { if currentMode != mode {
l.Warnln(err) err := os.Chmod(dir, mode)
// This can fail on crappy filesystems, nothing we can do about it.
if err != nil {
l.Warnln(err)
}
} }
} }
} }