diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/system/system.api.php | 28 | ||||
-rw-r--r-- | modules/system/system.archiver.inc | 67 | ||||
-rw-r--r-- | modules/system/system.info | 1 | ||||
-rw-r--r-- | modules/system/system.module | 12 |
4 files changed, 108 insertions, 0 deletions
diff --git a/modules/system/system.api.php b/modules/system/system.api.php index c1f597855..1f4d1d394 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -2399,6 +2399,34 @@ function hook_action_info_alter(&$actions) { } /** + * Declare archivers to the system. + * + * An archiver is a class that is able to package and unpackage one or more files + * into a single possibly compressed file. Common examples of such files are + * zip files and tar.gz files. All archiver classes must implement + * ArchiverInterface. + * + * When mapping a + * + * Each entry should be keyed on a unique value, and specify three + * additional keys: + * - class: The name of the PHP class for this archiver. + * - extensions: An array of file extensions that this archiver supports. + * - weight: This optional key specifies the weight of this archiver. + * When mapping file extensions to archivers, the first archiver by + * weight found that supports the requested extension will be used. + */ +function system_archiver_info() { + return array( + 'tar' => array( + 'class' => 'ArchiverTar', + 'extensions' => array('tar', 'tar.gz', 'tar.bz2'), + ), + ); +} + + +/** * Defines additional date types. * * Next to the 'long', 'medium' and 'short' date types defined in core, any diff --git a/modules/system/system.archiver.inc b/modules/system/system.archiver.inc new file mode 100644 index 000000000..65bf63e3a --- /dev/null +++ b/modules/system/system.archiver.inc @@ -0,0 +1,67 @@ +<?php + +/** + * @file + * Archiver implementations provided by the system module. + */ + +/** + * Archiver for .tar files. + */ +class ArchiverTar implements ArchiverInterface { + + /** + * The underlying Archive_Tar instance that does the heavy lifting. + * + * @var Archive_Tar + */ + protected $tar; + + public function __construct($file_path) { + $this->tar = new Archive_Tar($file_path); + } + + public function add($file_path) { + $this->tar->add($file_path); + + return $this; + } + + public function remove($path) { + // @todo Archive_Tar doesn't have a remove operation + // so we'll have to simulate it somehow, probably by + // creating a new archive with everything but the removed + // file. + + return $this; + } + + public function extract($path, Array $files = array()) { + if ($files) { + $this->tar->extractList($files, $path); + } + else { + $this->tar->extract($path); + } + + return $this; + } + + public function listContents() { + return $this->tar->listContent(); + } + + /** + * Retrieve the tar engine itself. + * + * In some cases it may be necessary to directly access the underlying + * Archive_Tar object for implementation-specific logic. This is for advanced + * use only as it is not shared by other implementations of ArchiveInterface. + * + * @return + * The Archive_Tar object used by this object. + */ + public function getArchive() { + return $this->tar; + } +} diff --git a/modules/system/system.info b/modules/system/system.info index fa9a77d59..2f288d9d7 100644 --- a/modules/system/system.info +++ b/modules/system/system.info @@ -6,6 +6,7 @@ version = VERSION core = 7.x files[] = system.module files[] = system.admin.inc +files[] = system.archiver.inc files[] = system.queue.inc files[] = image.gd.inc files[] = system.install diff --git a/modules/system/system.module b/modules/system/system.module index 70c789f8b..e89eb625b 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -3380,6 +3380,18 @@ function system_date_format_delete($dfid) { } /** + * Implement hook_archiver_info(). + */ +function system_archiver_info() { + return array( + 'tar' => array( + 'class' => 'ArchiverTar', + 'extensions' => array('tar', 'tar.gz', 'tar.bz2'), + ), + ); +} + +/** * Theme confirmation forms. * * By default this does not alter the appearance of a form at all, |