[Pkg-bazaar-commits] ./bzr-builddeb/trunk r209: Handle absolute pathnames in the tarfile.

James Westby jw+debian at jameswestby.net
Thu May 15 13:29:37 UTC 2008


------------------------------------------------------------
revno: 209
committer: James Westby <jw+debian at jameswestby.net>
branch nick: trunk
timestamp: Fri 2008-01-25 18:04:31 +0000
message:
  Handle absolute pathnames in the tarfile.
modified:
  import_dsc.py
  tests/test_import_dsc.py
-------------- next part --------------
=== modified file 'import_dsc.py'
--- a/import_dsc.py	2008-01-25 17:27:48 +0000
+++ b/import_dsc.py	2008-01-25 18:04:31 +0000
@@ -140,6 +140,8 @@
             continue
         relative_path = member.name
         relative_path = osutils.normpath(relative_path)
+        while relative_path.startswith('/'):
+          relative_path = relative_path.lstrip('/')
         if prefix is not None:
             relative_path = relative_path[len(prefix)+1:]
         if relative_path == '' or relative_path == '.':

=== modified file 'tests/test_import_dsc.py'
--- a/tests/test_import_dsc.py	2008-01-25 17:27:48 +0000
+++ b/tests/test_import_dsc.py	2008-01-25 18:04:31 +0000
@@ -1106,6 +1106,26 @@
     self.failUnlessExists(self.target)
     self.failIfExists(os.path.join(self.target, dir))
 
+  def test_import_absolute_path(self):
+    dir = 'dir'
+    os.mkdir(dir)
+    write_to_file(os.path.join(dir, 'README'), 'hello\n')
+    write_to_file(os.path.join(dir, 'NEWS'), 'bye bye\n')
+    tar = tarfile.open(self.native_1, 'w:gz')
+    try:
+      tar.addfile(_TarInfo(dir))
+      tar.addfile(_TarInfo('/' + os.path.join(dir, 'README')))
+      tar.addfile(_TarInfo(os.path.join(dir, 'NEWS')))
+    finally:
+      tar.close()
+      shutil.rmtree(dir)
+    self.make_dsc(self.native_dsc_1, '0.1', self.native_1)
+    DscImporter([self.native_dsc_1]).import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    self.failIfExists(os.path.join(self.target, dir))
+    self.failUnlessExists(os.path.join(self.target, 'README'))
+    self.failUnlessExists(os.path.join(self.target, 'NEWS'))
+
   def test_import_with_rcs(self):
     write_to_file('README', 'hello\n')
     write_to_file('README,v', 'bye bye\n')



More information about the Pkg-bazaar-commits mailing list