=== modified file 'bin/fileset_inc.sh' --- bin/fileset_inc.sh 2016-01-04 15:44:10 +0000 +++ bin/fileset_inc.sh 2015-12-09 23:31:28 +0000 @@ -193,7 +193,7 @@ return 0 fi if $f_bang; then - req type_or_missing d + req type_or_missing f elif test -e "$fname" -o -L "$fname"; then die "already present but not a directory: $fname" fi === modified file 'zsh-funcions/confz_fileset_init' --- zsh-funcions/confz_fileset_init 2016-01-04 15:44:10 +0000 +++ zsh-funcions/confz_fileset_init 2016-01-04 11:27:15 +0000 @@ -5,7 +5,6 @@ # zmodload -F zsh/stat b:zstat -zmodload -m -F zsh/files b:zf_\* fileset_ftypes=( # convert hex type to a word C S # unix socket @@ -20,7 +19,7 @@ ) global -A fileset_stat_cache -global fileset_stat_cur fileset_stat_next_id fileset_stat_cur_type fileset_stat_cur_perm +global fileset_stat_cur fileset_stat_next_id fileset_stat_cur_type fileset_reset_cache(){ # omit unsetting used variables for now @@ -33,34 +32,31 @@ # runs zstat on $1 if not already in cache # the result is available as ${(P)fileset_stat_cur} fileset_stat() { - local id ret ftype fperm + local id ret ftype id=${fileset_stat_cache[$1]:-missing} if [[ $id == missing ]]; then zstat -L -H fileset_stat_$fileset_stat_next_id $1 ret=$? if (($ret == 0)); then + fileset_stat_cur=fileset_stat_$fileset_stat_next_id fileset_stat[$1]=$fileset_stat_next_id - fileset_stat_set_cur $fileset_stat_next_id fileset_stat_next_id=$[ $fileset_stat_next_id + 1 ] + ftype=$(( [##16] ${${(P)fileset_stat_cur}[mode]} >> 12 )) + fileset_stat_cur_type=$fileset_ftypes[$ftype] else fileset_stat[$1]=-$ret fi return $ret elif (( $id >= 0 )); then - fileset_stat_set_cur $id + fileset_stat_cur=fileset_stat_$id + ftype=$(( [##16] ${${(P)fileset_stat_cur}[mode]} >> 12 )) + fileset_stat_cur_type=$fileset_ftypes[$ftype] return 0 else return $[ -$id ] fi } -fileset_stat_set_cur(){ - fileset_stat_cur=fileset_stat_$1 - ftype=$[ [##16] ${${(P)fileset_stat_cur}[mode]} >> 12 ] - fileset_stat_cur_type=$fileset_ftypes[$ftype] - fileset_stat_cur_perm=$[ [##8] ${${(P)fileset_stat_cur}[mode]} & 4095 ] -} - fileset_resetcmd() { fileset_reset_cache "$@" @@ -77,7 +73,6 @@ confz_fs_type_or_missing_check() { checkvars filename flags filetype - ! fileset_stat $parent || [[ $fileset_stat_cur_type == $vars[filetype] ]] } confz_fs_type_or_missing_do() { @@ -90,123 +85,17 @@ if [[ $vars[flags] == *r* ]]; then if [[ $vars[flags] == *f* ]]; then - zf_rm -rf $vars[filename] + rm -rf $vars[filename] else - zf_rm -r $vars[filename] + rm -r $vars[filename] fi elif (($is_dir)); then - zf_rmdir $vars[filename] + rmdir $vars[filename] else if [[ $vars[flags] == *f* ]]; then - zf_rm -f $vars[filename] + rm -f $vars[filename] else - zf_rm $vars[filename] + rm $vars[filename] fi fi } - - -confz_fs_l_check() { - checkvars filename flags destination - - if [[ $vars[flags] == *p* ]]; then - require fs_p :filename - fi - - if [[ $vars[flags] == *'!'* ]]; then - require fs_type_or_missing :filename :flags filetype=L - fi - - fileset_stat $vars[filename] && \ - [[ $fileset_stat_cur_type == L ]] && \ - [[ ${${(P)fileset_stat_cur}[link]} == $vars[destination] ]] -} - -confz_fs_l_do() { - local missing - fileset_stat $vars[filename] - missing=$? - fileset_reset_cache - if ! (($missing)); then - rm $vars[filename] || return $? - fi - zf_ln -s $vars[destination] $vars[filename] -} - - -confz_fs_r_check() { - checkvars filename flags - do_command=( confz_fs_type_or_missing_do ) - ! fileset_stat $vars[filename] -} - - -confz_fs_m_check() { - checkvars filename mode - do_command=( fileset_resetcmd chmod $vars[mode] $vars[file] ) - fileset_stat $vars[file] && (( $fileset_stat_cur_perm == $vars[mode] )) -} - - -confz_fs_o_check() { - checkvars filename owner - do_command=( fileset_resetcmd zf_chown $vars[owner] $vars[filename] ) - fileset_stat $vars[filename] || \ - die "fs_o: could not access file ${(qqq)vars[filename]}" - - if [[ $vars[owner] =~ '^[0-7]+:[0-7]+$' ]]; then - (( ${${(P)fileset_stat_cur}[uid]} == ${${vars[owner]}%:*} && \ - ${${(P)fileset_stat_cur}[gid]} == ${${vars[owner]}#*:} )) - elif [[ $vars[owner] =~ '^[0-7]+$' ]]; then - (( ${${(P)fileset_stat_cur}[uid]} == ${${vars[owner]}%:*} )) - else - die "fs_o does not support non-numeric user/group: ${(qqq)vars[owner]}" - fi -} - - -confz_fs_f_check() { - checkvars filename flags - - if [[ $vars[flags] == *p* ]]; then - require fs_p :filename - fi - - if [[ $vars[flags] == *'!'* ]]; then - require fs_type_or_missing :filename :flags filetype=f - fi - - fileset_stat $vars[filename] && [[ $fileset_stat_cur_type == f ]] -} - -confz_fs_f_do() { - fileset_reset_cache - printf '' >> $vars[filename] -} - - -confz_fs_d_check() { - checkvars filename flags - - if [[ $vars[flags] == *'!'* ]]; then - require fs_type_or_missing :filename :flags filetype=d - fi - - if [[ $vars[flags] == *p* ]]; then - do_command=( fileset_resetcmd mkdir -p $vars[filename] ) - else - do_command=( fileset_resetcmd mkdir $vars[filename] ) - fi - - fileset_stat $vars[filename] && [[ $fileset_stat_cur_type == d ]] -} - - -confz_fs_c_check() { - checkvars filename flags - require fs_f :filename :flags -} - -confz_fs_c_do() { - false # TODO -}