Skip to content

Commit 016e470

Browse files
authored
Directories aren't excluded from pruning logic (#548)
1 parent 0f30b95 commit 016e470

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

internal/storage/local/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (b *localStorage) Prune(deadline time.Time, pruningPrefix string) (*storage
9696
)
9797
}
9898

99-
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
99+
if !fi.IsDir() && fi.Mode()&os.ModeSymlink != os.ModeSymlink {
100100
candidates = append(candidates, candidate)
101101
}
102102
}

internal/storage/ssh/ssh.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,24 @@ func (b *sshStorage) Prune(deadline time.Time, pruningPrefix string) (*storage.P
163163
}
164164

165165
var matches []string
166+
var numCandidates int
166167
for _, candidate := range candidates {
167-
if !strings.HasPrefix(candidate.Name(), pruningPrefix) {
168+
if candidate.IsDir() || !strings.HasPrefix(candidate.Name(), pruningPrefix) {
168169
continue
169170
}
171+
172+
numCandidates++
170173
if candidate.ModTime().Before(deadline) {
171174
matches = append(matches, candidate.Name())
172175
}
173176
}
174177

175178
stats := &storage.PruneStats{
176-
Total: uint(len(candidates)),
179+
Total: uint(numCandidates),
177180
Pruned: uint(len(matches)),
178181
}
179182

180-
pruneErr := b.DoPrune(b.Name(), len(matches), len(candidates), deadline, func() error {
183+
pruneErr := b.DoPrune(b.Name(), len(matches), numCandidates, deadline, func() error {
181184
for _, match := range matches {
182185
p := path.Join(b.DestinationPath, match)
183186
if err := b.sftpClient.Remove(p); err != nil {

internal/storage/webdav/webdav.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,25 @@ func (b *webDavStorage) Prune(deadline time.Time, pruningPrefix string) (*storag
9090
if err != nil {
9191
return nil, errwrap.Wrap(err, "error looking up candidates from remote storage")
9292
}
93+
9394
var matches []fs.FileInfo
94-
var lenCandidates int
95+
var numCandidates int
9596
for _, candidate := range candidates {
96-
if !strings.HasPrefix(candidate.Name(), pruningPrefix) {
97+
if candidate.IsDir() || !strings.HasPrefix(candidate.Name(), pruningPrefix) {
9798
continue
9899
}
99-
lenCandidates++
100+
numCandidates++
100101
if candidate.ModTime().Before(deadline) {
101102
matches = append(matches, candidate)
102103
}
103104
}
104105

105106
stats := &storage.PruneStats{
106-
Total: uint(lenCandidates),
107+
Total: uint(numCandidates),
107108
Pruned: uint(len(matches)),
108109
}
109110

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

0 commit comments

Comments
 (0)