Skip to content

Commit

Permalink
Simplify test for broken symlink
Browse files Browse the repository at this point in the history
There's no need to read the link. If it's a link and the target is
missing, it can be ignored. (Why not just ignore any missing file?
Because a missing file might indicate some other problem, so better to
let it fail).

Signed-off-by: Michael Bridgen <[email protected]>
  • Loading branch information
squaremo committed Apr 2, 2021
1 parent 40699c1 commit a899d86
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions controllers/imageupdateautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ func commitChangedManifests(repo *gogit.Repository, absRepoPath string, ent *ope

// go-git has [a bug](https://github.com/go-git/go-git/issues/253)
// whereby it thinks broken symlinks to absolute paths are
// modified; and, there's no circumstance in which we want to
// commit a change to a broken symlink: so, skip those.
// modified. There's no circumstance in which we want to commit a
// change to a broken symlink: so, detect and skip those.
var changed bool
for file, _ := range status {
abspath := filepath.Join(absRepoPath, file)
Expand All @@ -492,13 +492,10 @@ func commitChangedManifests(repo *gogit.Repository, absRepoPath string, ent *ope
}
if info.Mode()&os.ModeSymlink > 0 {
// symlinks are OK; broken symlinks are probably a result
// of the bug mentioned above, but not of interest anyway.
if _, err := os.Readlink(abspath); err != nil {
return "", fmt.Errorf("problem reading symlink: %w", err)
} else {
if _, err := os.Stat(abspath); os.IsNotExist(err) {
continue
}
// of the bug mentioned above, but not of interest in any
// case.
if _, err := os.Stat(abspath); os.IsNotExist(err) {
continue
}
}
working.Add(file)
Expand Down

0 comments on commit a899d86

Please sign in to comment.