From 00b34a09eaeba2f74a44a155f0fdd4aa58d5e502 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 5 Oct 2012 12:29:27 +0200 Subject: cache tar archive headers --- lib/archive/tar.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/archive/tar.php') diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 639d2392b63..21d8057e4d6 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -14,6 +14,7 @@ class OC_Archive_TAR extends OC_Archive{ const BZIP=2; private $fileList; + private $cachedHeaders; /** * @var Archive_Tar tar @@ -74,6 +75,7 @@ class OC_Archive_TAR extends OC_Archive{ $result=$this->tar->addModify(array($tmpBase.$path), '', $tmpBase); rmdir($tmpBase.$path); $this->fileList=false; + $this->cachedHeaders=false; return $result; } /** @@ -95,6 +97,7 @@ class OC_Archive_TAR extends OC_Archive{ $result=$this->tar->addString($path, $source); } $this->fileList=false; + $this->cachedHeaders=false; return $result; } @@ -115,12 +118,15 @@ class OC_Archive_TAR extends OC_Archive{ $this->tar=new Archive_Tar($this->path, $types[self::getTarType($this->path)]); $this->tar->createModify(array($tmp), '', $tmp.'/'); $this->fileList=false; + $this->cachedHeaders=false; return true; } private function getHeader($file) { - $headers=$this->tar->listContent(); - foreach($headers as $header) { + if ( ! $this->cachedHeaders ) { + $this->cachedHeaders = $this->tar->listContent(); + } + foreach($this->cachedHeaders as $header) { if($file==$header['filename'] or $file.'/'==$header['filename'] or '/'.$file.'/'==$header['filename'] or '/'.$file==$header['filename']) { return $header; } @@ -180,9 +186,11 @@ class OC_Archive_TAR extends OC_Archive{ if($this->fileList) { return $this->fileList; } - $headers=$this->tar->listContent(); + if ( ! $this->cachedHeaders ) { + $this->cachedHeaders = $this->tar->listContent(); + } $files=array(); - foreach($headers as $header) { + foreach($this->cachedHeaders as $header) { $files[]=$header['filename']; } $this->fileList=$files; @@ -265,6 +273,7 @@ class OC_Archive_TAR extends OC_Archive{ return false; } $this->fileList=false; + $this->cachedHeaders=false; //no proper way to delete, extract entire archive, delete file and remake archive $tmp=OCP\Files::tmpFolder(); $this->tar->extract($tmp); -- cgit v1.2.3 From b5f11195af171edfbbc4fae2e1b7f4832f777f68 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 5 Oct 2012 12:39:43 +0200 Subject: fix checkstyle on archive zip/tar --- lib/archive.php | 8 ++++---- lib/archive/tar.php | 5 ++++- lib/archive/zip.php | 7 +++++-- 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/archive/tar.php') diff --git a/lib/archive.php b/lib/archive.php index b4459c2b6ce..a9c245eaf43 100644 --- a/lib/archive.php +++ b/lib/archive.php @@ -13,14 +13,14 @@ abstract class OC_Archive{ * @return OC_Archive */ public static function open($path) { - $ext=substr($path,strrpos($path,'.')); + $ext=substr($path, strrpos($path, '.')); switch($ext) { case '.zip': return new OC_Archive_ZIP($path); case '.gz': case '.bz': case '.bz2': - if(strpos($path,'.tar.')) { + if(strpos($path, '.tar.')) { return new OC_Archive_TAR($path); } break; @@ -126,9 +126,9 @@ abstract class OC_Archive{ continue; } if(is_dir($source.'/'.$file)) { - $this->addRecursive($path.'/'.$file,$source.'/'.$file); + $this->addRecursive($path.'/'.$file, $source.'/'.$file); }else{ - $this->addFile($path.'/'.$file,$source.'/'.$file); + $this->addFile($path.'/'.$file, $source.'/'.$file); } } } diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 21d8057e4d6..9aaa6d12796 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -127,7 +127,10 @@ class OC_Archive_TAR extends OC_Archive{ $this->cachedHeaders = $this->tar->listContent(); } foreach($this->cachedHeaders as $header) { - if($file==$header['filename'] or $file.'/'==$header['filename'] or '/'.$file.'/'==$header['filename'] or '/'.$file==$header['filename']) { + if( $file == $header['filename'] + or $file.'/' == $header['filename'] + or '/'.$file.'/' == $header['filename'] + or '/'.$file == $header['filename']) { return $header; } } diff --git a/lib/archive/zip.php b/lib/archive/zip.php index a2b07f1a35d..d016c692e35 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -86,7 +86,7 @@ class OC_Archive_ZIP extends OC_Archive{ $pathLength=strlen($path); foreach($files as $file) { 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); } } @@ -161,7 +161,10 @@ class OC_Archive_ZIP extends OC_Archive{ function getStream($path,$mode) { if($mode=='r' or $mode=='rb') { 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) { $ext=substr($path, strrpos($path, '.')); }else{ -- cgit v1.2.3 From ee6d96b7a8a7d179a66e49e0606ff024fdf105db Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 5 Oct 2012 12:54:18 +0200 Subject: really fix checkstyle on archive tar --- lib/archive/tar.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/archive/tar.php') diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 9aaa6d12796..7a47802bc34 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -130,7 +130,8 @@ class OC_Archive_TAR extends OC_Archive{ if( $file == $header['filename'] or $file.'/' == $header['filename'] or '/'.$file.'/' == $header['filename'] - or '/'.$file == $header['filename']) { + or '/'.$file == $header['filename']) + { return $header; } } -- cgit v1.2.3 From 77fbdb2ca8e31b9d930933a7d204a803d58ddf0a Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Sat, 13 Oct 2012 01:10:04 +0200 Subject: Fix the require path --- lib/archive/tar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/archive/tar.php') diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 7a47802bc34..86d39b88968 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -require_once 'Archive/Tar.php'; +require_once '3rdparty/Archive/Tar.php'; class OC_Archive_TAR extends OC_Archive{ const PLAIN=0; -- cgit v1.2.3