diff --git a/server/common/files.go b/server/common/files.go index bbc17fdb..26ee6e15 100644 --- a/server/common/files.go +++ b/server/common/files.go @@ -76,7 +76,7 @@ func SafeOsMkdir(path string, mode os.FileMode) error { Log.Debug("common::files safeOsMkdir err[%s] path[%s]", err.Error(), path) return ErrFilesystemError } - return os.Mkdir(path, mode) + return processError(os.Mkdir(path, mode)) } func SafeOsRemove(path string) error { @@ -84,7 +84,7 @@ func SafeOsRemove(path string) error { Log.Debug("common::files safeOsRemove err[%s] path[%s]", err.Error(), path) return ErrFilesystemError } - return os.Remove(path) + return processError(os.Remove(path)) } func SafeOsRemoveAll(path string) error { @@ -92,7 +92,7 @@ func SafeOsRemoveAll(path string) error { Log.Debug("common::files safeOsRemoveAll err[%s] path[%s]", err.Error(), path) return ErrFilesystemError } - return os.RemoveAll(path) + return processError(os.RemoveAll(path)) } func SafeOsRename(from string, to string) error { @@ -103,7 +103,7 @@ func SafeOsRename(from string, to string) error { Log.Debug("common::files safeOsRemove err[%s] to[%s]", err.Error(), to) return ErrFilesystemError } - return os.Rename(from, to) + return processError(os.Rename(from, to)) } func safePath(path string) error { @@ -121,3 +121,16 @@ func safePath(path string) error { } return nil } + +func processError(err error) error { + if err == nil { + return nil + } + if pe, ok := err.(*os.PathError); ok { + return pe.Err + } + if le, ok := err.(*os.LinkError); ok { + return le.Err + } + return err +} diff --git a/server/common/files_linux.go b/server/common/files_linux.go index 614b550e..ecb649dc 100644 --- a/server/common/files_linux.go +++ b/server/common/files_linux.go @@ -13,8 +13,11 @@ func SafeOsOpenFile(path string, flag int, perm os.FileMode) (*os.File, error) { return nil, ErrFilesystemError } f, err := os.OpenFile(path, flag|syscall.O_NOFOLLOW, perm) - if err != nil && errors.Is(err, fs.ErrNotExist) { - return nil, ErrNotFound + if err != nil { + if errors.Is(err, fs.ErrNotExist) { + return nil, ErrNotFound + } + return nil, processError(err) } return f, err }