From ee2026d9a6e8ea59ae7861bb642e8919da7667b9 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Fri, 2 Apr 2021 17:53:10 +0100 Subject: [PATCH] Simplify test for broken symlink 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 --- controllers/imageupdateautomation_controller.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/controllers/imageupdateautomation_controller.go b/controllers/imageupdateautomation_controller.go index 6b0896db..b3d4a6ba 100644 --- a/controllers/imageupdateautomation_controller.go +++ b/controllers/imageupdateautomation_controller.go @@ -509,8 +509,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) @@ -520,13 +520,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)