From 0cb434686ca05708dc53aba7254e882741de7477 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 2 May 2016 07:23:14 +0200 Subject: Move OC_Archive_XX to PSR-4 * Fix code * Fix tests --- lib/private/legacy/archive.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/private/legacy') diff --git a/lib/private/legacy/archive.php b/lib/private/legacy/archive.php index 62512d1448a..aebc586d721 100644 --- a/lib/private/legacy/archive.php +++ b/lib/private/legacy/archive.php @@ -28,6 +28,9 @@ * */ +use OC\Archive\TAR; +use OC\Archive\ZIP; + abstract class OC_Archive{ /** * Open any of the supported archive types @@ -40,11 +43,11 @@ abstract class OC_Archive{ switch($mime) { case 'application/zip': - return new OC_Archive_ZIP($path); + return new ZIP($path); case 'application/x-gzip': - return new OC_Archive_TAR($path); + return new TAR($path); case 'application/x-bzip2': - return new OC_Archive_TAR($path); + return new TAR($path); } } -- cgit v1.2.3 From c96ed5c4ce27d4ab62cf483193d311fed1c37556 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 2 May 2016 09:43:17 +0200 Subject: Move OC_Archive to \OC\Archive\Archive * Move out of legacy folder * Move to proper namespace * Fix calling code --- lib/private/Archive/Archive.php | 160 +++++++++++++++++++++++++++++++++++++++ lib/private/Archive/TAR.php | 2 +- lib/private/Archive/ZIP.php | 2 +- lib/private/Installer.php | 2 +- lib/private/legacy/archive.php | 161 ---------------------------------------- 5 files changed, 163 insertions(+), 164 deletions(-) create mode 100644 lib/private/Archive/Archive.php delete mode 100644 lib/private/legacy/archive.php (limited to 'lib/private/legacy') diff --git a/lib/private/Archive/Archive.php b/lib/private/Archive/Archive.php new file mode 100644 index 00000000000..b5286968a2f --- /dev/null +++ b/lib/private/Archive/Archive.php @@ -0,0 +1,160 @@ + + * @author Bart Visscher + * @author Christopher Schäpers + * @author Felix Moeller + * @author Joas Schilling + * @author Jörn Friedrich Dreyer + * @author Lukas Reschke + * @author Morris Jobke + * @author Robin Appelman + * @author Thomas Müller + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Archive; + +abstract class Archive{ + /** + * Open any of the supported archive types + * + * @param string $path + * @return Archive|void + */ + public static function open($path) { + $mime = \OC::$server->getMimeTypeDetector()->detect($path); + + switch($mime) { + case 'application/zip': + return new ZIP($path); + case 'application/x-gzip': + return new TAR($path); + case 'application/x-bzip2': + return new TAR($path); + } + } + + /** + * @param $source + */ + abstract function __construct($source); + /** + * add an empty folder to the archive + * @param string $path + * @return bool + */ + abstract function addFolder($path); + /** + * add a file to the archive + * @param string $path + * @param string $source either a local file or string data + * @return bool + */ + abstract function addFile($path, $source=''); + /** + * rename a file or folder in the archive + * @param string $source + * @param string $dest + * @return bool + */ + abstract function rename($source, $dest); + /** + * get the uncompressed size of a file in the archive + * @param string $path + * @return int + */ + abstract function filesize($path); + /** + * get the last modified time of a file in the archive + * @param string $path + * @return int + */ + abstract function mtime($path); + /** + * get the files in a folder + * @param string $path + * @return array + */ + abstract function getFolder($path); + /** + * get all files in the archive + * @return array + */ + abstract function getFiles(); + /** + * get the content of a file + * @param string $path + * @return string + */ + abstract function getFile($path); + /** + * extract a single file from the archive + * @param string $path + * @param string $dest + * @return bool + */ + abstract function extractFile($path, $dest); + /** + * extract the archive + * @param string $dest + * @return bool + */ + abstract function extract($dest); + /** + * check if a file or folder exists in the archive + * @param string $path + * @return bool + */ + abstract function fileExists($path); + /** + * remove a file or folder from the archive + * @param string $path + * @return bool + */ + abstract function remove($path); + /** + * get a file handler + * @param string $path + * @param string $mode + * @return resource + */ + abstract function getStream($path, $mode); + /** + * add a folder and all its content + * @param string $path + * @param string $source + * @return boolean|null + */ + function addRecursive($path, $source) { + $dh = opendir($source); + if(is_resource($dh)) { + $this->addFolder($path); + while (($file = readdir($dh)) !== false) { + if($file=='.' or $file=='..') { + continue; + } + if(is_dir($source.'/'.$file)) { + $this->addRecursive($path.'/'.$file, $source.'/'.$file); + }else{ + $this->addFile($path.'/'.$file, $source.'/'.$file); + } + } + } + } +} diff --git a/lib/private/Archive/TAR.php b/lib/private/Archive/TAR.php index e233bdeb9cc..d783e53d40c 100644 --- a/lib/private/Archive/TAR.php +++ b/lib/private/Archive/TAR.php @@ -32,7 +32,7 @@ namespace OC\Archive; -class TAR extends \OC_Archive { +class TAR extends Archive { const PLAIN = 0; const GZIP = 1; const BZIP = 2; diff --git a/lib/private/Archive/ZIP.php b/lib/private/Archive/ZIP.php index 1d35e178923..2bc17507d32 100644 --- a/lib/private/Archive/ZIP.php +++ b/lib/private/Archive/ZIP.php @@ -29,7 +29,7 @@ namespace OC\Archive; -class ZIP extends \OC_Archive{ +class ZIP extends Archive{ /** * @var \ZipArchive zip */ diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 643590ae22e..8ecc92e134b 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -300,7 +300,7 @@ class Installer { $extractDir = \OC::$server->getTempManager()->getTemporaryFolder(); OC_Helper::rmdirr($extractDir); mkdir($extractDir); - if($archive=\OC_Archive::open($path)) { + if($archive=\OC\Archive\Archive::open($path)) { $archive->extract($extractDir); } else { OC_Helper::rmdirr($extractDir); diff --git a/lib/private/legacy/archive.php b/lib/private/legacy/archive.php deleted file mode 100644 index aebc586d721..00000000000 --- a/lib/private/legacy/archive.php +++ /dev/null @@ -1,161 +0,0 @@ - - * @author Bart Visscher - * @author Christopher Schäpers - * @author Felix Moeller - * @author Joas Schilling - * @author Jörn Friedrich Dreyer - * @author Lukas Reschke - * @author Morris Jobke - * @author Robin Appelman - * @author Thomas Müller - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -use OC\Archive\TAR; -use OC\Archive\ZIP; - -abstract class OC_Archive{ - /** - * Open any of the supported archive types - * - * @param string $path - * @return OC_Archive|void - */ - public static function open($path) { - $mime = \OC::$server->getMimeTypeDetector()->detect($path); - - switch($mime) { - case 'application/zip': - return new ZIP($path); - case 'application/x-gzip': - return new TAR($path); - case 'application/x-bzip2': - return new TAR($path); - } - } - - /** - * @param $source - */ - abstract function __construct($source); - /** - * add an empty folder to the archive - * @param string $path - * @return bool - */ - abstract function addFolder($path); - /** - * add a file to the archive - * @param string $path - * @param string $source either a local file or string data - * @return bool - */ - abstract function addFile($path, $source=''); - /** - * rename a file or folder in the archive - * @param string $source - * @param string $dest - * @return bool - */ - abstract function rename($source, $dest); - /** - * get the uncompressed size of a file in the archive - * @param string $path - * @return int - */ - abstract function filesize($path); - /** - * get the last modified time of a file in the archive - * @param string $path - * @return int - */ - abstract function mtime($path); - /** - * get the files in a folder - * @param string $path - * @return array - */ - abstract function getFolder($path); - /** - * get all files in the archive - * @return array - */ - abstract function getFiles(); - /** - * get the content of a file - * @param string $path - * @return string - */ - abstract function getFile($path); - /** - * extract a single file from the archive - * @param string $path - * @param string $dest - * @return bool - */ - abstract function extractFile($path, $dest); - /** - * extract the archive - * @param string $dest - * @return bool - */ - abstract function extract($dest); - /** - * check if a file or folder exists in the archive - * @param string $path - * @return bool - */ - abstract function fileExists($path); - /** - * remove a file or folder from the archive - * @param string $path - * @return bool - */ - abstract function remove($path); - /** - * get a file handler - * @param string $path - * @param string $mode - * @return resource - */ - abstract function getStream($path, $mode); - /** - * add a folder and all its content - * @param string $path - * @param string $source - * @return boolean|null - */ - function addRecursive($path, $source) { - $dh = opendir($source); - if(is_resource($dh)) { - $this->addFolder($path); - while (($file = readdir($dh)) !== false) { - if($file=='.' or $file=='..') { - continue; - } - if(is_dir($source.'/'.$file)) { - $this->addRecursive($path.'/'.$file, $source.'/'.$file); - }else{ - $this->addFile($path.'/'.$file, $source.'/'.$file); - } - } - } - } -} -- cgit v1.2.3