feature (plg_backend_local): better error handling

This commit is contained in:
MickaelK
2024-01-01 23:31:45 +11:00
parent 80a28d88e7
commit 6ad16259ef
+7 -1
View File
@@ -1,6 +1,8 @@
package common
import (
"errors"
"io/fs"
"os"
"syscall"
)
@@ -10,5 +12,9 @@ func SafeOsOpenFile(path string, flag int, perm os.FileMode) (*os.File, error) {
Log.Debug("common::files safeOsOpenFile err[%s] path[%s]", err.Error(), path)
return nil, ErrFilesystemError
}
return os.OpenFile(path, flag|syscall.O_NOFOLLOW, perm)
f, err := os.OpenFile(path, flag|syscall.O_NOFOLLOW, perm)
if err != nil && errors.Is(err, fs.ErrNotExist) {
return nil, ErrNotFound
}
return f, err
}