* Fix Spark _temporary cleanup and add issue #8285 regression test * Generalize empty folder cleanup for Spark temp artifacts * Revert synchronous folder pruning and add cleanup diagnostics * Add actionable empty-folder cleanup diagnostics * Fix Spark temp marker cleanup in async folder cleaner * Fix Spark temp cleanup with implicit directory markers * Keep explicit directory markers non-implicit * logging * more logs * Switch empty-folder cleanup to bucket policy * Seaweed-X-Amz-Allow-Empty-Folders * less logs * go vet * less logs * refactoring
34 lines
746 B
Go
34 lines
746 B
Go
package util
|
|
|
|
import "strings"
|
|
|
|
// ExtractBucketPath returns the bucket path under basePath that contains target.
|
|
// If requireChild is true, the target must include additional segments beyond the bucket itself.
|
|
func ExtractBucketPath(basePath, target string, requireChild bool) (string, bool) {
|
|
cleanBase := strings.TrimSuffix(basePath, "/")
|
|
if cleanBase == "" {
|
|
return "", false
|
|
}
|
|
|
|
prefix := cleanBase + "/"
|
|
if !strings.HasPrefix(target, prefix) {
|
|
return "", false
|
|
}
|
|
|
|
rest := strings.TrimPrefix(target, prefix)
|
|
if rest == "" {
|
|
return "", false
|
|
}
|
|
|
|
bucketName, _, found := strings.Cut(rest, "/")
|
|
if bucketName == "" {
|
|
return "", false
|
|
}
|
|
|
|
if requireChild && !found {
|
|
return "", false
|
|
}
|
|
|
|
return prefix + bucketName, true
|
|
}
|