mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Ignore result of EvalSymlinks on ENOENT
When the path does not exist, filepath.EvalSymlinks returns an empty string - so we can't just ignore ENOENT, we have to discard the result if an ENOENT is returned. Should fix Jira issue RHEL-37948 Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -288,3 +289,22 @@ func writeStringToPath(path, contents, mountLabel string, uid, gid int) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// If the given path exists, evaluate any symlinks in it. If it does not, clean
|
||||
// the path and return it. Used to try and verify path equality in a somewhat
|
||||
// sane fashion.
|
||||
func evalSymlinksIfExists(toCheck string) (string, error) {
|
||||
checkedVal, err := filepath.EvalSymlinks(toCheck)
|
||||
if err != nil {
|
||||
// If the error is not ENOENT, something more serious has gone
|
||||
// wrong, return it.
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
return "", err
|
||||
}
|
||||
// This is an ENOENT. On ENOENT, EvalSymlinks returns "".
|
||||
// We don't want that. Return a cleaned version of the original
|
||||
// path.
|
||||
return filepath.Clean(toCheck), nil
|
||||
}
|
||||
return checkedVal, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user