cvs diff: Diffing modules/system
Index: modules/system/system.archiver.inc
===================================================================
RCS file: /Users/wright/drupal/local_repo/drupal/modules/system/system.archiver.inc,v
retrieving revision 1.2
diff -u -p -r1.2 system.archiver.inc
--- modules/system/system.archiver.inc	16 Oct 2009 13:18:32 -0000	1.2
+++ modules/system/system.archiver.inc	31 Jan 2010 21:27:56 -0000
@@ -66,3 +66,70 @@ class ArchiverTar implements ArchiverInt
     return $this->tar;
   }
 }
+
+/**
+ * Archiver for .zip files.
+ */
+class ArchiverZip implements ArchiverInterface {
+
+  /**
+   * The underlying ZipArchive instance that does the heavy lifting.
+   *
+   * @var ZipArchive
+   */
+  protected $zip;
+
+  public function __construct($file_path) {
+    $this->zip = new ZipArchive();
+    if (!$this->zip->open($file_path)) {
+      throw new Exception(t('Cannot open %file_path', array('%file_path' => $file_path)));
+    }
+  }
+
+  public function add($file_path) {
+    $this->zip->addFile($file_path);
+
+    return $this;
+  }
+
+  public function remove($path) {
+    $this->zip->deleteName($file_path);
+
+    return $this;
+  }
+
+  public function extract($path, Array $files = array()) {
+    $this->zip->extractTo($path, $files);
+
+    return $this;
+  }
+
+  public function listContents() {
+    $files = array();
+    for ($i=0; $i < $this->zip->numFiles; $i++) {
+      $stat = $this->zip->statIndex($i);
+      // The interface expects that the file name lives in an attribute called
+      // 'filename', but statIndex() returns it in something called 'name',
+      // so we have to move it so that callers can find it consistently.
+      $stat['filename'] = $stat['name'];
+      unset($stat['name']);
+      $files[] = $stat;
+    }
+
+    return $files;
+  }
+
+  /**
+   * Retrieve the zip engine itself.
+   *
+   * In some cases it may be necessary to directly access the underlying
+   * ZipArchive object for implementation-specific logic. This is for advanced
+   * use only as it is not shared by other implementations of ArchiveInterface.
+   *
+   * @return
+   *   The ZipArchive object used by this object.
+   */
+  public function getArchive() {
+    return $this->zip;
+  }
+}
Index: modules/system/system.module
===================================================================
RCS file: /Users/wright/drupal/local_repo/drupal/modules/system/system.module,v
retrieving revision 1.881
diff -u -p -r1.881 system.module
--- modules/system/system.module	30 Jan 2010 07:54:01 -0000	1.881
+++ modules/system/system.module	31 Jan 2010 18:52:47 -0000
@@ -3539,12 +3539,17 @@ function system_date_format_delete($dfid
  * Implements hook_archiver_info().
  */
 function system_archiver_info() {
-  return array(
-    'tar' => array(
-      'class' => 'ArchiverTar',
-      'extensions' => array('tar', 'tar.gz', 'tar.bz2'),
-    ),
+  $archivers['tar'] = array(
+    'class' => 'ArchiverTar',
+    'extensions' => array('tar', 'tar.gz', 'tar.bz2'),
   );
+  if (function_exists('zip_open')) {
+    $archivers['zip'] = array(
+      'class' => 'ArchiverZip',
+      'extensions' => array('zip'),
+    );
+  }
+  return $archivers;
 }
 
 /**
