ckolivas / lrzip

Long Range Zip
http://lrzip.kolivas.org
GNU General Public License v2.0
619 stars 76 forks source link

lrztar: -o file is not processed properly. output filename default #119

Closed pete4abw closed 5 years ago

pete4abw commented 5 years ago

$ ./lrztar -o usr.tar.5.lrz usr v_x = o, vopt = lrz, OPTARG = usr.tar.5.lrz lrztar: /tmp/usr.tar.lrz exists, use -f to overwrite

Note how output filename is the default directory name.

pete4abw commented 5 years ago

The issue has been found.

Here, there is a test for the output file existing. But the default output file never gets updated. } || { if ((v_o)); then ((v_f)) && [[ -e ${vopt[$v_o]} ]] && { printf "lrztar: %s exists, use -f to overwrite.\n" \ "${vopt[$v_o]}" return 1 } else ..... Later, just before the TAR command, there is a test for the output file. But -o is never taken into account. Hardcoding the output file negates what -o is trying. If you use -f, this conditional is bypassed. *! ((v_f)) && [[ -e $i/${s##/}.tar.${vopt[v_S]} ]] && {* printf "lrztar: %s exists, use -f to overwrite\n" \ "$i/${s##/}.tar.${vopt[v_S]}" echo '! ((v_f)) && [[ -e $i/${s##*/}.tar.${vopt[v_S]} ]]' echo $i $s return 1 } tar c "$s" | lrzip "${p[@]}" x=$?

p[@] = -o usr.5.tar.lrz + (( v_f )) + [[ -e /tmp/usr.tar.lrz ]] + printf 'lrztar: %s exists, use -f to overwrite\n' /tmp/usr.tar.lrz lrztar: /tmp/usr.tar.lrz exists, use -f to overwrite

pete4abw commented 5 years ago

I took a whack at it anyway. Added one more test for -o just before the tar command.

    **if ! ((v_o)); then** 
        ! ((v_f)) && [[ -e $i/${s##*/}.tar.${vopt[v_S]} ]] && {
            printf "lrztar: %s exists, use -f to overwrite\n" \
                "$i/${s##*/}.tar.${vopt[v_S]}"
            return 1
        }
    **fi**
   tar c "$s" | lrzip "${p[@]}"
   x=$?

code may be viewed at https://github.com/pete4abw/lrzip/tree/lrztar