mxmlnkn / ratarmount

Access large archives as a filesystem efficiently, e.g., TAR, RAR, ZIP, GZ, BZ2, XZ, ZSTD archives
MIT License
699 stars 36 forks source link

Locale dependent behaviour #132

Open fanfan70 opened 5 months ago

fanfan70 commented 5 months ago

For another issue (https://github.com/mxmlnkn/ratarmount/issues/125), I've written a test script. Thank for the answer by the way! I've fixed it and now I see a problem linked to configured language: I use a french environment, in which I get this error (run without argument, see script below) while committing:

+ ratarmount --commit-overlay --write-overlay /tmp/overlay /tmp/example.tar /tmp/mnt
To commit the overlay folder to the archive, these commands have to be executed:

    tar --delete --null --verbatim-files-from --files-from='/tmp/tmplvgbnz0o/deletions.lst' \
        --file '/tmp/example.tar' 2>&1 |
       sed '/^tar: Exiting with failure/d; /^tar.*Not found in archive/d'
    tar --append -C '/tmp/overlay' --null --verbatim-files-from --files-from='/tmp/tmplvgbnz0o/append.lst' --file '/tmp/example.tar'

Committing is an experimental feature!
Please confirm by entering "commit". Any other input will cancel.
> tar: file2 : non trouvé dans l'archive
tar: /file2 : non trouvé dans l'archive
tar: ./file2 : non trouvé dans l'archive
tar: Arrêt avec code d'échec à cause des erreurs précédentes
[Error] There were problems when trying to delete files.

"non trouvé dans l'archive" means "not found in the archive" "Arrêt avec code d'échec à cause des erreurs précédentes" means "stop with error code because of previous errors"

When I run the same script (no argument too) after a "export LANGUAGE=en_US", I don't get the error.

Script :

#!/bin/bash

set -xv
set -o errexit
set -o nounset

OVERLAY_DIR=/tmp/overlay
MOUNT_POINT=/tmp/mnt

function exit_handler()
{
  if (( $? == 0 )); then
    echo
    echo OK
  else
    echo
    echo ERROR >&2
  fi

  umount_dir
  rm -rf $OVERLAY_DIR $MOUNT_POINT
}
trap exit_handler EXIT

function umount_dir()
{
  if [[ -n $(mount|grep "FuseMount on $MOUNT_POINT type") ]]; then
    echo umounting $MOUNT_POINT
    fusermount -u $MOUNT_POINT
  fi
}

function create_dummy_tar()
{
  local tar_dir=/tmp/example_tar
  tar=/tmp/example.tar
  rm -rf $tar* $tar_dir
  mkdir -p $tar_dir/dir1
  ls -al / > $tar_dir/file1
  tar cf $tar $tar_dir
  rm -r $tar_dir
}

if (( $# == 0 )); then
  create_dummy_tar
elif (( $# == 1 )); then
  tar=$1
else
  echo "syntax: $(basename $0) <tar file>" >&2
  exit 1
fi

if [[ ! -f $tar ]]; then
  echo "$tar: no such file" >&2
  exit 1
fi

umount_dir

rm -rf $OVERLAY_DIR $MOUNT_POINT
mkdir -p $OVERLAY_DIR $MOUNT_POINT

# mount tar
ratarmount --write-overlay $OVERLAY_DIR $tar $MOUNT_POINT

# add file to mounted archive
ls -al / > $MOUNT_POINT/file2

# add folder to mounted archive
mkdir -p $MOUNT_POINT/dir2

# umount tar
sleep 1
umount_dir

# commit changes
echo "committing changes..."
ratarmount --commit-overlay --write-overlay $OVERLAY_DIR $tar $MOUNT_POINT <<EOT
commit
EOT

echo
tar tf $tar
echo

Thank you!

mxmlnkn commented 5 months ago

Hi there, glad I was able to help previously.

I have some follow-up questions:

mxmlnkn commented 5 months ago

The follow-up questions are unnecessary. The bug is obvious. English is hardcoded in the line with sed '/^tar: Exiting with failure/d; /^tar.*Not found in archive/d'. You can fully ignore those warnings. What happens is: to avoid multiple versions of the same file existing in the TAR, the delete line, simply tries to remove all paths for files that later will be appended to the archive. The resulting warnings by GNU tar are filtered, which only works in English.