summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-02-01 19:14:14 +0000
committerDries Buytaert <dries@buytaert.net>2010-02-01 19:14:14 +0000
commitdf6ae20b4f60240df1da6b93cd495685d1447276 (patch)
tree1a67ae4f67bc3980020ea9a72d9f4ee6159c64d6
parent5c07276020b7be4abd68c18dbdf4c2bf6df259ce (diff)
downloadbrdo-df6ae20b4f60240df1da6b93cd495685d1447276.tar.gz
brdo-df6ae20b4f60240df1da6b93cd495685d1447276.tar.bz2
- Patch #693082 by dww: added an ArchiverZip class to support .zip files in update manager.
-rw-r--r--modules/system/system.archiver.inc63
-rw-r--r--modules/system/system.module17
2 files changed, 74 insertions, 6 deletions
diff --git a/modules/system/system.archiver.inc b/modules/system/system.archiver.inc
index c6880e170..9972bfc22 100644
--- a/modules/system/system.archiver.inc
+++ b/modules/system/system.archiver.inc
@@ -70,3 +70,66 @@ class ArchiverTar implements ArchiverInterface {
return $this->tar;
}
}
+
+/**
+ * Archiver for .zip files.
+ *
+ * @link http://php.net/zip
+ */
+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) !== TRUE) {
+ // @todo: This should be an interface-specific exception some day.
+ 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++) {
+ $files[] = $this->zip->getNameIndex($i);
+ }
+ 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;
+ }
+}
diff --git a/modules/system/system.module b/modules/system/system.module
index 02a5db5fd..28c5340ac 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -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;
}
/**