Skip to content

Commit

Permalink
Do not wrap errors from filepath and stat as they are already wrapped.
Browse files Browse the repository at this point in the history
Since errors from filepath and lstat are already wrapped, they
do not need to be wrapped again. Wrapping them again will
cause os.IsErrNotExist(err) to return false while some providers
may want it to be true.

Signed-off-by: Manu Gupta <manugupt1@gmail.com>
  • Loading branch information
manugupt1 committed Apr 7, 2022
1 parent 0335593 commit 9edc129
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions mountinfo/mounted_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package mountinfo

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -33,13 +32,13 @@ func mountedByStat(path string) (bool, error) {

func normalizePath(path string) (realPath string, err error) {
if realPath, err = filepath.Abs(path); err != nil {
return "", fmt.Errorf("unable to get absolute path for %q: %w", path, err)
return "", err
}
if realPath, err = filepath.EvalSymlinks(realPath); err != nil {
return "", fmt.Errorf("failed to canonicalise path for %q: %w", path, err)
return "", err
}
if _, err := os.Stat(realPath); err != nil {
return "", fmt.Errorf("failed to stat target of %q: %w", path, err)
return "", err
}
return realPath, nil
}
Expand Down

0 comments on commit 9edc129

Please sign in to comment.