[svn] Fix various bugs in the recursive extraction. trunk

Sun, 20 Jan 2008 01:59:42 -0500

author
brett
date
Sun, 20 Jan 2008 01:59:42 -0500
branch
trunk
changeset 47
b034b6b4227d
parent 46
652871d804ab
child 48
0a0eeeb5b97d

[svn] Fix various bugs in the recursive extraction.

First, 5.0 introduced a regression where it wouldn't find archives hidden
in subdirectories. So fix that.

Then recursive extraction would get confused if the archive was a ONE_ENTRY
and we decided to wrap it or just extract it here. Fix that too: the
extractor keeps track of where it thinks it's extracting to, and then the
handler will change that if necessary.

There are unit tests for all this.

I twiddled some other small thing while I was at it but now I forget what.

TODO file | annotate | diff | comparison | revisions
scripts/dtrx file | annotate | diff | comparison | revisions
tests/test-deep-recursion.tar file | annotate | diff | comparison | revisions
tests/tests.yml file | annotate | diff | comparison | revisions
--- a/TODO	Thu Jan 17 22:44:46 2008 -0500
+++ b/TODO	Sun Jan 20 01:59:42 2008 -0500
@@ -1,8 +1,6 @@
 To do:
-* Fix recursive extraction to check subdirectories
 * Add ability to list included archives for recursive extraction
 * Make C-c not print a stack trace.
-* Make -v report some kind of progress
 
 Things which I have a use case/anti-use case for:
 * Support pisi packages (http://paketler.pardus.org.tr/pardus-2007/)
--- a/scripts/dtrx	Thu Jan 17 22:44:46 2008 -0500
+++ b/scripts/dtrx	Sun Jan 20 01:59:42 2008 -0500
@@ -197,11 +197,18 @@
     def prepare(self):
         pass
 
-    def check_included_archives(self, filenames):
-        for filename in filenames:
-            if (ExtractorBuilder.try_by_mimetype(filename) or
-                ExtractorBuilder.try_by_extension(filename)):
-                self.included_archives.append(filename)
+    def check_included_archives(self):
+        if (self.content_name is None) or (not self.content_name.endswith('/')):
+            self.included_root = './'
+        else:
+            self.included_root = self.content_name
+        start_index = len(self.included_root)
+        for path, dirname, filenames in os.walk(self.included_root):
+            path = path[start_index:]
+            for filename in filenames:
+                if (ExtractorBuilder.try_by_mimetype(filename) or
+                    ExtractorBuilder.try_by_extension(filename)):
+                    self.included_archives.append(os.path.join(path, filename))
 
     def check_contents(self):
         filenames = os.listdir('.')
@@ -217,7 +224,7 @@
                 self.content_name += '/'
         else:
             self.content_type = BOMB
-        self.check_included_archives(filenames)
+        self.check_included_archives()
 
     def basename(self):
         pieces = os.path.basename(self.filename).split('.')
@@ -334,7 +341,7 @@
         return '.'.join(pieces)
 
     def check_contents(self):
-        self.check_included_archives(os.listdir('.'))
+        self.check_included_archives()
         self.content_type = BOMB
 
 
@@ -356,7 +363,7 @@
         return '_'.join(pieces)
 
     def check_contents(self):
-        self.check_included_archives(os.listdir('.'))
+        self.check_included_archives()
         self.content_type = BOMB
 
 
@@ -375,7 +382,7 @@
         self.pipe(['zcat'], "data.tar.gz decompression")
 
     def check_contents(self):
-        self.check_included_archives(os.listdir('.'))
+        self.check_included_archives()
         self.content_type = BOMB
 
 
@@ -563,6 +570,7 @@
             os.rmdir(self.extractor.target)
         else:
             os.rename(self.extractor.target, self.target)
+        self.extractor.included_root = '.'
 
 
 class EmptyHandler(object):
@@ -926,8 +934,8 @@
         if self.options.recursion_policy.ok_to_recurse():
             for filename in archives:
                 tail_path, basename = os.path.split(filename)
-                directory = os.path.join(self.current_directory,
-                                         action.target, tail_path)
+                directory = os.path.join(self.current_directory, action.target,
+                                         extractor.included_root, tail_path)
                 self.archives.setdefault(directory, []).append(basename)
 
     def check_file(self, filename):
Binary file tests/test-deep-recursion.tar has changed
--- a/tests/tests.yml	Thu Jan 17 22:44:46 2008 -0500
+++ b/tests/tests.yml	Sun Jan 20 01:59:42 2008 -0500
@@ -405,6 +405,51 @@
     extract $1
     extract $1 .1
 
+- name: recursion in subdirectories here
+  filenames: test-deep-recursion.tar
+  options: ""
+  input: |
+    h
+    o
+  grep: "contains 2"
+  baseline: |
+    tar -xf $1
+    cd subdir
+    zcat test-text.gz > test-text
+    cd subsubdir
+    zcat test-text.gz > test-text
+
+- name: recursion in subdirectories with rename
+  filenames: test-deep-recursion.tar
+  options: ""
+  input: |
+    r
+    o
+  grep: "contains 2"
+  baseline: |
+    tar -xf $1
+    mv subdir test-deep-recursion
+    cd test-deep-recursion
+    zcat test-text.gz > test-text
+    cd subsubdir
+    zcat test-text.gz > test-text
+
+- name: recursion in subdirectories inside new dir
+  filenames: test-deep-recursion.tar
+  options: ""
+  input: |
+    i
+    o
+  grep: "contains 2"
+  baseline: |
+    mkdir test-deep-recursion
+    cd test-deep-recursion
+    tar -xf ../$1
+    cd subdir
+    zcat test-text.gz > test-text
+    cd subsubdir
+    zcat test-text.gz > test-text
+
 - name: extracting file with bad extension
   filenames: test-1.23.bin
   prerun: cp ${1}test-1.23.tar.gz ${1}test-1.23.bin
@@ -447,6 +492,7 @@
   prerun: |
     touch unreadable-file.tar.gz
     chmod 000 unreadable-file.tar.gz
+  cleanup: rm -f unreadable-file.tar.gz
   error: true
   grep: "[Pp]ermission denied"
 
@@ -455,6 +501,7 @@
   prerun: |
     touch unreadable-file.zip
     chmod 000 unreadable-file.zip
+  cleanup: rm -f unreadable-file.zip
   error: true
   grep: "[Pp]ermission denied"
 

mercurial