Skip to content

Commit

Permalink
Restrict max directories created at once to 10 for safety
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Nov 26, 2024
1 parent c8db2bc commit 8f49570
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ada/ada
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Latest version is available at: https://github.com/sara-nl/SpiderScripts
#
# Changes:
# 2024-11-26 - Haili - Add --recursive to --mkdir
# 2024-09-12 - Haili - Added bulk requests for staging and unstaging
# 2024-08-24 - Haili - Added option to use env var BEARER_TOKEN
# 2020-11-04 - Onno - Added link to Natalie's demo video
Expand Down Expand Up @@ -78,8 +79,11 @@ usage() {
--stat <file|directory>
Show all details of file or dir.
--mkdir <directory>
--mkdir <directory> [--recursive]
Create a directory.
To recursively create a directory and ALL of its
parents, add --recursive. For safety, the maximum number
of directories that can be created at once is 10.
--mv <file|directory> <destination>
Rename or move a file or directory.
Expand Down Expand Up @@ -203,6 +207,7 @@ certdir=${X509_CERT_DIR:-/etc/grid-security/certificates}
lifetime=7
lifetime_unit=D
from_file=false
counter=0

# Default options to curl for various activities;
# these can be overidden in configuration files, see below.
Expand Down Expand Up @@ -806,24 +811,28 @@ get_confirmation () {
}


create_path () {\
create_path () {
let counter++
if [ $counter -gt 10 ] ; then
echo 1>&2 "ERROR: max number of directories that can be created at once is 10."
exit 1
fi
local path="$1"
local recursive="$2"
local parent="$(dirname "$path")"
echo "parent" "$parent"
get_locality "$parent"
error=$?
if [ "$error" == 1 ] && $recursive ; then
if [ $error == 1 ] && $recursive ; then
if [ "${#parent}" -gt 1 ]; then
echo ${#parent}
echo 1>&2 "Warning: parent dir '$parent' does not exist. Will atempt to create it."
create_path $parent $recursive
else
echo 1>&2 "ERROR: Unable to create dirs. Check the specified path."
exit 1
fi
elif [ "$error" == 1 ]; then
elif [ $error == 1 ]; then
echo 1>&2 "ERROR: parent dir '$parent' does not exist. To recursivly create dirs, add --recursive."
exit 1
fi
parent=$(urlencode "$(dirname "$path")")
name=$(basename "$path")
Expand Down

0 comments on commit 8f49570

Please sign in to comment.