Changeset 520


Ignore:
Timestamp:
06/17/2011 16:25:47 (11 months ago)
Author:
joshu
Message:

confman now checks whether the directory that contains a file to be imported exists and, if it does not, recursively creates the containing directories. Fixes #132.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abspath.in

    r329 r520  
    3838    dir=`cd $file >/dev/null; echo \$PWD` 
    3939    echo "$dir" 
    40   else 
     40    return 0 
     41  elif [ -d $(dirname $file) ]; then 
    4142    dir=`cd $(dirname $file) >/dev/null ; echo \$PWD` 
    4243    echo "$dir/$(basename "$file")" 
     44    return 0 
     45  else 
     46    return 1 
    4347  fi 
    4448} 
  • trunk/confman.in

    r518 r520  
    388388        # If we can't enter the parent directory, this will help us 
    389389        # get the info we need. 
    390         if ! $SUDO [ -e $1 ]; then 
    391             echo "No such file or directory: $1" >&2 
    392             return 1 
    393         else 
    394             file=`$SUDO $ABSPATH $1` 
     390        file=`$SUDO $ABSPATH $1` 
     391        if [ $? -eq 1 ]; then 
     392            filename="$(basename $1)" 
     393            real_path="$(dirname $1)" 
     394            imaginary_path="" 
     395            while ! [ -d $real_path ]; do 
     396                imaginary_path="/${real_path##*/}$imaginary_path" 
     397                real_path="${real_path%/*}" 
     398            done 
     399            file="$($SUDO $ABSPATH $real_path)$imaginary_path/$filename" 
    395400        fi 
    396401    fi 
     
    487492        return 
    488493    else 
     494        # If some of the directories containing the file don't exist, we should 
     495        # prompt for the creation of those directories ... 
     496        if [ -z $imaginary_path ]; then 
     497            for directory in ${imaginary_path//\// }; do 
     498                d_owner=$owner 
     499                d_group=$group 
     500                d_mode=$mode 
     501                echo "${real_path}/${directory} does not exist; creating it." 
     502                # Prompt for directory owner 
     503                echo "Who should be the directory's owner? [ $d_owner ]" 
     504                read response 
     505                if [ ! -z $response ] ; then 
     506                    d_owner=$response 
     507                fi 
     508         
     509                # And directory's group 
     510                echo "Who should be the directory's group? [ $d_group ]" 
     511                read response 
     512                if [ ! -z $response ] ; then 
     513                    d_group=$response 
     514                fi 
     515         
     516                # now, the permissions 
     517                echo "What should the directory's permissions be? [ $d_mode ]" 
     518                read response 
     519                if [ ! -z $response ] ; then 
     520                    d_mode=$response 
     521                fi 
     522                real_path="$real_path/$directory" 
     523                conf_mkdir $real_path $d_owner $d_group $d_mode 
     524            done 
     525        fi 
    489526        # Prompt for file owner 
    490527        echo "Who should be the file's owner? [ $owner ]" 
Note: See TracChangeset for help on using the changeset viewer.