Respect coding style

This commit is contained in:
Thomas Müller 2012-09-10 12:21:54 +03:00
parent bd720bdf4c
commit f34588d1ff

View file

@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
require_once '3rdparty/Archive/Tar.php';
require_once 'Archive/Tar.php';
class OC_Archive_TAR extends OC_Archive{
const PLAIN=0;
@ -24,7 +24,7 @@ class OC_Archive_TAR extends OC_Archive{
function __construct($source) {
$types=array(null,'gz','bz');
$this->path=$source;
$this->tar=new Archive_Tar($source,$types[self::getTarType($source)]);
$this->tar=new Archive_Tar($source, $types[self::getTarType($source)]);
}
/**
@ -33,8 +33,8 @@ class OC_Archive_TAR extends OC_Archive{
* @return str
*/
static public function getTarType($file) {
if(strpos($file,'.')) {
$extension=substr($file,strrpos($file,'.'));
if(strpos($file, '.')) {
$extension=substr($file, strrpos($file, '.'));
switch($extension) {
case 'gz':
case 'tgz':
@ -57,13 +57,13 @@ class OC_Archive_TAR extends OC_Archive{
*/
function addFolder($path) {
$tmpBase=OC_Helper::tmpFolder();
if(substr($path,-1,1)!='/') {
if(substr($path, -1, 1)!='/') {
$path.='/';
}
if($this->fileExists($path)) {
return false;
}
$parts=explode('/',$path);
$parts=explode('/', $path);
$folder=$tmpBase;
foreach($parts as $part) {
$folder.='/'.$part;
@ -71,7 +71,7 @@ class OC_Archive_TAR extends OC_Archive{
mkdir($folder);
}
}
$result=$this->tar->addModify(array($tmpBase.$path),'',$tmpBase);
$result=$this->tar->addModify(array($tmpBase.$path), '', $tmpBase);
rmdir($tmpBase.$path);
$this->fileList=false;
return $result;
@ -90,9 +90,9 @@ class OC_Archive_TAR extends OC_Archive{
$header=array();
$dummy='';
$this->tar->_openAppend();
$result=$this->tar->_addfile($source,$header,$dummy,$dummy,$path);
$result=$this->tar->_addfile($source, $header, $dummy, $dummy, $path);
}else{
$result=$this->tar->addString($path,$source);
$result=$this->tar->addString($path, $source);
}
$this->fileList=false;
return $result;
@ -108,12 +108,12 @@ class OC_Archive_TAR extends OC_Archive{
//no proper way to delete, rename entire archive, rename file and remake archive
$tmp=OCP\Files::tmpFolder();
$this->tar->extract($tmp);
rename($tmp.$source,$tmp.$dest);
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->createModify(array($tmp),'',$tmp.'/');
$types=array(null, 'gz', 'bz');
$this->tar=new Archive_Tar($this->path, $types[self::getTarType($this->path)]);
$this->tar->createModify(array($tmp), '', $tmp.'/');
$this->fileList=false;
return true;
}
@ -158,14 +158,14 @@ class OC_Archive_TAR extends OC_Archive{
$pathLength=strlen($path);
foreach($files as $file) {
if($file[0]=='/') {
$file=substr($file,1);
$file=substr($file, 1);
}
if(substr($file,0,$pathLength)==$path and $file!=$path) {
$result=substr($file,$pathLength);
if($pos=strpos($result,'/')) {
$result=substr($result,0,$pos+1);
if(substr($file, 0, $pathLength)==$path and $file!=$path) {
$result=substr($file, $pathLength);
if($pos=strpos($result, '/')) {
$result=substr($result, 0, $pos+1);
}
if(array_search($result,$folderContent)===false) {
if(array_search($result, $folderContent)===false) {
$folderContent[]=$result;
}
}
@ -208,12 +208,12 @@ class OC_Archive_TAR extends OC_Archive{
return false;
}
if($this->fileExists('/'.$path)) {
$success=$this->tar->extractList(array('/'.$path),$tmp);
$success=$this->tar->extractList(array('/'.$path), $tmp);
}else{
$success=$this->tar->extractList(array($path),$tmp);
$success=$this->tar->extractList(array($path), $tmp);
}
if($success) {
rename($tmp.$path,$dest);
rename($tmp.$path, $dest);
}
OCP\Files::rmdirr($tmp);
return $success;
@ -234,16 +234,16 @@ class OC_Archive_TAR extends OC_Archive{
*/
function fileExists($path) {
$files=$this->getFiles();
if((array_search($path,$files)!==false) or (array_search($path.'/',$files)!==false)) {
if((array_search($path, $files)!==false) or (array_search($path.'/', $files)!==false)) {
return true;
}else{
$folderPath=$path;
if(substr($folderPath,-1,1)!='/') {
if(substr($folderPath, -1, 1)!='/') {
$folderPath.='/';
}
$pathLength=strlen($folderPath);
foreach($files as $file) {
if(strlen($file)>$pathLength and substr($file,0,$pathLength)==$folderPath) {
if(strlen($file)>$pathLength and substr($file, 0, $pathLength)==$folderPath) {
return true;
}
}
@ -272,7 +272,7 @@ class OC_Archive_TAR extends OC_Archive{
$this->tar=null;
unlink($this->path);
$this->reopen();
$this->tar->createModify(array($tmp),'',$tmp);
$this->tar->createModify(array($tmp), '', $tmp);
return true;
}
/**
@ -282,23 +282,23 @@ class OC_Archive_TAR extends OC_Archive{
* @return resource
*/
function getStream($path,$mode) {
if(strrpos($path,'.')!==false) {
$ext=substr($path,strrpos($path,'.'));
if(strrpos($path, '.')!==false) {
$ext=substr($path, strrpos($path, '.'));
}else{
$ext='';
}
$tmpFile=OCP\Files::tmpFile($ext);
if($this->fileExists($path)) {
$this->extractFile($path,$tmpFile);
$this->extractFile($path, $tmpFile);
}elseif($mode=='r' or $mode=='rb') {
return false;
}
if($mode=='r' or $mode=='rb') {
return fopen($tmpFile,$mode);
return fopen($tmpFile, $mode);
}else{
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile,$mode);
return fopen('close://'.$tmpFile, $mode);
}
}
@ -308,7 +308,7 @@ class OC_Archive_TAR extends OC_Archive{
*/
function writeBack($tmpFile) {
if(isset(self::$tempFiles[$tmpFile])) {
$this->addFile(self::$tempFiles[$tmpFile],$tmpFile);
$this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
unlink($tmpFile);
}
}
@ -322,6 +322,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)]);
}
}