On Mon, Aug 3, 2009 at 1:20 AM, Eddie Drapkin<oorza...@gmail.com> wrote:
> There's a script, mod_files.sh, in ext/session for creating directory
> tree with depth X for sessions.  As it stands, it's pretty poorly
> documented and very basic.  I got exceptionally bored and rewrote most
> of it, the patch is attached.  It runs fine for me in linux (with sh
> version 4.0).  I don't have any other *NIX systems to test it out on,
> so I can't verify that it works in anything but linux, sorry.
>
> What I changed:
>
> 1. Usage now properly reflects arguments, and is better explained.
> 2. Will create directory given if it doesn't exist
> 3. Will hop into interactive select if directory already has contents
> 4. Switched from "test" to "[[ ]]" as it's easier to read and _should_
> be just as supported.
>

Not to be a moron, but I attached a bad patch.  This is the right one, sorry.
Index: trunk/mod_files.sh
===================================================================
--- trunk/mod_files.sh	(revision 44)
+++ trunk/mod_files.sh	(working copy)
@@ -1,25 +1,65 @@
 #! /bin/sh
 
-if test "$2" = ""; then
-	echo "usage: $0 basedir depth"
+if [[ "$2" = "" ]] || [[ "$3" = "" ]]; then
+	echo "Usage: $0 BASE_DIRECTORY DEPTH MAJOR_PHP_VERSION"
+	echo "BASE_DIRECTORY will be created if it doesn't exist"
+	echo "DEPTH must be an integer number >0"
+	echo "MAJOR_PHP_VERSION should be one of 4, 5, or 6"
 	exit 1
 fi
 
-if test "$2" = "0"; then
+if [[ "$2" = "0" ]] && [[ ! "$4" = "recurse" ]]; then
+	echo "Can't create a directory tree with depth of 0, exiting."
+fi
+
+if [[ "$2" = "0" ]]; then
 	exit 0
 fi
 
+directory="$1"
+depth="$2"
+PHPVer="$3"
+
 hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
-if test "$3" -a "$3" -ge "5"; then
-  hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
-  if test "$3" -eq "6"; then
-    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 - ,"
-  fi
+
+if [[ "$PHPVer" -ge "5" ]]; then
+	hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
 fi
 
+if [[ "$PHPVer" -ge "6" ]]; then
+	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 - ,"
+fi
+
+while [[ -d $directory ]] && [[ $( ls $directory ) ]]; do
+	echo "Directory $directory is not empty! What would you like to do?"
+	
+	options="\"Delete directory contents\" \"Choose another directory\" \"Quit\""
+	eval set $options
+	select opt in "$@"; do
+		
+		if [[ $opt = "Delete directory contents" ]]; then
+			echo "Deleting $directory contents... "
+			rm -rf $directory/*
+		elif [[ $opt = "Choose another directory" ]]; then
+			echo "Which directory would you like to choose?"
+			read directory
+		elif [[ $opt = "Quit" ]]; then
+			exit 0
+		fi 
+		
+		break;
+	done
+done
+
+if [[ ! -d $directory ]]; then
+	mkdir -p $directory
+fi
+
+
+echo "Creating session path in $directory with a depth of $depth for PHP Version $PHPVer".X
+
 for i in $hash_chars; do
-	newpath="$1/$i"
+	newpath="$directory/$i"
 	mkdir $newpath || exit 1
-	sh $0 $newpath `expr $2 - 1` $3
+	sh $0 $newpath `expr $depth - 1` $PHPVer recurse
 done
-
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to