Skip to content

Commit

Permalink
Directories aren't excluded from pruning logic
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Feb 28, 2025
1 parent eb4099d commit ad829fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/storage/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (b *localStorage) Prune(deadline time.Time, pruningPrefix string) (*storage
)
}

if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
if !fi.IsDir() && fi.Mode()&os.ModeSymlink != os.ModeSymlink {
candidates = append(candidates, candidate)
}
}
Expand Down
9 changes: 6 additions & 3 deletions internal/storage/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,24 @@ func (b *sshStorage) Prune(deadline time.Time, pruningPrefix string) (*storage.P
}

var matches []string
var numCandidates int
for _, candidate := range candidates {
if !strings.HasPrefix(candidate.Name(), pruningPrefix) {
if candidate.IsDir() || !strings.HasPrefix(candidate.Name(), pruningPrefix) {
continue
}

numCandidates++
if candidate.ModTime().Before(deadline) {
matches = append(matches, candidate.Name())
}
}

stats := &storage.PruneStats{
Total: uint(len(candidates)),
Total: uint(numCandidates),
Pruned: uint(len(matches)),
}

pruneErr := b.DoPrune(b.Name(), len(matches), len(candidates), deadline, func() error {
pruneErr := b.DoPrune(b.Name(), len(matches), numCandidates, deadline, func() error {
for _, match := range matches {
if err := b.sftpClient.Remove(path.Join(b.DestinationPath, match)); err != nil {
return errwrap.Wrap(err, "error removing file")
Expand Down
11 changes: 6 additions & 5 deletions internal/storage/webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,25 @@ func (b *webDavStorage) Prune(deadline time.Time, pruningPrefix string) (*storag
if err != nil {
return nil, errwrap.Wrap(err, "error looking up candidates from remote storage")
}

var matches []fs.FileInfo
var lenCandidates int
var numCandidates int
for _, candidate := range candidates {
if !strings.HasPrefix(candidate.Name(), pruningPrefix) {
if candidate.IsDir() || !strings.HasPrefix(candidate.Name(), pruningPrefix) {
continue
}
lenCandidates++
numCandidates++
if candidate.ModTime().Before(deadline) {
matches = append(matches, candidate)
}
}

stats := &storage.PruneStats{
Total: uint(lenCandidates),
Total: uint(numCandidates),
Pruned: uint(len(matches)),
}

pruneErr := b.DoPrune(b.Name(), len(matches), lenCandidates, deadline, func() error {
pruneErr := b.DoPrune(b.Name(), len(matches), numCandidates, deadline, func() error {
for _, match := range matches {
if err := b.client.Remove(path.Join(b.DestinationPath, match.Name())); err != nil {
return errwrap.Wrap(err, "error removing file")
Expand Down

0 comments on commit ad829fe

Please sign in to comment.