Skip to content

Commit 8494658

Browse files
committed
Allow the use of wildcards in the remote path string
Signed-off-by: Kostis Papazafeiropoulos <[email protected]>
1 parent cae98dd commit 8494658

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

entrypoint.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ die() {
2121

2222
ok_or_die() {
2323
if [ $? -ne 0 ]; then
24-
die $1
24+
die "$1"
2525
fi
2626
}
2727

@@ -37,10 +37,23 @@ remote_path=$5
3737

3838
info "Will fetch $remote_path to $local_path"
3939

40-
mc alias set s3 $url $access_key $secret_key
40+
mc alias set s3 "$url" "$access_key" "$secret_key"
4141
ok_or_die "Could not set mc alias"
4242

43-
mc cp -r s3/$remote_path $local_path
43+
if [ "${remote_path#*'*'}" != "$remote_path" ]; then
44+
# Handle remote_dir with wildcard
45+
remote_dir=$(dirname "$remote_path")
46+
remote_files=$(basename "$remote_path")
47+
path_depth=$(echo "$remote_dir" | awk -F"/" '{print NF-1}')
48+
IFS=$'\n'
49+
for p in $(mc find "s3/$remote_dir" \
50+
--name "$remote_files" --maxdepth "$path_depth"); do
51+
mc cp -r "$p" "$local_path";
52+
done
53+
unset IFS
54+
else
55+
mc cp -r "s3/$remote_path $local_path"
56+
fi
4457
ok_or_die "Could not fetch object"
4558

4659
# Fix owner of local path

0 commit comments

Comments
 (0)