Skip to content

Commit

Permalink
Change error cleanup in objstore.DownloadDir to delete files not dire…
Browse files Browse the repository at this point in the history
…ctories

Dst is always a directory. If any file after the first fails to download,
the cleanup will fail because the destination already contains at least one file.
This commit changes the cleanup logic to clean up successfully downloaded files one by one
instead of attempting to clean up the whole dst directory.

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
  • Loading branch information
dimitarvdimitrov committed Mar 11, 2022
1 parent b769250 commit 3da2fbb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/objstore/objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,13 @@ func DownloadDir(ctx context.Context, logger log.Logger, bkt BucketReader, origi

var downloadedFiles []string
if err := bkt.Iter(ctx, src, func(name string) error {
dst := filepath.Join(dst, filepath.Base(name))
if strings.HasSuffix(name, DirDelim) {
return DownloadDir(ctx, logger, bkt, originalSrc, name, filepath.Join(dst, filepath.Base(name)), ignoredPaths...)
if err := DownloadDir(ctx, logger, bkt, originalSrc, name, dst, ignoredPaths...); err != nil {
return err
}
downloadedFiles = append(downloadedFiles, dst)
return nil
}
for _, ignoredPath := range ignoredPaths {
if ignoredPath == strings.TrimPrefix(name, string(originalSrc)+DirDelim) {
Expand Down

0 comments on commit 3da2fbb

Please sign in to comment.