MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / listFilesScript

Function listFilesScript

tests/utils/objectstore/objectstore.go:685–696  ·  view source on GitHub ↗

listFilesScript builds a shell script printing every object in the store as a `bucket/key` line, filtered by the glob expressed in the given path. A failure enumerating the buckets aborts the script, so an unreachable endpoint is not mistaken for an empty store, and the per-bucket listings run in pa

(path string)

Source from the content-addressed store, hash-verified

683// linearly with the number of buckets. The script ends with the pipeline
684// emitting the matches, so callers can append further stages (e.g. `| wc -l`)
685func listFilesScript(path string) string {
686 return fmt.Sprintf(
687 `buckets=$(aws s3api list-buckets --query "Buckets[].Name" --output text) || exit 1; `+
688 `dir=$(mktemp -d) || exit 1; trap "rm -rf $dir" EXIT; n=0; `+
689 `for b in $buckets; do `+
690 `aws s3api list-objects-v2 --bucket "$b" --query "Contents[].Key" --output text | `+
691 `tr "\t" "\n" | sed "s|^|$b/|" > "$dir/$b" & `+
692 `n=$((n+1)); [ $((n %% 8)) -eq 0 ] && wait; `+
693 `done; wait; `+
694 `cat /dev/null "$dir"/* 2>/dev/null | { grep -E "%v" || true; }`,
695 globToRegexp(path))
696}
697
698// composeListFiles builds the command to list the filenames matching a given path
699func composeListFiles(path string) string {

Callers 3

composeListFilesFunction · 0.85
composeFindCmdFunction · 0.85
GetFileTagsFunction · 0.85

Calls 1

globToRegexpFunction · 0.85

Tested by

no test coverage detected