summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-06-17 19:19:13 +0200
committerJakob Unterwurzacher2021-06-20 18:09:21 +0200
commit9ac77d42d1c2f56018eb5bcb4e2265d78d572e8c (patch)
tree35b7ea1555e59f307dbb0fbb5c5176e748b2459e
parent2e738efe8647539b96de60d763df44d237f5389b (diff)
contrib/maxlen.bash: also test dir and path length
Move the script from tests to contrib as it may now be useful to somebody else. https://github.com/rfjakob/gocryptfs/issues/552
-rwxr-xr-xcontrib/maxlen.bash74
-rwxr-xr-xtests/maxlen.bash18
2 files changed, 74 insertions, 18 deletions
diff --git a/contrib/maxlen.bash b/contrib/maxlen.bash
new file mode 100755
index 0000000..a4aa082
--- /dev/null
+++ b/contrib/maxlen.bash
@@ -0,0 +1,74 @@
+#!/bin/bash
+#
+# Find out the maximum supported filename length and print it.
+#
+# Part of the gocryptfs test suite
+# https://nuetzlich.net/gocryptfs/
+
+set -eu
+MYNAME=$(basename "$0")
+
+if [[ $# -ne 1 || $1 == -* ]]; then
+ echo "Usage: $MYNAME DIRECTORY"
+ exit 1
+fi
+
+cd "$1"
+echo "Testing $PWD"
+
+echo -n " Maximum filename length: "
+# Add one character at a time until we hit an error
+NAME=""
+while true ; do
+ NEXT="${NAME}x"
+ if [[ -e $NEXT ]]; then
+ echo "error: file $NEXT already exists"
+ exit 1
+ fi
+ touch $NEXT 2> /dev/null || break
+ rm $NEXT
+ NAME="$NEXT"
+done
+echo "${#NAME}"
+
+echo -n " Maximum dirname length: "
+# Add one character at a time until we hit an error
+NAME=""
+while true ; do
+ NEXT="${NAME}x"
+ mkdir $NEXT 2> /dev/null || break
+ rmdir $NEXT
+ NAME="$NEXT"
+done
+MAX_DIRNAME=${#NAME}
+echo "${#NAME}"
+
+for CHARS_PER_SUBDIR in 1 10 100 $MAX_DIRNAME ; do
+ echo -n " Maximum path length with $(printf %3d $CHARS_PER_SUBDIR) chars per subdir: "
+ # Trick from https://stackoverflow.com/a/5349842/1380267
+ SUBDIR=$(printf 'x%.0s' $(seq 1 $CHARS_PER_SUBDIR))
+ mkdir "$SUBDIR"
+ P=$SUBDIR
+ # Create a deep path, one $SUBDIR at a time, until we hit an error
+ while true ; do
+ NEXT="$P/$SUBDIR"
+ mkdir "$NEXT" 2> /dev/null || break
+ P=$NEXT
+ echo -n -e "\b\b\b\b"
+ printf %4d ${#P}
+ done
+ # Then add one character at a time until we hit an error
+ NAME=""
+ while true ; do
+ NEXT="${NAME}x"
+ touch "$P/$NEXT" 2> /dev/null || break
+ NAME=$NEXT
+ done
+ if [[ $NAME != "" ]] ; then
+ P=$P/$NAME
+ fi
+ echo -n -e "\b\b\b\b"
+ printf %4d ${#P}
+ echo
+ rm -R "$SUBDIR"
+done
diff --git a/tests/maxlen.bash b/tests/maxlen.bash
deleted file mode 100755
index fb133e0..0000000
--- a/tests/maxlen.bash
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash -eu
-#
-# Find out the maximum supported filename length and print it.
-#
-# Part of the gocryptfs test suite
-# https://nuetzlich.net/gocryptfs/
-
-NAME="maxlen."
-LEN=0
-
-while [ $LEN -le 10000 ]; do
- touch $NAME 2> /dev/null || break
- rm $NAME
- LEN=${#NAME}
- NAME="${NAME}x"
-done
-
-echo $LEN