[Erp5-report] r12465 - /spec/mandriva/2007.0/python/Python-2.4.3-tarfile.py.patch
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jan 30 17:22:56 CET 2007
Author: kevin
Date: Tue Jan 30 17:22:54 2007
New Revision: 12465
URL: http://svn.erp5.org?rev=12465&view=rev
Log:
Patch to fix tarfile.py
Added:
spec/mandriva/2007.0/python/Python-2.4.3-tarfile.py.patch
Added: spec/mandriva/2007.0/python/Python-2.4.3-tarfile.py.patch
URL: http://svn.erp5.org/spec/mandriva/2007.0/python/Python-2.4.3-tarfile.py.patch?rev=12465&view=auto
==============================================================================
--- spec/mandriva/2007.0/python/Python-2.4.3-tarfile.py.patch (added)
+++ spec/mandriva/2007.0/python/Python-2.4.3-tarfile.py.patch Tue Jan 30 17:22:54 2007
@@ -1,0 +1,243 @@
+--- Python-2.4.3/Lib/tarfile.py-python2.4.3 2005-10-28 08:00:51.000000000 +0200
++++ Python-2.4.3/Lib/tarfile.py 2005-03-04 00:15:03.000000000 +0100
+@@ -688,11 +688,6 @@
+ tarinfo.devmajor = tarinfo.devmajor = 0
+ tarinfo.prefix = buf[345:500]
+
+- # Some old tar programs represent a directory as a regular
+- # file with a trailing slash.
+- if tarinfo.isreg() and tarinfo.name.endswith("/"):
+- tarinfo.type = DIRTYPE
+-
+ # The prefix field is used for filenames > 100 in
+ # the POSIX standard.
+ # name = prefix + '/' + name
+@@ -700,7 +695,7 @@
+ tarinfo.name = normpath(os.path.join(nts(tarinfo.prefix), tarinfo.name))
+
+ # Directory names should have a '/' at the end.
+- if tarinfo.isdir():
++ if tarinfo.isdir() and tarinfo.name[-1:] != "/":
+ tarinfo.name += "/"
+ return tarinfo
+
+@@ -1108,8 +1103,7 @@
+ stmd = statres.st_mode
+ if stat.S_ISREG(stmd):
+ inode = (statres.st_ino, statres.st_dev)
+- if not self.dereference and \
+- statres.st_nlink > 1 and inode in self.inodes:
++ if inode in self.inodes and not self.dereference:
+ # Is it a hardlink to an already
+ # archived file?
+ type = LNKTYPE
+@@ -1138,16 +1132,17 @@
+
+ # Fill the TarInfo object with all
+ # information we can get.
+- tarinfo.name = arcname
+- tarinfo.mode = stmd
+- tarinfo.uid = statres.st_uid
+- tarinfo.gid = statres.st_gid
+- if stat.S_ISREG(stmd):
+- tarinfo.size = statres.st_size
++ tarinfo.name = arcname
++ tarinfo.mode = stmd
++ tarinfo.uid = statres.st_uid
++ tarinfo.gid = statres.st_gid
++ if stat.S_ISDIR(stmd):
++ # For a directory, the size must be 0
++ tarinfo.size = 0
+ else:
+- tarinfo.size = 0L
++ tarinfo.size = statres.st_size
+ tarinfo.mtime = statres.st_mtime
+- tarinfo.type = type
++ tarinfo.type = type
+ tarinfo.linkname = linkname
+ if pwd:
+ try:
+@@ -1238,15 +1233,16 @@
+ self.addfile(tarinfo, f)
+ f.close()
+
+- elif tarinfo.isdir():
++ if tarinfo.type in (LNKTYPE, SYMTYPE, FIFOTYPE, CHRTYPE, BLKTYPE):
++ tarinfo.size = 0L
++ self.addfile(tarinfo)
++
++ if tarinfo.isdir():
+ self.addfile(tarinfo)
+ if recursive:
+ for f in os.listdir(name):
+ self.add(os.path.join(name, f), os.path.join(arcname, f))
+
+- else:
+- self.addfile(tarinfo)
+-
+ def addfile(self, tarinfo, fileobj=None):
+ """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
+ given, tarinfo.size bytes are read from it and added to the archive.
+@@ -1378,7 +1374,7 @@
+ # stream of tar blocks.
+ raise StreamError, "cannot extract (sym)link as file object"
+ else:
+- # A (sym)link's file object is its target's file object.
++ # A (sym)link's file object is it's target's file object.
+ return self.extractfile(self._getmember(tarinfo.linkname,
+ tarinfo))
+ else:
+@@ -1633,6 +1629,10 @@
+ # Skip the following data blocks.
+ self.offset += self._block(tarinfo.size)
+
++ if tarinfo.isreg() and tarinfo.name[:-1] == "/":
++ # some old tar programs don't know DIRTYPE
++ tarinfo.type = DIRTYPE
++
+ self.members.append(tarinfo)
+ return tarinfo
+
+--- Python-2.4.3/Lib/test/test_tarfile.py-2.4.3 2005-10-28 08:00:51.000000000 +0200
++++ Python-2.4.3/Lib/test/test_tarfile.py 2004-10-25 05:19:41.000000000 +0200
+@@ -134,30 +134,6 @@
+ "readlines() after seek failed")
+ fobj.close()
+
+- def test_old_dirtype(self):
+- """Test old style dirtype member (bug #1336623).
+- """
+- # Old tars create directory members using a REGTYPE
+- # header with a "/" appended to the filename field.
+-
+- # Create an old tar style directory entry.
+- filename = tmpname()
+- tarinfo = tarfile.TarInfo("directory/")
+- tarinfo.type = tarfile.REGTYPE
+-
+- fobj = file(filename, "w")
+- fobj.write(tarinfo.tobuf())
+- fobj.close()
+-
+- # Test if it is still a directory entry when
+- # read back.
+- tar = tarfile.open(filename)
+- tarinfo = tar.getmembers()[0]
+- tar.close()
+-
+- self.assert_(tarinfo.type == tarfile.DIRTYPE)
+- self.assert_(tarinfo.name.endswith("/"))
+-
+ class ReadStreamTest(ReadTest):
+ sep = "|"
+
+@@ -232,40 +208,6 @@
+ else:
+ self.dst.addfile(tarinfo, f)
+
+-class WriteSize0Test(BaseTest):
+- mode = 'w'
+-
+- def setUp(self):
+- self.tmpdir = dirname()
+- self.dstname = tmpname()
+- self.dst = tarfile.open(self.dstname, "w")
+-
+- def tearDown(self):
+- self.dst.close()
+-
+- def test_file(self):
+- path = os.path.join(self.tmpdir, "file")
+- file(path, "w")
+- tarinfo = self.dst.gettarinfo(path)
+- self.assertEqual(tarinfo.size, 0)
+- file(path, "w").write("aaa")
+- tarinfo = self.dst.gettarinfo(path)
+- self.assertEqual(tarinfo.size, 3)
+-
+- def test_directory(self):
+- path = os.path.join(self.tmpdir, "directory")
+- os.mkdir(path)
+- tarinfo = self.dst.gettarinfo(path)
+- self.assertEqual(tarinfo.size, 0)
+-
+- def test_symlink(self):
+- if hasattr(os, "symlink"):
+- path = os.path.join(self.tmpdir, "symlink")
+- os.symlink("link_target", path)
+- tarinfo = self.dst.gettarinfo(path)
+- self.assertEqual(tarinfo.size, 0)
+-
+-
+ class WriteStreamTest(WriteTest):
+ sep = '|'
+
+@@ -374,53 +316,6 @@
+ if e.errno == errno.ENOENT:
+ self.fail("hardlink not extracted properly")
+
+-class CreateHardlinkTest(BaseTest):
+- """Test the creation of LNKTYPE (hardlink) members in an archive.
+- In this respect tarfile.py mimics the behaviour of GNU tar: If
+- a file has a st_nlink > 1, it will be added a REGTYPE member
+- only the first time.
+- """
+-
+- def setUp(self):
+- self.tar = tarfile.open(tmpname(), "w")
+-
+- self.foo = os.path.join(dirname(), "foo")
+- self.bar = os.path.join(dirname(), "bar")
+-
+- if os.path.exists(self.foo):
+- os.remove(self.foo)
+- if os.path.exists(self.bar):
+- os.remove(self.bar)
+-
+- file(self.foo, "w").write("foo")
+- self.tar.add(self.foo)
+-
+- def test_add_twice(self):
+- # If st_nlink == 1 then the same file will be added as
+- # REGTYPE every time.
+- tarinfo = self.tar.gettarinfo(self.foo)
+- self.assertEqual(tarinfo.type, tarfile.REGTYPE,
+- "add file as regular failed")
+-
+- def test_add_hardlink(self):
+- # If st_nlink > 1 then the same file will be added as
+- # LNKTYPE.
+- os.link(self.foo, self.bar)
+- tarinfo = self.tar.gettarinfo(self.foo)
+- self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
+- "add file as hardlink failed")
+-
+- tarinfo = self.tar.gettarinfo(self.bar)
+- self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
+- "add file as hardlink failed")
+-
+- def test_dereference_hardlink(self):
+- self.tar.dereference = True
+- os.link(self.foo, self.bar)
+- tarinfo = self.tar.gettarinfo(self.bar)
+- self.assertEqual(tarinfo.type, tarfile.REGTYPE,
+- "dereferencing hardlink failed")
+-
+
+ # Gzip TestCases
+ class ReadTestGzip(ReadTest):
+@@ -471,14 +366,12 @@
+ ReadTest,
+ ReadStreamTest,
+ WriteTest,
+- WriteSize0Test,
+ WriteStreamTest,
+ WriteGNULongTest,
+ ]
+
+ if hasattr(os, "link"):
+ tests.append(ExtractHardlinkTest)
+- tests.append(CreateHardlinkTest)
+
+ if gzip:
+ tests.extend([
More information about the Erp5-report
mailing list