Lines Matching full:tar
45 tarname = support.findfile("testtar.tar")
46 gzipname = os.path.join(TEMPDIR, "testtar.tar.gz")
47 bz2name = os.path.join(TEMPDIR, "testtar.tar.bz2")
48 xzname = os.path.join(TEMPDIR, "testtar.tar.xz")
49 tmpname = os.path.join(TEMPDIR, "tmp.tar")
97 self.tar = tarfile.open(self.tarname, mode=self.mode,
101 self.tar.close()
107 tarinfo = self.tar.getmember("ustar/regtype")
108 with self.tar.extractfile(tarinfo) as fobj:
116 self.tar.extract("ustar/regtype", TEMPDIR, filter='data')
117 tarinfo = self.tar.getmember("ustar/regtype")
121 with self.tar.extractfile(tarinfo) as fobj:
134 self.tar.extract("ustar/regtype", TEMPDIR, filter='data')
135 tarinfo = self.tar.getmember("ustar/regtype")
138 with self.tar.extractfile(tarinfo) as fobj2:
144 self.tar.extract("ustar/regtype", TEMPDIR,
149 tarinfo = self.tar.getmember("ustar/regtype")
150 with self.tar.extractfile(tarinfo) as fobj:
193 with self.tar.extractfile("ustar/regtype") as fobj:
208 with self.tar.extractfile(lnktype) as a, \
209 self.tar.extractfile(regtype) as b:
242 with tarfile.open(tmpname, 'w') as tar:
243 tar.format = tarfile.USTAR_FORMAT
246 tar.add(name, filter=filter)
249 with tarfile.open(tmpname) as tar:
251 tar.getmember(name),
252 tar.getmember(name + '/')
269 self.tar = tarfile.open(self.tarname, mode=self.mode)
274 self.tar.list(verbose=False)
287 s = b.decode(self.tar.encoding, 'surrogateescape')
311 self.tar.list(verbose=True)
334 def members(tar): argument
335 for tarinfo in tar.getmembers():
339 self.tar.list(verbose=False, members=members(self.tar))
405 # This test checks if tarfile.open() is able to open an empty tar
406 # archive successfully. Note that an empty tar archive is not the
411 tar = tarfile.open(tmpname, self.mode)
412 tar.getnames()
416 self.assertListEqual(tar.getmembers(), [])
418 tar.close()
429 # file as an empty tar archive.
449 tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
451 self.assertListEqual(tar.getnames(), ["foo"],
455 tar.close()
459 with tarfile.open(tmpname, "w:") as tar:
462 tar.addfile(t, io.BytesIO(b"a" * 1024))
467 with tarfile.open(tmpname) as tar:
469 for t in tar:
472 with tarfile.open(tmpname) as tar:
473 t = tar.next()
476 tar.extract(t, TEMPDIR, filter='data')
479 tar.extractfile(t).read()
485 with tarfile.open(support.findfile('recursion.tar')) as tar:
496 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
497 self.assertIsInstance(tar.name, str)
498 self.assertEqual(tar.name, os.path.abspath(fobj.name))
505 tar = tarfile.open(fileobj=fobj, mode=self.mode)
506 self.assertIsNone(tar.name)
513 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
514 self.assertIsNone(tar.name)
522 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
523 self.assertIsNone(tar.name)
530 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
531 self.assertIsInstance(tar.name, bytes)
532 self.assertEqual(tar.name, os.path.abspath(fobj.name))
536 with tarfile.open(tarname, mode=self.mode) as tar:
537 self.assertIsInstance(tar.name, str)
538 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
539 with self.taropen(tarname) as tar:
540 self.assertIsInstance(tar.name, str)
541 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
542 with tarfile.TarFile.open(tarname, mode=self.mode) as tar:
543 self.assertIsInstance(tar.name, str)
544 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
546 with tarfile.TarFile(tarname, mode='r') as tar:
547 self.assertIsInstance(tar.name, str)
548 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
554 tar = self.taropen(tmpname, 'q')
556 tar = self.taropen(tmpname, 'rw')
558 tar = self.taropen(tmpname, '')
563 tar = tarfile.open(self.tarname, mode=self.mode)
565 tar.next()
566 t = tar.next()
569 with tar.extractfile(t) as f:
572 tar.close()
579 with tar.open(self.tarname, mode="r:", fileobj=fobj) as tar:
580 t = tar.next()
584 tar.getmembers()
585 self.assertEqual(tar.extractfile(t).read(), data,
599 tarinfo = self.tar.getmember("misc/dirtype-old-v7")
608 self.tar.getmember("misc/regtype-xstar")
613 for tarinfo in self.tar:
622 self.assertEqual(self.tar.getmembers()[-1].name, "misc/eof",
630 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
631 tar.extract("ustar/regtype", TEMPDIR, filter='data')
634 tar.extract("ustar/lnktype", TEMPDIR, filter='data')
640 tar.extract("ustar/symtype", TEMPDIR, filter='data')
650 tar = tarfile.open(tarname, encoding="iso8859-1")
654 directories = [t for t in tar if t.isdir()]
655 tar.extractall(DIR, directories, filter='fully_trusted')
669 errmsg = "tar mtime {0} != file time {1} of path {2!a}".format(
675 tar.close()
684 with tarfile.open(tarname, encoding="iso8859-1") as tar:
685 tarinfo = tar.getmember(dirtype)
686 tar.extract(tarinfo, path=DIR, filter='fully_trusted')
697 tarfile.open(tarname, encoding="iso8859-1") as tar:
698 directories = [t for t in tar if t.isdir()]
699 tar.extractall(DIR, directories, filter='fully_trusted')
708 tarfile.open(tarname, encoding="iso8859-1") as tar:
709 tarinfo = tar.getmember(dirtype)
710 tar.extract(tarinfo, path=DIR, filter='fully_trusted')
723 tar = object.__new__(tarfile.TarFile)
725 tar.__init__(empty)
727 self.assertTrue(tar.fileobj.closed)
736 with tarfile.open(self.tarname) as tar:
737 for m1, m2 in zip(tar, tar):
784 # caused seeking errors with stream tar files.
785 for tarinfo in self.tar:
788 with self.tar.extractfile(tarinfo) as fobj:
799 tarinfo = self.tar.next() # get "regtype" (can't use getmember)
800 with self.tar.extractfile(tarinfo) as fobj:
808 tarinfos = self.tar.getmembers()
809 with self.tar.extractfile(tarinfos[0]) as f: # read the first member
815 tar2 = self.tar
852 tar = tarfile.open(name, mode)
856 tar.close()
861 tar = tarfile.open(name, mode, fileobj=f)
865 tar.close()
915 with self.tar.extractfile(tarinfo) as f:
923 # V7 tar can't handle alphabetic owners.
931 tarinfo = self.tar.getmember("ustar/regtype")
935 tarinfo = self.tar.getmember("ustar/conttype")
939 tarinfo = self.tar.getmember("ustar/dirtype")
943 tarinfo = self.tar.getmember("ustar/dirtype-with-size")
947 tarinfo = self.tar.getmember("ustar/lnktype")
951 tarinfo = self.tar.getmember("ustar/symtype")
955 tarinfo = self.tar.getmember("ustar/blktype")
959 tarinfo = self.tar.getmember("ustar/chrtype")
963 tarinfo = self.tar.getmember("ustar/fifotype")
967 tarinfo = self.tar.getmember("ustar/sparse")
971 tarinfo = self.tar.getmember("gnu/sparse")
975 tarinfo = self.tar.getmember("gnu/sparse-0.0")
979 tarinfo = self.tar.getmember("gnu/sparse-0.1")
983 tarinfo = self.tar.getmember("gnu/sparse-1.0")
987 tarinfo = self.tar.getmember("ustar/umlauts-"
993 self.assertIn(name, self.tar.getnames())
996 tarinfo = self.tar.getmember("misc/regtype-old-v7")
1000 self.tar.close()
1001 self.tar = tarfile.open(self.tarname, mode=self.mode,
1003 tarinfo = self.tar.getmember("pax/umlauts-"
1014 tarinfo = self.tar.getmember(longname)
1024 tarinfo = self.tar.getmember(longlink)
1031 tarinfo = self.tar.getmember(longname)
1033 self.tar.fileobj.seek(offset)
1034 fobj = io.BytesIO(self.tar.fileobj.read(3 * 512))
1036 tarfile.open(name="foo.tar", fileobj=fobj)
1042 offset = self.tar.getmember(longname).offset
1053 with tarfile.open(tmpname, 'w') as tar:
1054 tar.format = self.format
1057 tar.add(longdir)
1060 with tarfile.open(tmpname) as tar:
1061 self.assertIsNotNone(tar.getmember(longdir))
1062 self.assertIsNotNone(tar.getmember(longdir.removesuffix('/')))
1078 self.tar.extract(name, TEMPDIR, filter='data')
1131 tar = tarfile.open(tarname, encoding="iso8859-1")
1133 tarinfo = tar.getmember("pax/regtype1")
1139 tarinfo = tar.getmember("pax/regtype2")
1145 tarinfo = tar.getmember("pax/regtype3")
1151 tar.close()
1155 tar = tarfile.open(tarname, encoding="iso8859-1")
1157 tarinfo = tar.getmember("pax/regtype4")
1166 tar.close()
1175 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
1176 tar.addfile(tarfile.TarInfo("foo"))
1180 del tar
1190 with tarfile.open(tmpname, self.mode) as tar:
1193 tar.addfile(t, io.BytesIO(b"a" * t.size))
1204 # The name field in a tar header stores strings of at most 100 chars.
1209 tar = tarfile.open(tmpname, self.mode)
1212 tar.addfile(t)
1214 tar.close()
1216 tar = tarfile.open(tmpname)
1218 self.assertEqual(tar.getnames()[0], name,
1221 tar.close()
1225 tar = tarfile.open(tmpname, self.mode)
1230 tar.add(path)
1232 tar.close()
1238 tar = tarfile.open(tmpname, self.mode)
1243 tarinfo = tar.gettarinfo(path)
1248 tarinfo = tar.gettarinfo(path)
1251 tar.close()
1257 tar = tarfile.open(tmpname, self.mode)
1259 tarinfo = tar.gettarinfo(path)
1262 tar.close()
1274 tar = tarfile.open(tmpname, self.mode)
1278 tar.add(path)
1280 for m in tar.getmembers():
1284 tar.close()
1291 with tarfile.open(tmpname, self.mode) as tar:
1295 tarinfo = tar.gettarinfo(path)
1296 tarinfo2 = tar.gettarinfo(os.fspath(path))
1313 tar = tarfile.open(tmpname, self.mode)
1316 tar.gettarinfo(target)
1317 tarinfo = tar.gettarinfo(link)
1320 tar.close()
1330 tar = tarfile.open(tmpname, self.mode)
1332 tarinfo = tar.gettarinfo(path)
1335 tar.close()
1342 tar = tarfile.open(tmpname, self.mode)
1344 self.assertEqual(tar.name, dstname,
1346 tar.add(dstname)
1347 self.assertEqual(tar.getnames(), [],
1351 tar.add(dstname)
1352 self.assertEqual(tar.getnames(), [],
1355 tar.close()
1372 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
1374 tar.add(tempdir, arcname="empty_dir", filter=filter)
1376 tar.close()
1380 tar.add(tempdir, "empty_dir", True, None, filter)
1382 tar = tarfile.open(tmpname, "r")
1384 for tarinfo in tar:
1387 self.assertEqual(len(tar.getmembers()), 3)
1389 tar.close()
1406 tar = tarfile.open(tmpname, self.mode)
1408 tar.add(foo, arcname=path)
1410 tar.close()
1412 tar = tarfile.open(tmpname, "r")
1414 t = tar.next()
1416 tar.close()
1430 temparchive = os.path.join(TEMPDIR, "testsymlinks.tar")
1438 with tarfile.open(temparchive, 'w') as tar:
1439 tar.add(source_file, arcname="source")
1440 tar.add(target_file, arcname="symlink")
1442 with tarfile.open(temparchive, errorlevel=2) as tar:
1445 tar.extractall(path=tempdir,
1480 tar = tarfile.open(tmpname, self.mode)
1482 tar.add(".")
1484 tar.close()
1486 tar = tarfile.open(tmpname, "r")
1488 for t in tar:
1492 tar.close()
1505 tar = tarfile.open(tmpname, self.mode, fileobj=f,
1530 tar = tarfile.open(tmpname, self.mode)
1531 tar.close()
1558 tar = tarfile.open(tmpname, self.mode)
1559 tar.close()
1569 Ensure the source directory is not included in the tar header
1593 # Initial tar header
1612 tar = tarfile.open(tmpname, "w")
1614 tar.format = tarfile.GNU_FORMAT
1615 tar.addfile(tarinfo)
1618 v2 = tar.offset
1621 tar.close()
1623 tar = tarfile.open(tmpname)
1625 member = tar.next()
1633 tar.close()
1675 tar = tarfile.open(tmpname, self.mode)
1681 tar.addfile(input_blk)
1682 tar.addfile(input_reg)
1684 tar.close()
1687 tar = tarfile.open(tmpname, "r")
1689 output_blk = tar.getmember("my_block_device")
1690 output_reg = tar.getmember("my_regular_file")
1692 tar.close()
1704 # <https://www.gnu.org/software/tar/manual/html_node/Standard.html>
1853 self.tar = tarfile.open(tmpname, "w")
1854 self.tar.add(self.foo)
1857 self.tar.close()
1864 tarinfo = self.tar.gettarinfo(self.foo)
1869 tarinfo = self.tar.gettarinfo(self.bar)
1874 self.tar.dereference = True
1875 tarinfo = self.tar.gettarinfo(self.bar)
1889 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
1891 tar.addfile(tarinfo)
1893 tar.close()
1895 tar = tarfile.open(tmpname)
1898 l = tar.getmembers()[0].linkname
1901 n = tar.getmembers()[0].name
1904 tar.close()
1914 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1917 tar.addfile(tarfile.TarInfo("test"))
1919 tar.close()
1922 tar = tarfile.open(tmpname, encoding="iso8859-1")
1924 self.assertEqual(tar.pax_headers, pax_headers)
1925 self.assertEqual(tar.getmembers()[0].pax_headers, pax_headers)
1927 for key, val in tar.pax_headers.items():
1936 tar.close()
1943 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1950 tar.addfile(t)
1952 tar.close()
1954 tar = tarfile.open(tmpname, encoding="iso8859-1")
1956 t = tar.getmembers()[0]
1961 tar.close()
2031 tar = tarfile.open(tmpname, "w", format=self.format,
2035 tar.addfile(tarfile.TarInfo(name))
2037 tar.close()
2039 tar = tarfile.open(tmpname, encoding=encoding)
2041 self.assertEqual(tar.getmembers()[0].name, name)
2043 tar.close()
2046 tar = tarfile.open(tmpname, "w", format=self.format,
2052 self.assertRaises(UnicodeError, tar.addfile, tarinfo)
2056 self.assertRaises(UnicodeError, tar.addfile, tarinfo)
2058 tar.close()
2061 tar = tarfile.open(tarname, "r",
2064 for t in tar:
2070 tar.close()
2077 tar = tarfile.open(tmpname, mode="w", format=self.format,
2080 tar.addfile(t)
2082 tar.close()
2084 tar = tarfile.open(tmpname, encoding="iso8859-1")
2086 t = tar.getmember("foo")
2091 tar.close()
2092 tar = tarfile.open(tmpname, encoding="ascii")
2093 t = tar.getmember("foo")
2097 tar.close()
2139 with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar:
2142 tar.addfile(t)
2144 self.assertRaises(exc, tar.addfile, t)
2147 with tarfile.open(tmpname, "r", encoding="utf-8") as tar:
2148 for t in tar:
2164 with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar:
2168 tar.addfile(t)
2170 self.assertRaises(exc, tar.addfile, t)
2173 with tarfile.open(tmpname, "r", encoding="utf-8") as tar:
2174 for t in tar:
2184 # Test for issue #8633. GNU tar <= 1.23 creates raw binary fields
2190 errors="surrogateescape") as tar:
2192 t = tar.getmember(name)
2194 self.fail("unable to read bad GNU tar pax header")
2210 errors="surrogateescape") as tar:
2212 t = tar.getmember(name)
2230 with tarfile.open(self.tarname, mode) as tar:
2231 tar.addfile(t, f)
2241 with tarfile.open(self.tarname, "a", fileobj=fileobj) as tar:
2242 tar.addfile(tarfile.TarInfo("bar"))
2245 with tarfile.open(self.tarname, fileobj=fileobj) as tar:
2246 self.assertEqual(tar.getnames(), names)
2383 # Issue 13158: Test if GNU tar specific base-256 number fields
2456 fname = os.path.join(os.path.dirname(__file__), 'testtar.tar.xz')
2517 self.assertIn(b'is a tar archive.\n', out)
2522 self.assertIn(b' is not a tar archive.', err)
2564 self.assertIn(b' is not a tar archive.', err)
2576 with tarfile.open(tmpname) as tar:
2577 tar.getmembers()
2590 with tarfile.open(tmpname) as tar:
2591 tar.getmembers()
2600 with tarfile.open(dotlessname) as tar:
2601 tar.getmembers()
2611 with tarfile.open(tar_name) as tar:
2612 tar.getmembers()
2626 with filetype.taropen(tar_name) as tar:
2627 tar.getmembers()
2684 self.assertIn(b' is not a tar archive.', err)
2692 with tarfile.open(tarname) as tar:
2693 self.assertFalse(tar.closed, "closed inside runtime context")
2694 self.assertTrue(tar.closed, "context manager failed")
2699 tar = tarfile.open(tarname)
2700 tar.close()
2702 with tar:
2708 with tarfile.open(tarname) as tar:
2712 self.assertTrue(tar.closed, "context manager failed")
2718 with tarfile.open(tmpname, "w") as tar:
2724 self.assertTrue(tar.closed, "context manager failed")
2739 with tarfile.open(fileobj=fobj, mode="w") as tar:
2744 self.assertTrue(tar.closed, "context manager failed")
2754 self.tar.extract(name, TEMPDIR, filter='fully_trusted')
2838 # create a tar file with a file, a directory, and a file within that
2854 # return the full pathname to the tar file
2950 member = self.tar.getmember('ustar/regtype')
2954 self.assertEqual(self.tar.getmember('ustar/regtype').name,
2958 member = self.tar.getmember('pax/regtype1')
2963 self.tar.getmember('pax/regtype1').pax_headers['gname'], 'bar')
2966 member = self.tar.getmember('pax/regtype1')
2971 self.tar.getmember('pax/regtype1').pax_headers['gname'], 'not-bar')
2974 member = self.tar.getmember('ustar/regtype')
2983 member = self.tar.getmember('ustar/regtype')
2999 tar = tarfile.open(tarname, mode='r', encoding="iso8859-1")
3001 tar.errorlevel = 0
3002 tar.extractall(cls.control_dir, filter=cls.extraction_filter)
3003 tar.close()
3021 self.tar.errorlevel = 0
3022 for member in self.tar.getmembers():
3026 self.tar.extractall(DIR, filter='fully_trusted')
3090 extraction_filter = 'tar'
3103 tar = tarfile.open(fileobj=bio, mode='w', format=tarformat)
3104 tarinfo = tar.gettarinfo(tarname)
3106 tar.addfile(tarinfo)
3121 tar.addfile(replaced)
3132 tarfile.open(tarname, encoding="iso8859-1") as tar):
3135 tar.list()
3136 for member in tar.getmembers():
3141 tar.list()
3219 """Helper to create a tar file with specific contents
3226 with t.open() as tar:
3227 ... # `tar` is now a TarFile with 'filename' in it!
3293 def check_context(self, tar, filter): argument
3294 """Extracts `tar` to `self.destdir` and allows checking the result
3305 tar.extractall(self.destdir, filter=filter)
3316 tar.close()
3362 for filter in 'fully_trusted', 'tar', 'data':
3375 for filter in 'tar', 'data':
3378 # We strip leading slashes, as e.g. GNU tar does
3414 with self.check_context(arc.open(), 'tar'):
3430 with self.check_context(arc.open(), 'tar'):
3453 with self.check_context(arc.open(), 'tar'):
3485 with self.check_context(arc.open(), 'tar'):
3514 # Note that e.g. GNU `tar` rejects '..' components,
3526 for filter in 'tar', 'data':
3546 for filter in 'tar', 'data':
3593 with self.check_context(arc.open(), 'tar'):
3616 for filter in 'fully_trusted', 'tar':
3637 tar = tarfile.tar_filter(tarinfo, '')
3638 self.assertEqual(tar.type, special_type)
3646 with tarfile.TarFile.open(tarname) as tar:
3647 for tarinfo in tar.getmembers():
3652 # The 'tar' filter returns TarInfo objects with the same name/type.
3655 with tarfile.TarFile.open(tarname) as tar:
3656 for tarinfo in tar.getmembers():
3664 with tarfile.TarFile.open(tarname) as tar:
3665 for tarinfo in tar.getmembers():
3682 tar = tarfile.TarFile(tarname, 'r')
3688 tar.extraction_filter = strict_filter
3689 with self.check_context(tar, None):
3698 tar = tarfile.TarFile(tarname, 'r')
3701 with self.check_context(tar, None):
3712 tar = TarSubclass(tarname, 'r')
3713 with self.check_context(tar, None):
3717 tar = tarfile.TarFile(tarname, 'r')
3718 tar.extraction_filter = 'data'
3719 with self.check_context(tar, None):
3861 with c.open(c.tarname, "wb") as tar:
3862 tar.write(data)