deleteDir recursion fix
This commit is contained in:
parent
1d5dbfaa1c
commit
8296b21883
@ -32,12 +32,33 @@ func listObjectsBatch(c context.Context, k dataloader.Keys) []*dataloader.Result
|
||||
return results
|
||||
}
|
||||
|
||||
// listObjectsRecursiveBatch just like listObjectsBatch but with recursive set to true
|
||||
func listObjectsRecursiveBatch(c context.Context, k dataloader.Keys) []*dataloader.Result {
|
||||
log.Debug("listObjectsRecursiveBatch: ", k.Keys())
|
||||
var results []*dataloader.Result
|
||||
|
||||
s3Client, ok := c.Value("s3Client").(*minio.Client)
|
||||
|
||||
if !ok {
|
||||
return handleLoaderError(k, fmt.Errorf("Failed to get s3Client from context"))
|
||||
}
|
||||
|
||||
for _, v := range k {
|
||||
results = append(results, &dataloader.Result{
|
||||
Data: listObjects(s3Client, bucketName, v.String(), true),
|
||||
Error: nil,
|
||||
})
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// listObjects helper func for listObjectsBatch
|
||||
func listObjects(s3Client *minio.Client, bukitName, path string, recursive bool) []minio.ObjectInfo {
|
||||
log.Debug("S3 call 'ListObjects': ", path)
|
||||
objectCh := s3Client.ListObjects(context.Background(), bukitName, minio.ListObjectsOptions{
|
||||
Prefix: path,
|
||||
Recursive: false,
|
||||
Recursive: recursive,
|
||||
})
|
||||
|
||||
result := make([]minio.ObjectInfo, 0)
|
||||
@ -210,6 +231,11 @@ func createDataloader(config AppConfig) map[string]*dataloader.Loader {
|
||||
dataloader.WithCache(newCache(config.CacheTTL, config.CacheCleanup)),
|
||||
)
|
||||
|
||||
loaderMap["listObjectsRecursive"] = dataloader.NewBatchedLoader(
|
||||
listObjectsRecursiveBatch,
|
||||
dataloader.WithCache(newCache(config.CacheTTL, config.CacheCleanup)),
|
||||
)
|
||||
|
||||
loaderMap["getDirs"] = dataloader.NewBatchedLoader(
|
||||
getDirsBatch,
|
||||
dataloader.WithCache(newCache(config.CacheTTL, config.CacheCleanup)),
|
||||
|
@ -152,7 +152,7 @@ func deleteDirectory(ctx context.Context, path string) error {
|
||||
}
|
||||
|
||||
// Get all files inside the directory
|
||||
thunk := loader["listObjects"].Load(ctx, dataloader.StringKey(path))
|
||||
thunk := loader["listObjectsRecursive"].Load(ctx, dataloader.StringKey(path))
|
||||
|
||||
result, err := thunk()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user