# header information.
self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors)
+ # Remove redundant slashes from directories. This is to be consistent
+ # with frombuf().
+ if self.isdir():
+ self.name = self.name.rstrip("/")
+
return self
def _proc_gnulong(self, tarfile):
elif self.type == GNUTYPE_LONGLINK:
next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
+ # Remove redundant slashes from directories. This is to be consistent
+ # with frombuf().
+ if next.isdir():
+ next.name = next.name.removesuffix("/")
+
return next
def _proc_sparse(self, tarfile):
def add_dir_and_getmember(self, name):
with os_helper.temp_cwd():
with tarfile.open(tmpname, 'w') as tar:
+ tar.format = tarfile.USTAR_FORMAT
try:
os.mkdir(name)
tar.add(name)
"iso8859-1", "strict")
self.assertEqual(tarinfo.type, self.longnametype)
+ def test_longname_directory(self):
+ # Test reading a longlink directory. Issue #47231.
+ longdir = ('a' * 101) + '/'
+ with os_helper.temp_cwd():
+ with tarfile.open(tmpname, 'w') as tar:
+ tar.format = self.format
+ try:
+ os.mkdir(longdir)
+ tar.add(longdir)
+ finally:
+ os.rmdir(longdir)
+ with tarfile.open(tmpname) as tar:
+ self.assertIsNotNone(tar.getmember(longdir))
+ self.assertIsNotNone(tar.getmember(longdir.removesuffix('/')))
class GNUReadTest(LongnameTest, ReadTest, unittest.TestCase):
subdir = "gnu"
longnametype = tarfile.GNUTYPE_LONGNAME
+ format = tarfile.GNU_FORMAT
# Since 3.2 tarfile is supposed to accurately restore sparse members and
# produce files with holes. This is what we actually want to test here.
subdir = "pax"
longnametype = tarfile.XHDTYPE
+ format = tarfile.PAX_FORMAT
def test_pax_global_headers(self):
tar = tarfile.open(tarname, encoding="iso8859-1")