Subject: | list_files() sometimes removes trailing '/' from directories |
Date: | Mon, 23 Jan 2017 15:53:11 -0600 |
To: | bug-Archive-Tar [...] rt.cpan.org |
From: | Chris Lindee <chris.lindee [...] cpanel.net> |
When the header for a directory listing in a tarball uses both the 'Prefix’ and ‘Name’ fields, any trailing slashes in the ‘Name' are removed. However, if the directory only uses the ‘Name’ field or uses constructs like ././@LongLink, trailing slashes are not removed from the name. This causes inconsistency in the output of list_files().
In particular, I’ve seen this issue with tarballs created by git-archive (so it appears modern tools still use this format). Can this function be made to not strip trailing ‘/‘ characters [0]?
mkdir -p directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdir/
echo "hey" > directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdir/file
tar -H ustar -cvf testing.tar directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/
echo "Tar results:"
tar -tf testing.tar
echo
echo "Archive::Tar results:"
perl -MArchive::Tar -e 'print join "\n", Archive::Tar->new("testing.tar")->list_files(), "”;'
Which will output (notice the missing slash on ’subdir/‘):
Tar results:
directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/
directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdir/
directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdir/file
Archive::Tar results:
directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/
directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdir
directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdir/file
Perl: v5.24.1
Archive::Tar: 2.04_01
See also: https://rt.cpan.org/Public/Bug/Display.html?id=101922 <https://rt.cpan.org/Public/Bug/Display.html?id=101922>
[0] Honestly, it would be better to always strip the trailing ‘/‘. This would force developers to use is_dir(), which is the most accurate way to check if the entry is a directory. However, I’m certain this would break compatibility with existing programs that expect directories to end with ‘/‘ and files to not.