Skip to content

Commit 27b01cf

Browse files
author
Yasuo Ohgaki
committed
Fixed bug #49175: mod_files.sh does not support hash bits
1 parent 657d486 commit 27b01cf

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

ext/session/mod_files.sh

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
#! /bin/sh
22

3-
if test "$2" = ""; then
4-
echo "usage: $0 basedir depth"
5-
exit 1
3+
if [[ "$2" = "" ]] || [[ "$3" = "" ]]; then
4+
echo "Usage: $0 BASE_DIRECTORY DEPTH HASH_BITS"
5+
echo "BASE_DIRECTORY will be created if it doesn't exist"
6+
echo "DEPTH must be an integer number >0"
7+
echo "HASH_BITS(session.hash_bits_per_charactor) should be one of 4, 5, or 6"
8+
exit 1
69
fi
710

8-
if test "$2" = "0"; then
9-
exit 0
11+
if [[ "$2" = "0" ]] && [[ ! "$4" = "recurse" ]]; then
12+
echo "Can't create a directory tree with depth of 0, exiting."
1013
fi
1114

15+
if [[ "$2" = "0" ]]; then
16+
exit 0
17+
fi
18+
19+
directory="$1"
20+
depth="$2"
21+
hashbits="$3"
22+
1223
hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
13-
if test "$3" -a "$3" -ge "5"; then
14-
hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
15-
if test "$3" -eq "6"; then
16-
hash_chars="$hash_chars w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - ,"
17-
fi
24+
25+
if [[ "$hashbits" -ge "5" ]]; then
26+
hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
1827
fi
1928

29+
if [[ "$hashbits" -ge "6" ]]; then
30+
hash_chars="$hash_chars w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - ,"
31+
fi
32+
33+
while [[ -d $directory ]] && [[ $( ls $directory ) ]]; do
34+
echo "Directory $directory is not empty! What would you like to do?"
35+
36+
options="\"Delete directory contents\" \"Choose another directory\" \"Quit\""
37+
eval set $options
38+
select opt in "$@"; do
39+
40+
if [[ $opt = "Delete directory contents" ]]; then
41+
echo "Deleting $directory contents... "
42+
rm -rf $directory/*
43+
elif [[ $opt = "Choose another directory" ]]; then
44+
echo "Which directory would you like to choose?"
45+
read directory
46+
elif [[ $opt = "Quit" ]]; then
47+
exit 0
48+
fi
49+
50+
break;
51+
done
52+
done
53+
54+
if [[ ! -d $directory ]]; then
55+
mkdir -p $directory
56+
fi
57+
58+
59+
echo "Creating session path in $directory with a depth of $depth for session.hash_bits_per_character = $hashbits"
60+
2061
for i in $hash_chars; do
21-
newpath="$1/$i"
22-
mkdir $newpath || exit 1
23-
sh $0 $newpath `expr $2 - 1` $3
62+
newpath="$directory/$i"
63+
mkdir $newpath || exit 1
64+
sh $0 $newpath `expr $depth - 1` $hashbits recurse
2465
done

0 commit comments

Comments
 (0)