summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-05-03 08:37:01 +0200
committerLukas Reschke <lukas@statuscode.ch>2016-05-03 08:37:01 +0200
commitadf7e7295ed94a04bd9fcb056b81e664b45b4f07 (patch)
treef95b0dcaa8c4f0954237bacbc01c81a7db2dc3aa
parenta72e6a2dac82c90582d478ead1f5518fc7299f80 (diff)
parentc96ed5c4ce27d4ab62cf483193d311fed1c37556 (diff)
downloadnextcloud-server-adf7e7295ed94a04bd9fcb056b81e664b45b4f07.tar.gz
nextcloud-server-adf7e7295ed94a04bd9fcb056b81e664b45b4f07.zip
Merge pull request #24375 from owncloud/archive_move
Move OC_Archive to \OC\Archive and PSR-4
-rw-r--r--lib/private/Archive/Archive.php (renamed from lib/private/legacy/archive.php)12
-rw-r--r--lib/private/Archive/TAR.php (renamed from lib/private/archive/tar.php)24
-rw-r--r--lib/private/Archive/ZIP.php (renamed from lib/private/archive/zip.php)14
-rw-r--r--lib/private/Installer.php2
-rw-r--r--tests/lib/archive/tar.php6
-rw-r--r--tests/lib/archive/zip.php6
6 files changed, 37 insertions, 27 deletions
diff --git a/lib/private/legacy/archive.php b/lib/private/Archive/Archive.php
index 62512d1448a..b5286968a2f 100644
--- a/lib/private/legacy/archive.php
+++ b/lib/private/Archive/Archive.php
@@ -28,23 +28,25 @@
*
*/
-abstract class OC_Archive{
+namespace OC\Archive;
+
+abstract class Archive{
/**
* Open any of the supported archive types
*
* @param string $path
- * @return OC_Archive|void
+ * @return Archive|void
*/
public static function open($path) {
$mime = \OC::$server->getMimeTypeDetector()->detect($path);
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);
}
}
diff --git a/lib/private/archive/tar.php b/lib/private/Archive/TAR.php
index 20e2e05f238..d783e53d40c 100644
--- a/lib/private/archive/tar.php
+++ b/lib/private/Archive/TAR.php
@@ -30,7 +30,9 @@
*
*/
-class OC_Archive_TAR extends OC_Archive {
+namespace OC\Archive;
+
+class TAR extends Archive {
const PLAIN = 0;
const GZIP = 1;
const BZIP = 2;
@@ -39,7 +41,7 @@ class OC_Archive_TAR extends OC_Archive {
private $cachedHeaders;
/**
- * @var Archive_Tar tar
+ * @var \Archive_Tar tar
*/
private $tar = null;
private $path;
@@ -50,7 +52,7 @@ class OC_Archive_TAR extends OC_Archive {
function __construct($source) {
$types = array(null, 'gz', 'bz2');
$this->path = $source;
- $this->tar = new Archive_Tar($source, $types[self::getTarType($source)]);
+ $this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]);
}
/**
@@ -137,13 +139,13 @@ class OC_Archive_TAR extends OC_Archive {
*/
function rename($source, $dest) {
//no proper way to delete, rename entire archive, rename file and remake archive
- $tmp = OCP\Files::tmpFolder();
+ $tmp = \OCP\Files::tmpFolder();
$this->tar->extract($tmp);
rename($tmp . $source, $tmp . $dest);
$this->tar = null;
unlink($this->path);
$types = array(null, 'gz', 'bz');
- $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]);
+ $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
$this->tar->createModify(array($tmp), '', $tmp . '/');
$this->fileList = false;
$this->cachedHeaders = false;
@@ -256,7 +258,7 @@ class OC_Archive_TAR extends OC_Archive {
* @return bool
*/
function extractFile($path, $dest) {
- $tmp = OCP\Files::tmpFolder();
+ $tmp = \OCP\Files::tmpFolder();
if (!$this->fileExists($path)) {
return false;
}
@@ -268,7 +270,7 @@ class OC_Archive_TAR extends OC_Archive {
if ($success) {
rename($tmp . $path, $dest);
}
- OCP\Files::rmdirr($tmp);
+ \OCP\Files::rmdirr($tmp);
return $success;
}
@@ -324,9 +326,9 @@ class OC_Archive_TAR extends OC_Archive {
$this->fileList = false;
$this->cachedHeaders = false;
//no proper way to delete, extract entire archive, delete file and remake archive
- $tmp = OCP\Files::tmpFolder();
+ $tmp = \OCP\Files::tmpFolder();
$this->tar->extract($tmp);
- OCP\Files::rmdirr($tmp . $path);
+ \OCP\Files::rmdirr($tmp . $path);
$this->tar = null;
unlink($this->path);
$this->reopen();
@@ -347,7 +349,7 @@ class OC_Archive_TAR extends OC_Archive {
} else {
$ext = '';
}
- $tmpFile = OCP\Files::tmpFile($ext);
+ $tmpFile = \OCP\Files::tmpFile($ext);
if ($this->fileExists($path)) {
$this->extractFile($path, $tmpFile);
} elseif ($mode == 'r' or $mode == 'rb') {
@@ -383,6 +385,6 @@ class OC_Archive_TAR extends OC_Archive {
$this->tar = null;
}
$types = array(null, 'gz', 'bz');
- $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]);
+ $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
}
}
diff --git a/lib/private/archive/zip.php b/lib/private/Archive/ZIP.php
index 0d8d3b7ce76..2bc17507d32 100644
--- a/lib/private/archive/zip.php
+++ b/lib/private/Archive/ZIP.php
@@ -27,9 +27,11 @@
*
*/
-class OC_Archive_ZIP extends OC_Archive{
+namespace OC\Archive;
+
+class ZIP extends Archive{
/**
- * @var ZipArchive zip
+ * @var \ZipArchive zip
*/
private $zip=null;
private $path;
@@ -39,10 +41,10 @@ class OC_Archive_ZIP extends OC_Archive{
*/
function __construct($source) {
$this->path=$source;
- $this->zip=new ZipArchive();
- if($this->zip->open($source, ZipArchive::CREATE)) {
+ $this->zip=new \ZipArchive();
+ if($this->zip->open($source, \ZipArchive::CREATE)) {
}else{
- OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, OCP\Util::WARN);
+ \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
}
}
/**
@@ -193,7 +195,7 @@ class OC_Archive_ZIP extends OC_Archive{
}else{
$ext='';
}
- $tmpFile=OCP\Files::tmpFile($ext);
+ $tmpFile=\OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if($this->fileExists($path)) {
$this->extractFile($path, $tmpFile);
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/tests/lib/archive/tar.php b/tests/lib/archive/tar.php
index 43157e2054d..2d20bb4c3b1 100644
--- a/tests/lib/archive/tar.php
+++ b/tests/lib/archive/tar.php
@@ -6,6 +6,8 @@
* See the COPYING-README file.
*/
+use OC\Archive\TAR;
+
class Test_Archive_TAR extends Test_Archive {
protected function setUp() {
parent::setUp();
@@ -17,10 +19,10 @@ class Test_Archive_TAR extends Test_Archive {
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
- return new OC_Archive_TAR($dir . '/data.tar.gz');
+ return new TAR($dir . '/data.tar.gz');
}
protected function getNew() {
- return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
+ return new TAR(OCP\Files::tmpFile('.tar.gz'));
}
}
diff --git a/tests/lib/archive/zip.php b/tests/lib/archive/zip.php
index 09ea5d7d27c..2f4c9cace1d 100644
--- a/tests/lib/archive/zip.php
+++ b/tests/lib/archive/zip.php
@@ -6,6 +6,8 @@
* See the COPYING-README file.
*/
+use OC\Archive\ZIP;
+
class Test_Archive_ZIP extends Test_Archive {
protected function setUp() {
parent::setUp();
@@ -17,10 +19,10 @@ class Test_Archive_ZIP extends Test_Archive {
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
- return new OC_Archive_ZIP($dir . '/data.zip');
+ return new ZIP($dir . '/data.zip');
}
protected function getNew() {
- return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
+ return new ZIP(OCP\Files::tmpFile('.zip'));
}
}