os.FileInfo cannot be used for deleting files as it does not contain a full path

This commit is contained in:
Frederik Ring 2021-11-02 06:40:37 +01:00
parent c391230be6
commit 3193e88fc0

View File

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