diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-09-22 16:28:00 +0400 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-09-22 16:28:00 +0400 |
commit | 1a184af79dd7b76db46a2506797470e5c547039e (patch) | |
tree | 8f1d46cb65cbb43d156bd3106096b15c4b06a670 /files_archive | |
parent | 3b8f539837e9be3fd94c4897e366404e5304ac7d (diff) | |
parent | dc0f123b9f030e74f4210ff7d4892c8ee3659b28 (diff) |
merge master into filesystem
Diffstat (limited to 'files_archive')
-rw-r--r-- | files_archive/js/archive.js | 10 | ||||
-rw-r--r-- | files_archive/lib/storage.php | 83 | ||||
-rw-r--r-- | files_archive/tests/storage.php | 8 |
3 files changed, 55 insertions, 46 deletions
diff --git a/files_archive/js/archive.js b/files_archive/js/archive.js index b62d16f3f..bc9bb1139 100644 --- a/files_archive/js/archive.js +++ b/files_archive/js/archive.js @@ -14,6 +14,14 @@ $(document).ready(function() { FileActions.register('application/x-gzip','Open', OC.PERMISSION_READ, '',function(filename){ window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); - FileActions.setDefault('application/x-gzip','Open'); + FileActions.setDefault('application/x-compressed','Open'); + FileActions.register('application/x-compressed','Open', OC.PERMISSION_READ, '',function(filename){ + window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); + }); + FileActions.setDefault('application/x-compressed','Open'); + FileActions.register('application/x-tar','Open', OC.PERMISSION_READ, '',function(filename){ + window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); + }); + FileActions.setDefault('application/x-tar','Open'); } }); diff --git a/files_archive/lib/storage.php b/files_archive/lib/storage.php index 28fa3063f..108d85896 100644 --- a/files_archive/lib/storage.php +++ b/files_archive/lib/storage.php @@ -8,10 +8,10 @@ namespace OC\Files\Storage; -class Archive extends \OC\Files\Storage\Common{ +class Archive extends Common{ /** * underlying local storage used for missing functions - * @var OC_Archive + * @var \OC_Archive */ private $archive; private $path; @@ -19,38 +19,38 @@ class Archive extends \OC\Files\Storage\Common{ private static $enableAutomount=true; private static $rootView; - private function stripPath($path){//files should never start with / - if(!$path || $path[0]=='/'){ + private function stripPath($path) {//files should never start with / + if(!$path || $path[0]=='/') { $path=substr($path,1); } return $path; } - public function __construct($params){ + public function __construct($params) { $this->archive=\OC_Archive::open($params['archive']); $this->path=$params['archive']; } - public function mkdir($path){ + public function mkdir($path) { $path=$this->stripPath($path); return $this->archive->addFolder($path); } - public function rmdir($path){ + public function rmdir($path) { $path=$this->stripPath($path); return $this->archive->remove($path.'/'); } - public function opendir($path){ - if(substr($path,-1)!=='/'){ + public function opendir($path) { + if(substr($path,-1)!=='/') { $path.='/'; } $path=$this->stripPath($path); $files=$this->archive->getFolder($path); $content=array(); - foreach($files as $file){ - if(substr($file,-1)=='/'){ + foreach($files as $file) { + if(substr($file,-1)=='/') { $file=substr($file,0,-1); } - if($file and strpos($file,'/')===false){ + if($file and strpos($file,'/')===false) { $content[]=$file; } } @@ -58,21 +58,21 @@ class Archive extends \OC\Files\Storage\Common{ \OC_FakeDirStream::$dirs[$id]=$content; return opendir('fakedir://'.$id); } - public function stat($path){ + public function stat($path) { $ctime=-1; $path=$this->stripPath($path); - if($path==''){ + if($path=='') { $stat=stat($this->path); $stat['size']=0; }else{ - if($this->is_dir($path)){ + if($this->is_dir($path)) { $stat=array('size'=>0); $stat['mtime']=filemtime($this->path); }else{ $stat=array(); $stat['mtime']=$this->archive->mtime($path); $stat['size']=$this->archive->filesize($path); - if(!$stat['mtime']){ + if(!$stat['mtime']) { $stat['mtime']=time(); } } @@ -80,52 +80,53 @@ class Archive extends \OC\Files\Storage\Common{ $stat['ctime']=$ctime; return $stat; } - public function filetype($path){ + public function filetype($path) { $path=$this->stripPath($path); - if($path==''){ + if($path=='') { return 'dir'; } - if(substr($path,-1)=='/'){ + if(substr($path,-1)=='/') { return $this->archive->fileExists($path)?'dir':'file'; }else{ return $this->archive->fileExists($path.'/')?'dir':'file'; } } - public function isReadable($path){ + public function isReadable($path) { return is_readable($this->path); } - public function isUpdatable($path){ + public function isUpdatable($path) { return is_writable($this->path); } - public function file_exists($path){ + public function file_exists($path) { $path=$this->stripPath($path); - if($path==''){ + if($path=='') { return file_exists($this->path); } return $this->archive->fileExists($path); } - public function unlink($path){ + public function unlink($path) { $path=$this->stripPath($path); return $this->archive->remove($path); } - public function fopen($path,$mode){ + public function fopen($path,$mode) { $path=$this->stripPath($path); return $this->archive->getStream($path,$mode); } - public function free_space($path){ + public function free_space($path) { return 0; } - public function touch($path, $mtime=null){ - if(is_null($mtime)){ - $tmpFile=OCP\Files::tmpFile(); + public function touch($path, $mtime=null) { + if(is_null($mtime)) { + $tmpFile=\OCP\Files::tmpFile(); $this->archive->extractFile($path,$tmpFile); $this->archive->addfile($path,$tmpFile); }else{ return false;//not supported } } - private function toTmpFile($path){ - $tmpFile=\OC_Helper::tmpFile($extension); + + private function toTmpFile($path) { + $tmpFile=\OC_Helper::tmpFile(); $this->archive->extractFile($path,$tmpFile); return $tmpFile; } @@ -140,23 +141,23 @@ class Archive extends \OC\Files\Storage\Common{ /** * automount paths from file hooks - * @param aray params + * @param array params */ - public static function autoMount($params){ - if(!self::$enableAutomount){ + public static function autoMount($params) { + if(!self::$enableAutomount) { return; } $path=$params['path']; - if(!self::$rootView){ + if(!self::$rootView) { self::$rootView=new \OC_FilesystemView(''); } - self::$enableAutomount=false;//prevent recursion +// self::$enableAutomount=false;//prevent recursion $supported=array('zip','tar.gz','tar.bz2','tgz'); - foreach($supported as $type){ + foreach($supported as $type) { $ext='.'.$type.'/'; - if(($pos=strpos(strtolower($path),$ext))!==false){ + if(($pos=strpos(strtolower($path),$ext))!==false) { $archive=substr($path,0,$pos+strlen($ext)-1); - if(self::$rootView->file_exists($archive) and array_search($archive,self::$mounted)===false){ + if(self::$rootView->file_exists($archive) and array_search($archive,self::$mounted)===false) { $localArchive=self::$rootView->getLocalFile($archive); \OC_Filesystem::mount('\OC\Files\Storage\Archive',array('archive'=>$localArchive),$archive.'/'); self::$mounted[]=$archive; @@ -166,11 +167,11 @@ class Archive extends \OC\Files\Storage\Common{ self::$enableAutomount=true; } - public function rename($path1,$path2){ + public function rename($path1,$path2) { return $this->archive->rename($path1,$path2); } - public function hasUpdated($path,$time){ + public function hasUpdated($path,$time) { return $this->filemtime($this->path)>$time; } } diff --git a/files_archive/tests/storage.php b/files_archive/tests/storage.php index 94ac4ada4..a15fe0d63 100644 --- a/files_archive/tests/storage.php +++ b/files_archive/tests/storage.php @@ -12,12 +12,12 @@ class Test_Filestorage_Archive_Zip extends Test_FileStorage { */ private $tmpFile; - public function setUp(){ + public function setUp() { $this->tmpFile=OCP\Files::tmpFile('.zip'); $this->instance=new \OC\Files\Storage\Archive(array('archive'=>$this->tmpFile)); } - public function tearDown(){ + public function tearDown() { unlink($this->tmpFile); } } @@ -28,12 +28,12 @@ class Test_Filestorage_Archive_Tar extends Test_FileStorage { */ private $tmpFile; - public function setUp(){ + public function setUp() { $this->tmpFile=OCP\Files::tmpFile('.tar.gz'); $this->instance=new \OC\Files\Storage\Archive(array('archive'=>$this->tmpFile)); } - public function tearDown(){ + public function tearDown() { unlink($this->tmpFile); } } |