fileset

git mirror of https://ccx.te2000.cz/bzr/fileset
git clone https://ccx.te2000.cz/git/fileset
Log | Files | Refs | README

commit 44140da866f5b0fddc979c4430024e6b160ccf2b
parent 76ca64e5f85f5b6e7608644ff8a48293530dc289
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Thu, 26 Sep 2013 22:16:05 +0200

don't omit top-level directories
Diffstat:
Mbin/fslist | 89++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 45 insertions(+), 44 deletions(-)

diff --git a/bin/fslist b/bin/fslist @@ -32,60 +32,61 @@ statement_end() { delim='' } +fnames=( ) for arg in "${@:-$PWD}"; do - if [[ -d $arg ]]; then - fnames=( $arg:a/**/* ) + fnames+=( $arg:a ) + [[ -d $arg ]] && fnames+=( $arg:a/**/* ) +done + +for fname in $fnames; do + zstat -LH s $fname || continue + ftype=$(( [##16] $s[mode] >> 12 )) + fmode=$(( [##8] $s[mode] & 8#7777 )) + t=$ftypes[$ftype] + + if [[ $fname == *$'\t'* || $fname == *$'\n'* ]]; then + statement $'P\t'$fname $'\t' else - fnames=( $arg:a ) + statement $fname fi - for fname in $fnames; do - zstat -LH s $fname || continue - ftype=$(( [##16] $s[mode] >> 12 )) - fmode=$(( [##8] $s[mode] & 8#7777 )) - t=$ftypes[$ftype] - if [[ $fname == *$'\t'* || $fname == *$'\n'* ]]; then - statement $'P\t'$fname $'\t' + if [[ $t != d && $s[nlink] -gt 1 ]]; then + id=$s[device]:$s[inode] + if (($+hardlinks[$id])); then + statement $'H\t'$hardlinks[$id] $'\n' + continue else - statement $fname - fi - - if [[ $t != d && $s[nlink] -gt 1 ]]; then - id=$s[device]:$s[inode] - if (($+hardlinks[$id])); then - statement $'H\t'$hardlinks[$id] $'\n' - continue - else - hardlinks[$id]=$fname - fi + hardlinks[$id]=$fname fi + fi - if [[ $t == [BC] ]]; then - statement $t$(( $s[rdev] >> 8 )):$(( $s[rdev] & 255 )) - elif [[ $t == l ]]; then - statement $'l\t'$s[link] $'\t' - elif [[ $t == f ]]; then - IFS= read -r -d '' content <$fname - flags='' + if [[ $t == [BC] ]]; then + statement $t$(( $s[rdev] >> 8 )):$(( $s[rdev] & 255 )) + elif [[ $t == l ]]; then + statement $'l\t'$s[link] $'\t' + elif [[ $t == f ]]; then + IFS= read -r -d '' content <$fname + flags='' + if [[ $content == *$'\n' ]]; then + content=${content%$'\n'} if [[ $content == *$'\n' ]]; then - content=${content%$'\n'} - if [[ $content == *$'\n' ]]; then - # force appending newline - flags+=n - fi - else - flags+=N - fi - if [[ $content == *$'\t'* || $content == *$'\n'* ]]; then - statement C$flags$'\t'$content $'\n' - else - statement c$flags$'\t'$content $'\n' + # force appending newline + flags+=n fi + else + flags+=N + fi + if [[ $content == *$'\t'* || $content == *$'\n'* ]]; then + statement C$flags$'\t'$content $'\n' + else + statement c$flags$'\t'$content $'\n' fi - statement o$s[uid]:$s[gid] - statement m$fmode - statement_end - done + else + statement $t + fi + statement o$s[uid]:$s[gid] + statement m$fmode + statement_end done # while getopts omcaOMC o