Respect coding style
This commit is contained in:
parent
f34588d1ff
commit
87e1a27fde
|
@ -16,9 +16,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -37,9 +37,9 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
*/
|
*/
|
||||||
function addFile($path,$source='') {
|
function addFile($path,$source='') {
|
||||||
if($source and $source[0]=='/' and file_exists($source)) {
|
if($source and $source[0]=='/' and file_exists($source)) {
|
||||||
$result=$this->zip->addFile($source,$path);
|
$result=$this->zip->addFile($source, $path);
|
||||||
}else{
|
}else{
|
||||||
$result=$this->zip->addFromString($path,$source);
|
$result=$this->zip->addFromString($path, $source);
|
||||||
}
|
}
|
||||||
if($result) {
|
if($result) {
|
||||||
$this->zip->close();//close and reopen to save the zip
|
$this->zip->close();//close and reopen to save the zip
|
||||||
|
@ -56,7 +56,7 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
function rename($source,$dest) {
|
function rename($source,$dest) {
|
||||||
$source=$this->stripPath($source);
|
$source=$this->stripPath($source);
|
||||||
$dest=$this->stripPath($dest);
|
$dest=$this->stripPath($dest);
|
||||||
$this->zip->renameName($source,$dest);
|
$this->zip->renameName($source, $dest);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* get the uncompressed size of a file in the archive
|
* get the uncompressed size of a file in the archive
|
||||||
|
@ -85,9 +85,9 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
$folderContent=array();
|
$folderContent=array();
|
||||||
$pathLength=strlen($path);
|
$pathLength=strlen($path);
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
if(substr($file,0,$pathLength)==$path and $file!=$path) {
|
if(substr($file, 0, $pathLength)==$path and $file!=$path) {
|
||||||
if(strrpos(substr($file,0,-1),'/')<=$pathLength) {
|
if(strrpos(substr($file, 0, -1),'/')<=$pathLength) {
|
||||||
$folderContent[]=substr($file,$pathLength);
|
$folderContent[]=substr($file, $pathLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
*/
|
*/
|
||||||
function extractFile($path,$dest) {
|
function extractFile($path,$dest) {
|
||||||
$fp = $this->zip->getStream($path);
|
$fp = $this->zip->getStream($path);
|
||||||
file_put_contents($dest,$fp);
|
file_put_contents($dest, $fp);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* extract the archive
|
* extract the archive
|
||||||
|
@ -162,18 +162,18 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
if($mode=='r' or $mode=='rb') {
|
if($mode=='r' or $mode=='rb') {
|
||||||
return $this->zip->getStream($path);
|
return $this->zip->getStream($path);
|
||||||
}else{//since we cant directly get a writable stream, make a temp copy of the file and put it back in the archive when the stream is closed
|
}else{//since we cant directly get a writable stream, make a temp copy of the file and put it back in the archive when the stream is closed
|
||||||
if(strrpos($path,'.')!==false) {
|
if(strrpos($path, '.')!==false) {
|
||||||
$ext=substr($path,strrpos($path,'.'));
|
$ext=substr($path, strrpos($path, '.'));
|
||||||
}else{
|
}else{
|
||||||
$ext='';
|
$ext='';
|
||||||
}
|
}
|
||||||
$tmpFile=OCP\Files::tmpFile($ext);
|
$tmpFile=OCP\Files::tmpFile($ext);
|
||||||
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
|
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
|
||||||
if($this->fileExists($path)) {
|
if($this->fileExists($path)) {
|
||||||
$this->extractFile($path,$tmpFile);
|
$this->extractFile($path, $tmpFile);
|
||||||
}
|
}
|
||||||
self::$tempFiles[$tmpFile]=$path;
|
self::$tempFiles[$tmpFile]=$path;
|
||||||
return fopen('close://'.$tmpFile,$mode);
|
return fopen('close://'.$tmpFile, $mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,14 +183,14 @@ class OC_Archive_ZIP extends OC_Archive{
|
||||||
*/
|
*/
|
||||||
function writeBack($tmpFile) {
|
function writeBack($tmpFile) {
|
||||||
if(isset(self::$tempFiles[$tmpFile])) {
|
if(isset(self::$tempFiles[$tmpFile])) {
|
||||||
$this->addFile(self::$tempFiles[$tmpFile],$tmpFile);
|
$this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
|
||||||
unlink($tmpFile);
|
unlink($tmpFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function stripPath($path) {
|
private function stripPath($path) {
|
||||||
if(!$path || $path[0]=='/') {
|
if(!$path || $path[0]=='/') {
|
||||||
return substr($path,1);
|
return substr($path, 1);
|
||||||
}else{
|
}else{
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue