fileutils: use fileutils.{Le,E}xists()

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2024-04-04 16:03:46 +02:00
parent 336611b4d0
commit 81c2f5f2d0
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772
1 changed files with 2 additions and 2 deletions

View File

@ -344,7 +344,7 @@ func ReadSymlinkedPath(path string) (realPath string, err error) {
if realPath, err = filepath.EvalSymlinks(realPath); err != nil {
return "", fmt.Errorf("failed to canonicalise path for %q: %w", path, err)
}
if _, err := os.Stat(realPath); err != nil {
if err := Exists(realPath); err != nil {
return "", fmt.Errorf("failed to stat target %q of %q: %w", realPath, path, err)
}
return realPath, nil
@ -352,7 +352,7 @@ func ReadSymlinkedPath(path string) (realPath string, err error) {
// CreateIfNotExists creates a file or a directory only if it does not already exist.
func CreateIfNotExists(path string, isDir bool) error {
if _, err := os.Stat(path); err != nil {
if err := Exists(path); err != nil {
if os.IsNotExist(err) {
if isDir {
return os.MkdirAll(path, 0o755)