From c2db9378b90a030ea97c7a90041b7c3c8a39859e Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Wed, 1 Apr 2026 12:57:25 -0400 Subject: [PATCH] tarbz2: use DEST directory name in tar archive When specifying the "-f" option, this will allow the decompression to be done in DEST directory instead of the source directory. This avoids the necessity to create a copy first, tarbz2 it, and then remove the temporary copy. Signed-off-by: Hugo Villeneuve --- scripts/tarbz2 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/tarbz2 b/scripts/tarbz2 index c830504..3ea891c 100755 --- a/scripts/tarbz2 +++ b/scripts/tarbz2 @@ -48,17 +48,19 @@ fi DIR=${1%/} -if [ -z ${DEST} ]; then - DEST=$(basename ${DIR}) -fi - # Checking if directory exists. if [ ! -d ${DIR} ]; then echo "$0: Directory ${DIR} not found." exit 1 fi +if [ -z ${DEST} ]; then + DEST=$(basename ${DIR}) +else + DIR_OPTS="--transform "s@${DIR}@${DEST}@"" +fi + # Decompressing file to standard output and piping result to bzip2 -tar cf - ${DIR} | ${BZIP2_BIN} -9 > ${DEST}.tar.bz2 +tar cf - ${DIR} ${DIR_OPTS} | ${BZIP2_BIN} -9 > ${DEST}.tar.bz2 exit $? -- 2.47.3