=== removed directory 'zsh-funcions' === removed file 'zsh-funcions/confz_fileset_init' --- zsh-funcions/confz_fileset_init 2016-01-04 11:27:15 +0000 +++ zsh-funcions/confz_fileset_init 1970-01-01 00:00:00 +0000 @@ -1,101 +0,0 @@ -# vim: ft=zsh noet ts=4 sts=4 sw=4 - -# -# confz functions for file hierarchies and fileset miniformat -# - -zmodload -F zsh/stat b:zstat - -fileset_ftypes=( # convert hex type to a word - C S # unix socket - c S - A L # symlink, could also be 'h' - a L - 8 f # plain file - 6 b # block device file - 4 d # directory - 2 c # character device file - 1 p # FIFO pipe -) - -global -A fileset_stat_cache -global fileset_stat_cur fileset_stat_next_id fileset_stat_cur_type - -fileset_reset_cache(){ - # omit unsetting used variables for now - # probably no particular gain in freeing them - fileset_stat=() - fileset_stat_cur= - fileset_stat_next_id=1 -} - -# runs zstat on $1 if not already in cache -# the result is available as ${(P)fileset_stat_cur} -fileset_stat() { - 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_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_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_resetcmd() { - fileset_reset_cache - "$@" -} - -confz_fs_p_check() { - checkvars filename - local parent - parent=${${vars[filename]}:h} - do_command=( fileset_resetcmd mkdir -p $parent ) - fileset_stat $parent && [[ $fileset_stat_cur_type == d ]] -} - - -confz_fs_type_or_missing_check() { - checkvars filename flags filetype -} - -confz_fs_type_or_missing_do() { - local is_dir - if fileset_stat $vars_filename && [[ $fileset_stat_cur_type == d ]]; then - is_dir=1 - else - is_dir=0 - fi - - if [[ $vars[flags] == *r* ]]; then - if [[ $vars[flags] == *f* ]]; then - rm -rf $vars[filename] - else - rm -r $vars[filename] - fi - elif (($is_dir)); then - rmdir $vars[filename] - else - if [[ $vars[flags] == *f* ]]; then - rm -f $vars[filename] - else - rm $vars[filename] - fi - fi -}