mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-22 13:20:29 +01:00
os.FileInfo cannot be used for deleting files as it does not contain a full path
This commit is contained in:
parent
c391230be6
commit
3193e88fc0
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user