parent
05cf552f66
commit
0cb434686c
|
@ -30,7 +30,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_Archive_TAR extends OC_Archive {
|
namespace OC\Archive;
|
||||||
|
|
||||||
|
class TAR extends \OC_Archive {
|
||||||
const PLAIN = 0;
|
const PLAIN = 0;
|
||||||
const GZIP = 1;
|
const GZIP = 1;
|
||||||
const BZIP = 2;
|
const BZIP = 2;
|
||||||
|
@ -39,7 +41,7 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
private $cachedHeaders;
|
private $cachedHeaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Archive_Tar tar
|
* @var \Archive_Tar tar
|
||||||
*/
|
*/
|
||||||
private $tar = null;
|
private $tar = null;
|
||||||
private $path;
|
private $path;
|
||||||
|
@ -50,7 +52,7 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
function __construct($source) {
|
function __construct($source) {
|
||||||
$types = array(null, 'gz', 'bz2');
|
$types = array(null, 'gz', 'bz2');
|
||||||
$this->path = $source;
|
$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) {
|
function rename($source, $dest) {
|
||||||
//no proper way to delete, rename entire archive, rename file and remake archive
|
//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);
|
$this->tar->extract($tmp);
|
||||||
rename($tmp . $source, $tmp . $dest);
|
rename($tmp . $source, $tmp . $dest);
|
||||||
$this->tar = null;
|
$this->tar = null;
|
||||||
unlink($this->path);
|
unlink($this->path);
|
||||||
$types = array(null, 'gz', 'bz');
|
$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->tar->createModify(array($tmp), '', $tmp . '/');
|
||||||
$this->fileList = false;
|
$this->fileList = false;
|
||||||
$this->cachedHeaders = false;
|
$this->cachedHeaders = false;
|
||||||
|
@ -256,7 +258,7 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function extractFile($path, $dest) {
|
function extractFile($path, $dest) {
|
||||||
$tmp = OCP\Files::tmpFolder();
|
$tmp = \OCP\Files::tmpFolder();
|
||||||
if (!$this->fileExists($path)) {
|
if (!$this->fileExists($path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +270,7 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
if ($success) {
|
if ($success) {
|
||||||
rename($tmp . $path, $dest);
|
rename($tmp . $path, $dest);
|
||||||
}
|
}
|
||||||
OCP\Files::rmdirr($tmp);
|
\OCP\Files::rmdirr($tmp);
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,9 +326,9 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
$this->fileList = false;
|
$this->fileList = false;
|
||||||
$this->cachedHeaders = false;
|
$this->cachedHeaders = false;
|
||||||
//no proper way to delete, extract entire archive, delete file and remake archive
|
//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);
|
$this->tar->extract($tmp);
|
||||||
OCP\Files::rmdirr($tmp . $path);
|
\OCP\Files::rmdirr($tmp . $path);
|
||||||
$this->tar = null;
|
$this->tar = null;
|
||||||
unlink($this->path);
|
unlink($this->path);
|
||||||
$this->reopen();
|
$this->reopen();
|
||||||
|
@ -347,7 +349,7 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
} else {
|
} else {
|
||||||
$ext = '';
|
$ext = '';
|
||||||
}
|
}
|
||||||
$tmpFile = OCP\Files::tmpFile($ext);
|
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||||
if ($this->fileExists($path)) {
|
if ($this->fileExists($path)) {
|
||||||
$this->extractFile($path, $tmpFile);
|
$this->extractFile($path, $tmpFile);
|
||||||
} elseif ($mode == 'r' or $mode == 'rb') {
|
} elseif ($mode == 'r' or $mode == 'rb') {
|
||||||
|
@ -383,6 +385,6 @@ class OC_Archive_TAR extends OC_Archive {
|
||||||
$this->tar = null;
|
$this->tar = null;
|
||||||
}
|
}
|
||||||
$types = array(null, 'gz', 'bz');
|
$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)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,9 +27,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_Archive_ZIP extends OC_Archive{
|
namespace OC\Archive;
|
||||||
|
|
||||||
|
class ZIP extends \OC_Archive{
|
||||||
/**
|
/**
|
||||||
* @var ZipArchive zip
|
* @var \ZipArchive zip
|
||||||
*/
|
*/
|
||||||
private $zip=null;
|
private $zip=null;
|
||||||
private $path;
|
private $path;
|
||||||
|
@ -39,10 +41,10 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
*/
|
*/
|
||||||
function __construct($source) {
|
function __construct($source) {
|
||||||
$this->path=$source;
|
$this->path=$source;
|
||||||
$this->zip=new ZipArchive();
|
$this->zip=new \ZipArchive();
|
||||||
if($this->zip->open($source, ZipArchive::CREATE)) {
|
if($this->zip->open($source, \ZipArchive::CREATE)) {
|
||||||
}else{
|
}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{
|
}else{
|
||||||
$ext='';
|
$ext='';
|
||||||
}
|
}
|
||||||
$tmpFile=OCP\Files::tmpFile($ext);
|
$tmpFile=\OCP\Files::tmpFile($ext);
|
||||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||||
if($this->fileExists($path)) {
|
if($this->fileExists($path)) {
|
||||||
$this->extractFile($path, $tmpFile);
|
$this->extractFile($path, $tmpFile);
|
|
@ -28,6 +28,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use OC\Archive\TAR;
|
||||||
|
use OC\Archive\ZIP;
|
||||||
|
|
||||||
abstract class OC_Archive{
|
abstract class OC_Archive{
|
||||||
/**
|
/**
|
||||||
* Open any of the supported archive types
|
* Open any of the supported archive types
|
||||||
|
@ -40,11 +43,11 @@ abstract class OC_Archive{
|
||||||
|
|
||||||
switch($mime) {
|
switch($mime) {
|
||||||
case 'application/zip':
|
case 'application/zip':
|
||||||
return new OC_Archive_ZIP($path);
|
return new ZIP($path);
|
||||||
case 'application/x-gzip':
|
case 'application/x-gzip':
|
||||||
return new OC_Archive_TAR($path);
|
return new TAR($path);
|
||||||
case 'application/x-bzip2':
|
case 'application/x-bzip2':
|
||||||
return new OC_Archive_TAR($path);
|
return new TAR($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use OC\Archive\TAR;
|
||||||
|
|
||||||
class Test_Archive_TAR extends Test_Archive {
|
class Test_Archive_TAR extends Test_Archive {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -17,10 +19,10 @@ class Test_Archive_TAR extends Test_Archive {
|
||||||
|
|
||||||
protected function getExisting() {
|
protected function getExisting() {
|
||||||
$dir = OC::$SERVERROOT . '/tests/data';
|
$dir = OC::$SERVERROOT . '/tests/data';
|
||||||
return new OC_Archive_TAR($dir . '/data.tar.gz');
|
return new TAR($dir . '/data.tar.gz');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getNew() {
|
protected function getNew() {
|
||||||
return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
|
return new TAR(OCP\Files::tmpFile('.tar.gz'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use OC\Archive\ZIP;
|
||||||
|
|
||||||
class Test_Archive_ZIP extends Test_Archive {
|
class Test_Archive_ZIP extends Test_Archive {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -17,10 +19,10 @@ class Test_Archive_ZIP extends Test_Archive {
|
||||||
|
|
||||||
protected function getExisting() {
|
protected function getExisting() {
|
||||||
$dir = OC::$SERVERROOT . '/tests/data';
|
$dir = OC::$SERVERROOT . '/tests/data';
|
||||||
return new OC_Archive_ZIP($dir . '/data.zip');
|
return new ZIP($dir . '/data.zip');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getNew() {
|
protected function getNew() {
|
||||||
return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
|
return new ZIP(OCP\Files::tmpFile('.zip'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue