From 1f5214e4aa2afc09bf51f92dff6c2f81f42785a1 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Sat, 23 Jul 2016 16:02:27 +0300 Subject: [PATCH] Fixing archiver, storing names after deletion --- files/archive-subfolders | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/files/archive-subfolders b/files/archive-subfolders index 0b87502..b168ca8 100755 --- a/files/archive-subfolders +++ b/files/archive-subfolders @@ -15,7 +15,7 @@ function helpexit() { exit } function listfolders() { - find "$@" -mindepth $DEPTH -maxdepth $DEPTH -type d | sort | tr '\n' '\000' + find "$@" -mindepth $DEPTH -maxdepth $DEPTH -type d | sort } function fsize() { echo -en "\e[2K\r" @@ -27,8 +27,8 @@ function killtrap() { } function exitokay() { [[ "$REMOVE" -eq 1 ]] && { exit; } - echo -ne "\nIf all looks okay, delete source folders with: # rm -r '" - listfolders "${FOLDERS[@]}" | sed -e "s/\x0/' '/g" -e "s,..$,," + echo -ne "\nIf all looks okay, delete source folders with: # rm -r " + for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder' "; done echo '' exit } @@ -47,6 +47,8 @@ for ((i=1; i<=${#@}; i++)) { DEPTH=0 } [[ ${#FOLDERS[@]} -eq 0 ]] && FOLDERS+=( "." ) +export IFS=$'\n' +REALFOLDERS=( $( listfolders "${FOLDERS[@]}" ) ) echo 'Existing files will be overwritten!' [[ "$REMOVE" -eq 1 ]] && { echo 'Source folders will be deleted!' @@ -58,15 +60,14 @@ echo -n "Archive the following folders " [[ "$COMPRESSION" -eq 1 ]] && echo -n with gzip compression } echo ':' -echo -n "'" -listfolders "${FOLDERS[@]}" | sed -e "s/\x0/' '/g" -e "s,..$,," +for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder', "; done | sed -e "s/..$//" echo "" echo ' to quit' read foo -read -a SLEEPS <<< "0.1 0.5 1 2 3 4 5" +IFS=" " read -a SLEEPS <<< '0.1 0.5 1 2 3 4 5' trap killtrap 9 15 -listfolders "${FOLDERS[@]}" | while read -r -d "" d; do +for d in "${REALFOLDERS[@]}"; do printf "%s" $d tar cvvf "$d.tar" "$d" > "$d.tar.lst" & PID=$! @@ -79,7 +80,7 @@ listfolders "${FOLDERS[@]}" | while read -r -d "" d; do sleep $i; kill -0 "$PID" &>/dev/null || break 2 printf . done - read -a SLEEPS <<< "4 4 4 4" + IFS=" " read -a SLEEPS <<< '4 4 4 4' done fsize "$d.tar" "$DU" kill -0 "$DUPID" &>/dev/null || kill "$DUPID" &>/dev/null @@ -102,10 +103,10 @@ trap - 9 15 read foo } echo 'Compressing..' -read -a SLEEPS <<< "0.1 0.5 1 2 3 4 5" +IFS=" " read -a SLEEPS <<< '0.1 0.5 1 2 3 4 5' trap killtrap 9 15 -listfolders "${FOLDERS[@]}" | while read -r -d "" d; do +for d in "${REALFOLDERS[@]}"; do DU=$( fastdu -h "$d.tar" ) gzip -f "$d.tar" & PID=$! @@ -116,7 +117,7 @@ listfolders "${FOLDERS[@]}" | while read -r -d "" d; do sleep $i; kill -0 "$PID" &>/dev/null || break 2 printf . done - read -a SLEEPS <<< "4 4 4 4" + IFS=" " read -a SLEEPS <<< '4 4 4 4' done fsize "$d.tar.gz" "$DU" echo ''