Changeset 587


Ignore:
Timestamp:
12/23/2011 15:18:16 (5 months ago)
Author:
blee
Message:

Implement confman touch for creating versioned files in working copies.

See #154

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/confman.8.in

    r569 r587  
    310310directories do not have to exist; they will be created automatically. This 
    311311command only affects your working copy. It does not commit the change. 
     312.It Cm touch Ar file 
     313Create a new version-controlled file in your working copy. Parent directories 
     314must exist. This command only affects your working copy. It does not commit the 
     315change. 
    312316.It Cm revert Ar 
    313317Restore the working copy files to the state before you began making edits. 
  • trunk/confman.in

    r554 r587  
    654654} 
    655655 
     656function cnf_touch { 
     657    local file="$1" 
     658 
     659    local owner="${DEFAULT_OWNER}" 
     660    local group="${DEFAULT_GROUP}" 
     661    local mode="${DEFAULT_MODE_FILE}" 
     662    local comment="${DEFAULT_COMMENT}" 
     663    local wcopy_lock 
     664    local livefile 
     665 
     666    if [ -z "${file}" ]; then 
     667        print_usage 1 
     668    fi 
     669     
     670    wcopy_lock=$(conf_lock_wcopy) 
     671 
     672    # Resolve the absolute path to the file 
     673    file="$("${ABSPATH}" .)/${file}" 
     674 
     675    # If the filename doesn't begin with WORK_PATH, we can't operate here 
     676    if [ "${file#${WORK_PATH}}" = "${file}" ]; then 
     677        echo "Cannot operate on non-working-copy file: ${file}" >&4 
     678    fi 
     679 
     680    module=${file#${WORK_PATH}/} 
     681    module=${module%%/*} 
     682    livefile="/${file#${WORK_PATH}/*/}" 
     683 
     684    # If it exists on the live filesystem, pull the attributes from there 
     685    if [ -f "${livefile}" ]; then 
     686        eval `$SUDO ${stat_cmd} "${stat_opts}" "${livefile}"` 
     687 
     688        # TODO: Guess the comment character too 
     689 
     690        # Convert mode string to base 10: 
     691        mode=`echo "obase=10;ibase=8;${mode}" | bc` 
     692        # And use a bitmask to subtract off all write-access 
     693        # 3949d = 7555o 
     694        mode=$((${mode} & 3949)) 
     695        # And back to an octet: 
     696        mode=`printf '%04o\n' ${mode}` 
     697 
     698        echo "Touching file ${livefile} with ${owner}:${group}, ${mode}, comment string ${comment}" 
     699        conf_gen_file "${module}" "${livefile}" "${owner}" "${group}" "${mode}" "${comment}" "" "" 
     700 
     701    # Otherwise, prompt for attributes 
     702    else 
     703        # Prompt for file owner 
     704        echo "Who should be the file's owner? [ ${owner} ]" 
     705        read response 
     706        if [ -n "${response}" ]; then 
     707            owner="${response}" 
     708        fi 
     709 
     710        # Prompt for file group 
     711        echo "Who should be the file's group? [ ${group} ]" 
     712        read response 
     713        if [ -n "${response}" ]; then 
     714            group="${response}" 
     715        fi 
     716 
     717        # Prompt for file mode 
     718        echo "What should the file's permissions be? [ ${mode} ]" 
     719        read response 
     720        if [ -n "${response}" ]; then 
     721            mode="${response}" 
     722        fi 
     723 
     724        # Prompt for file comment 
     725        echo "What string starts comment lines? [ ${comment} ]" 
     726        read response 
     727        if [ -n "${response}" ]; then 
     728            comment="${response}" 
     729        fi 
     730 
     731        echo "Touching file ${livefile} with ${owner}:${group}, ${mode}, comment string ${comment}" 
     732        conf_gen_file "${module}" "${livefile}" "${owner}" "${group}" "${mode}" "${comment}" "" "" 
     733    fi 
     734 
     735    conf_unlock_wcopy "${wcopy_lock}" 
     736} 
     737 
    656738function list { 
    657739        local file item 
     
    12711353    rmmod )                         rmmod "$@" ;; 
    12721354    mkdir|mkd* )                    newdir "$@" ;; 
     1355    touch )                         cnf_touch "$@" ;; 
    12731356    list|ls )                       list "$@" ;; 
    12741357    link|ln )                       mklink "$@" ;; 
  • trunk/confmandoc.sh

    r512 r587  
    5858  $MYNAME mv src_working_copy dest_working_copy 
    5959  $MYNAME mkdir workingdirectory 
     60  $MYNAME touch workingfile 
    6061  $MYNAME revert workingfile 
    6162  $MYNAME chown owner [ workingfile | workingdirectory ]  
  • trunk/confmanlib.sh.in

    r585 r587  
    10341034        echo $file 
    10351035 
    1036         if [ -z $usefile ] ; then 
     1036        if [ -z "${usefile}" ] ; then 
    10371037                                        echo -e "${warning}\n${morewarn}\n${revision}\n" > $myfile 
    10381038        elif head -n 1 ${usefile} | grep '^#!' >/dev/null ; then 
Note: See TracChangeset for help on using the changeset viewer.