]> granicus.if.org Git - python/commitdiff
merge from 3.1
authorSenthil Kumaran <senthil@uthcode.com>
Fri, 29 Apr 2011 22:09:51 +0000 (06:09 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Fri, 29 Apr 2011 22:09:51 +0000 (06:09 +0800)
1  2 
Lib/test/test_tarfile.py

index f363f701cb19921c2c8dac84d96f702ec9db44b6,6c7db9535f5088b1ba158e6d627635cc78d0819c..8036c5cda138a4486f59fadc8863dd593a9a6f6a
@@@ -327,31 -230,25 +327,30 @@@ class MiscReadTest(CommonReadTest)
          # Test hardlink extraction (e.g. bug #857297).
          tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1")
  
 -        tar.extract("ustar/regtype", TEMPDIR)
          try:
 -            tar.extract("ustar/lnktype", TEMPDIR)
 -        except EnvironmentError as e:
 -            if e.errno == errno.ENOENT:
 -                self.fail("hardlink not extracted properly")
 -
 -        data = open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb").read()
 -        self.assertEqual(md5sum(data), md5_regtype)
 +            tar.extract("ustar/regtype", TEMPDIR)
 +            try:
 +                tar.extract("ustar/lnktype", TEMPDIR)
 +            except EnvironmentError as e:
 +                if e.errno == errno.ENOENT:
 +                    self.fail("hardlink not extracted properly")
  
 -        try:
 -            tar.extract("ustar/symtype", TEMPDIR)
 -        except EnvironmentError as e:
 -            if e.errno == errno.ENOENT:
 -                self.fail("symlink not extracted properly")
 +            with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f:
 +                data = f.read()
 +            self.assertEqual(md5sum(data), md5_regtype)
  
 -        data = open(os.path.join(TEMPDIR, "ustar/symtype"), "rb").read()
 -        self.assertEqual(md5sum(data), md5_regtype)
 +            try:
 +                tar.extract("ustar/symtype", TEMPDIR)
 +            except EnvironmentError as e:
 +                if e.errno == errno.ENOENT:
 +                    self.fail("symlink not extracted properly")
 +
 +            with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f:
 +                data = f.read()
 +            self.assertEqual(md5sum(data), md5_regtype)
 +        finally:
 +            tar.close()
  
-     @support.skip_unless_symlink
      def test_extractall(self):
          # Test if extractall() correctly restores directory permissions
          # and times (see issue1735).
@@@ -951,38 -678,7 +950,40 @@@ class WriteTest(WriteTestBase)
          finally:
              shutil.rmtree(tempdir)
  
 -    @unittest.skipUnless(hasattr(os,'symlink'), "needs os.symlink")
 +    # Guarantee that stored pathnames are not modified. Don't
 +    # remove ./ or ../ or double slashes. Still make absolute
 +    # pathnames relative.
 +    # For details see bug #6054.
 +    def _test_pathname(self, path, cmp_path=None, dir=False):
 +        # Create a tarfile with an empty member named path
 +        # and compare the stored name with the original.
 +        foo = os.path.join(TEMPDIR, "foo")
 +        if not dir:
 +            open(foo, "w").close()
 +        else:
 +            os.mkdir(foo)
 +
 +        tar = tarfile.open(tmpname, self.mode)
 +        try:
 +            tar.add(foo, arcname=path)
 +        finally:
 +            tar.close()
 +
 +        tar = tarfile.open(tmpname, "r")
 +        try:
 +            t = tar.next()
 +        finally:
 +            tar.close()
 +
 +        if not dir:
 +            os.remove(foo)
 +        else:
 +            os.rmdir(foo)
 +
 +        self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/"))
 +
++
++    @support.skip_unless_symlink
      def test_extractall_symlinks(self):
          # Test if extractall works properly when tarfile contains symlinks
          tempdir = os.path.join(TEMPDIR, "testsymlinks")