Merge pull request #745 from elezar/fix-symlink-logging

Fix symlink resolution error message
This commit is contained in:
Evan Lezar 2024-10-17 18:04:54 +02:00 committed by GitHub
commit e5175c270e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 11 deletions

View File

@ -211,21 +211,14 @@ func changeRoot(current string, new string, path string) (string, error) {
// Locate returns the link target of the specified filename or an empty slice if the // Locate returns the link target of the specified filename or an empty slice if the
// specified filename is not a symlink. // specified filename is not a symlink.
func (m command) Locate(filename string) ([]string, error) { func (m command) Locate(filename string) ([]string, error) {
info, err := os.Lstat(filename) target, err := symlinks.Resolve(filename)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get file info: %v", info) return nil, err
} }
if info.Mode()&os.ModeSymlink == 0 { if target == filename {
m.logger.Debugf("%v is not a symlink", filename) m.logger.Debugf("%v is not a symlink", filename)
return nil, nil return nil, nil
} }
target, err := os.Readlink(filename)
if err != nil {
return nil, fmt.Errorf("error checking symlink: %v", err)
}
m.logger.Debugf("Resolved link: '%v' => '%v'", filename, target) m.logger.Debugf("Resolved link: '%v' => '%v'", filename, target)
return []string{target}, nil return []string{target}, nil
} }

View File

@ -25,7 +25,7 @@ import (
func Resolve(filename string) (string, error) { func Resolve(filename string) (string, error) {
info, err := os.Lstat(filename) info, err := os.Lstat(filename)
if err != nil { if err != nil {
return filename, fmt.Errorf("failed to get file info: %v", info) return filename, fmt.Errorf("failed to get file info: %w", err)
} }
if info.Mode()&os.ModeSymlink == 0 { if info.Mode()&os.ModeSymlink == 0 {
return filename, nil return filename, nil