Compare commits

..

3 Commits

Author SHA1 Message Date
Frederik Ring
0c666d0c88 use lstat when checking whether file is a symlink 2021-11-03 18:07:55 +01:00
Frederik Ring
a0402b407d fix fileinfo mode comparison when checking for symlinks 2021-11-03 18:03:44 +01:00
Frederik Ring
3193e88fc0 os.FileInfo cannot be used for deleting files as it does not contain a full path 2021-11-02 06:40:37 +01:00

View File

@@ -516,8 +516,24 @@ func (s *script) pruneOldBackups() error {
)
}
var candidates []os.FileInfo
var candidates []string
for _, candidate := range globMatches {
fi, err := os.Lstat(candidate)
if err != nil {
return fmt.Errorf(
"pruneOldBackups: error calling Lstat on file %s: %w",
candidate,
err,
)
}
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
candidates = append(candidates, candidate)
}
}
var matches []string
for _, candidate := range candidates {
fi, err := os.Stat(candidate)
if err != nil {
return fmt.Errorf(
@@ -526,22 +542,15 @@ func (s *script) pruneOldBackups() error {
err,
)
}
if fi.Mode() != os.ModeSymlink {
candidates = append(candidates, fi)
}
}
var matches []os.FileInfo
for _, candidate := range candidates {
if candidate.ModTime().Before(deadline) {
if fi.ModTime().Before(deadline) {
matches = append(matches, candidate)
}
}
if len(matches) != 0 && len(matches) != len(candidates) {
var removeErrors []error
for _, candidate := range matches {
if err := os.Remove(candidate.Name()); err != nil {
for _, match := range matches {
if err := os.Remove(match); err != nil {
removeErrors = append(removeErrors, err)
}
}