]> source.dussan.org Git - nextcloud-server.git/commitdiff
move all the files stuff into a files class
authorFrank Karlitschek <frank@owncloud.org>
Wed, 2 May 2012 10:54:31 +0000 (12:54 +0200)
committerFrank Karlitschek <frank@owncloud.org>
Wed, 2 May 2012 10:54:31 +0000 (12:54 +0200)
18 files changed:
apps/files/ajax/upload.php
apps/files_archive/lib/storage.php
apps/files_archive/lib/tar.php
apps/files_archive/lib/zip.php
apps/files_archive/tests/archive.php
apps/files_archive/tests/storage.php
apps/files_archive/tests/tar.php
apps/files_archive/tests/zip.php
apps/files_encryption/lib/proxy.php
apps/files_encryption/tests/encryption.php
apps/files_encryption/tests/stream.php
apps/files_external/lib/ftp.php
apps/files_external/lib/google.php
apps/files_external/lib/swift.php
apps/files_external/lib/webdav.php
apps/files_external/tests/ftp.php
lib/public/files.php [new file with mode: 0644]
lib/public/util.php

index c50f6233a466c699d528e4e879451626f4e6ca5f..ca64f58e14b5de95198a79f8e5b5d2a2a02b6cd9 100755 (executable)
@@ -46,7 +46,7 @@ $result=array();
 if(strpos($dir,'..') === false){
        $fileCount=count($files['name']);
        for($i=0;$i<$fileCount;$i++){
-        $target = OCP\Util::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
+        $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
                if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i],$target)){
                        $meta=OC_FileCache::getCached($target);
                        $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'],'name'=>basename($target));
index 7a4ae339621745cab5d2f4ed41e9d744052d4062..086a338db25f26543b4300133d75d67461ad6709 100755 (executable)
@@ -104,7 +104,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
        }
        public function touch($path, $mtime=null){
                if(is_null($mtime)){
-                       $tmpFile=OCP\Util::tmpFile();
+                       $tmpFile=OCP\Files::tmpFile();
                        $this->archive->extractFile($path,$tmpFile);
                        $this->archive->addfile($path,$tmpFile);
                }else{
index 3a07a28906c00fcecfbb987cb3475d84d1d66047..2cb8dc2a8aee858274c506e3dd5605be19077b66 100755 (executable)
@@ -93,7 +93,7 @@ class OC_Archive_TAR extends OC_Archive{
         */
        function rename($source,$dest){
                //no proper way to delete, rename entire archive, rename file and remake archive
-               $tmp=OCP\Util::tmpFolder();
+               $tmp=OCP\Files::tmpFolder();
                $this->tar->extract($tmp);
                rename($tmp.$source,$tmp.$dest);
                $this->tar=null;
@@ -177,7 +177,7 @@ class OC_Archive_TAR extends OC_Archive{
         * @return bool
         */
        function extractFile($path,$dest){
-               $tmp=OCP\Util::tmpFolder();
+               $tmp=OCP\Files::tmpFolder();
                if(!$this->fileExists($path)){
                        return false;
                }
@@ -185,7 +185,7 @@ class OC_Archive_TAR extends OC_Archive{
                if($success){
                        rename($tmp.$path,$dest);
                }
-               OCP\Util::rmdirr($tmp);
+               OCP\Files::rmdirr($tmp);
                return $success;
        }
        /**
@@ -216,9 +216,9 @@ class OC_Archive_TAR extends OC_Archive{
                        return false;
                }
                //no proper way to delete, extract entire archive, delete file and remake archive
-               $tmp=OCP\Util::tmpFolder();
+               $tmp=OCP\Files::tmpFolder();
                $this->tar->extract($tmp);
-               OCP\Util::rmdirr($tmp.$path);
+               OCP\Files::rmdirr($tmp.$path);
                $this->tar=null;
                unlink($this->path);
                $this->reopen();
@@ -237,7 +237,7 @@ class OC_Archive_TAR extends OC_Archive{
                }else{
                        $ext='';
                }
-               $tmpFile=OCP\Util::tmpFile($ext);
+               $tmpFile=OCP\Files::tmpFile($ext);
                if($this->fileExists($path)){
                        $this->extractFile($path,$tmpFile);
                }elseif($mode=='r' or $mode=='rb'){
index 16f722a734e476d4243521d5104ec8de738a1547..22ab48937ebadaa9fb87e13e1a516d0c019aa4bb 100755 (executable)
@@ -169,7 +169,7 @@ class OC_Archive_ZIP extends OC_Archive{
                        }else{
                                $ext='';
                        }
-                       $tmpFile=OCP\Util::tmpFile($ext);
+                       $tmpFile=OCP\Files::tmpFile($ext);
                        OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
                        if($this->fileExists($path)){
                                $this->extractFile($path,$tmpFile);
index 512afe9e915607e788ebd8bea2bef42d444695a4..1779127c932bb909bd4e794931105da824c4cdd2 100755 (executable)
@@ -55,7 +55,7 @@ abstract class Test_Archive extends UnitTestCase {
                $textFile=$dir.'/lorem.txt';
                $this->assertEqual(file_get_contents($textFile),$this->instance->getFile('lorem.txt'));
                
-               $tmpFile=OCP\Util::tmpFile('.txt');
+               $tmpFile=OCP\Files::tmpFile('.txt');
                $this->instance->extractFile('lorem.txt',$tmpFile);
                $this->assertEqual(file_get_contents($textFile),file_get_contents($tmpFile));
        }
@@ -89,7 +89,7 @@ abstract class Test_Archive extends UnitTestCase {
                $this->instance=$this->getNew();
                $fh=$this->instance->getStream('lorem.txt','w');
                $source=fopen($dir.'/lorem.txt','r');
-               OCP\Util::streamCopy($source,$fh);
+               OCP\Files::streamCopy($source,$fh);
                fclose($source);
                fclose($fh);
                $this->assertTrue($this->instance->fileExists('lorem.txt'));
@@ -109,13 +109,13 @@ abstract class Test_Archive extends UnitTestCase {
        public function testExtract(){
                $dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
                $this->instance=$this->getExisting();
-               $tmpDir=OCP\Util::tmpFolder();
+               $tmpDir=OCP\Files::tmpFolder();
                $this->instance->extract($tmpDir);
                $this->assertEqual(true,file_exists($tmpDir.'lorem.txt'));
                $this->assertEqual(true,file_exists($tmpDir.'dir/lorem.txt'));
                $this->assertEqual(true,file_exists($tmpDir.'logo-wide.png'));
                $this->assertEqual(file_get_contents($dir.'/lorem.txt'),file_get_contents($tmpDir.'lorem.txt'));
-               OCP\Util::rmdirr($tmpDir);
+               OCP\Files::rmdirr($tmpDir);
        }
        public function testMoveRemove(){
                $dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
index 52d6a4296e9c393c600f581a3dbc10e3fafd6c53..7ebcce4ac6fdc1f6c723588fc78f92e0c29b4127 100755 (executable)
@@ -13,7 +13,7 @@ class Test_Filestorage_Archive_Zip extends Test_FileStorage {
        private $tmpFile;
        
        public function setUp(){
-               $this->tmpFile=OCP\Util::tmpFile('.zip');
+               $this->tmpFile=OCP\Files::tmpFile('.zip');
                $this->instance=new OC_Filestorage_Archive(array('archive'=>$this->tmpFile));
        }
 
index c543c226bef998937df7451bc1055a350df78338..c138a51a6518829b38a934757c8107ada73f089b 100755 (executable)
@@ -16,7 +16,7 @@ if(is_dir(OC::$SERVERROOT.'/apps/files_archive/tests/data')){
                }
 
                protected function getNew(){
-                       return new OC_Archive_TAR(OCP\Util::tmpFile('.tar.gz'));
+                       return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
                }
        }
 }else{
index b22ea3b79e9ce119f618255ba0fddd4c0d2aee8d..615c9e3c7e23cb8ce184f6c3085eff0bc0093334 100755 (executable)
@@ -16,7 +16,7 @@ if(is_dir(OC::$SERVERROOT.'/apps/files_archive/tests/data')){
                }
 
                protected function getNew(){
-                       return new OC_Archive_ZIP(OCP\Util::tmpFile('.zip'));
+                       return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
                }
        }
 }else{
index cbe88adb5e47a4aafacd368b17fc281c9e22500b..ba357f235026827b923bea571b34a793bde0ccac 100755 (executable)
@@ -92,7 +92,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
                                //first encrypt the target file so we don't end up with a half encrypted file
                                OCP\Util::writeLog('files_encryption','Decrypting '.$path.' before writing',OCP\Util::DEBUG);
                                $tmp=fopen('php://temp');
-                               OCP\Util::streamCopy($result,$tmp);
+                               OCP\Files::streamCopy($result,$tmp);
                                fclose($result);
                                OC_Filesystem::file_put_contents($path,$tmp);
                                fclose($tmp);
@@ -104,7 +104,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
 
        public function postGetMimeType($path,$mime){
                if(self::isEncrypted($path)){
-                       $mime=OCP\Util::getMimeType('crypt://'.$path,'w');
+                       $mime=OCP\Files::getMimeType('crypt://'.$path,'w');
                }
                return $mime;
        }
index 24b3bbcaf40ff6e8a04a7b62d1badd06b4d73b3c..00466cc671c1b041f9a162959672e5330810deb7 100755 (executable)
@@ -27,14 +27,14 @@ class Test_Encryption extends UnitTestCase {
                $this->assertNotEqual($encrypted,$source);
                $this->assertEqual($decrypted,$source);
 
-               $tmpFileEncrypted=OCP\Util::tmpFile();
+               $tmpFileEncrypted=OCP\Files::tmpFile();
                OC_Crypt::encryptfile($file,$tmpFileEncrypted,$key);
                $encrypted=file_get_contents($tmpFileEncrypted);
                $decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
                $this->assertNotEqual($encrypted,$source);
                $this->assertEqual($decrypted,$source);
 
-               $tmpFileDecrypted=OCP\Util::tmpFile();
+               $tmpFileDecrypted=OCP\Files::tmpFile();
                OC_Crypt::decryptfile($tmpFileEncrypted,$tmpFileDecrypted,$key);
                $decrypted=file_get_contents($tmpFileDecrypted);
                $this->assertEqual($decrypted,$source);
index 225e82c99e83d7ef48d18a88a59a491e3fde6240..b23805d60b00374e94583a94a6756ce02bc652e3 100755 (executable)
@@ -22,7 +22,7 @@ class Test_CryptStream extends UnitTestCase {
                $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
                $source=fopen($file,'r');
                $target=$this->getStream('test2','w');
-               OCP\Util::streamCopy($source,$target);
+               OCP\Files::streamCopy($source,$target);
                fclose($target);
                fclose($source);
 
@@ -44,7 +44,7 @@ class Test_CryptStream extends UnitTestCase {
                        $id=uniqid();
                }
                if(!isset($this->tmpFiles[$id])){
-                       $file=OCP\Util::tmpFile();
+                       $file=OCP\Files::tmpFile();
                        $this->tmpFiles[$id]=$file;
                }else{
                        $file=$this->tmpFiles[$id];
index 1618a22ba8a4dd98430ae911214a5d373ade1cb2..981eeab58bf3b1cad0e2e785bfcb51700f739fb9 100755 (executable)
@@ -108,7 +108,7 @@ class OC_FileStorage_FTP extends OC_Filestorage_Common{
                                }else{
                                        $ext='';
                                }
-                               $tmpFile=OCP\Util::tmpFile($ext);
+                               $tmpFile=OCP\Files::tmpFile($ext);
                                OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
                                if($this->file_exists($path)){
                                        $this->getFile($path,$tmpFile);
index 24a9d6c3d528c52283a972bee4d71d5237ccc8c6..a133d35e737ded5e29009a35687f606b7bc1a043 100755 (executable)
@@ -84,7 +84,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
                                curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
                }
                if ($isDownload) {
-                       $tmpFile = OCP\Util::tmpFile();
+                       $tmpFile = OCP\Files::tmpFile();
                        $fp = fopen($tmpFile, 'w');
                        curl_setopt($curl, CURLOPT_FILE, $fp);
                        curl_exec($curl);
index aaba79d9b7bf1c4e7dc339221960d15277cb2e7f..e3ba9c240cf7e511ef2b6221f326e9e6ff366a0e 100755 (executable)
@@ -164,7 +164,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
         * @return array
         */
        private function getSubContainers($container){
-               $tmpFile=OCP\Util::tmpFile();
+               $tmpFile=OCP\Files::tmpFile();
                $obj=$this->getSubContainerFile($container);
                try{
                        $obj->save_to_filename($tmpFile);
@@ -190,7 +190,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                if(!$name){
                        return false;
                }
-               $tmpFile=OCP\Util::tmpFile();
+               $tmpFile=OCP\Files::tmpFile();
                $obj=$this->getSubContainerFile($container);
                try{
                        $obj->save_to_filename($tmpFile);
@@ -225,7 +225,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                if(!$name){
                        return false;
                }
-               $tmpFile=OCP\Util::tmpFile();
+               $tmpFile=OCP\Files::tmpFile();
                $obj=$this->getSubContainerFile($container);
                try{
                        $obj->save_to_filename($tmpFile);
@@ -501,7 +501,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
        private function getTmpFile($path){
                $obj=$this->getObject($path);
                if(!is_null($obj)){
-                       $tmpFile=OCP\Util::tmpFile();
+                       $tmpFile=OCP\Files::tmpFile();
                        $obj->save_to_filename($tmpFile);
                        return $tmpFile;
                }else{
index 75e5f80d2178093c0252fa4cd3c58be4c8f43cc2..07c90d4878e94b208b3abd1f4c610ba25195f19a 100755 (executable)
@@ -150,7 +150,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
                                }else{
                                        $ext='';
                                }
-                               $tmpFile=OCP\Util::tmpFile($ext);
+                               $tmpFile=OCP\Files::tmpFile($ext);
                                OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
                                if($this->file_exists($path)){
                                        $this->getFile($path,$tmpFile);
index d2d3622fa78e2e7092792c1bf3d8d2e7afd8d627..68481b4e66bcca947862b2348ce510ed5647af70 100755 (executable)
@@ -23,7 +23,7 @@ if(!is_array($config) or !isset($config['ftp']) or !$config['ftp']['run']){
                }
 
                public function tearDown(){
-                       OCP\Util::rmdirr($this->instance->constructUrl(''));
+                       OCP\Files::rmdirr($this->instance->constructUrl(''));
                }
        }
 }
diff --git a/lib/public/files.php b/lib/public/files.php
new file mode 100644 (file)
index 0000000..f2153f3
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+/**
+* ownCloud
+*
+* @author Frank Karlitschek
+* @copyright 2010 Frank Karlitschek karlitschek@kde.org
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Files Class
+ *
+ */
+
+// use OCP namespace for all classes that are considered public. 
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class Files {
+
+
+       /**
+        * @brief Recusive deletion of folders
+        * @param string $dir path to the folder
+        *
+        */
+       static function rmdirr($dir) {
+               \OC_Helper::rmdirr( $dir );
+       }
+
+
+       /**
+        * get the mimetype form a local file
+        * @param string path
+        * @return string
+        * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
+        */
+       static function getMimeType($path){
+               return(\OC_Helper::getMimeType( $path ));
+       }
+
+       /**
+        * copy the contents of one stream to another
+        * @param resource source
+        * @param resource target
+        * @return int the number of bytes copied
+        */
+       public static function streamCopy($source,$target){
+               return(\OC_Helper::streamCopy($source,$target));
+       }
+
+
+       /**
+        * create a temporary file with an unique filename
+        * @param string postfix
+        * @return string
+        *
+        * temporary files are automatically cleaned up after the script is finished
+        */
+       public static function tmpFile($postfix=''){
+               return(\OC_Helper::tmpFile($postfix));
+       }
+
+       /**
+        * create a temporary folder with an unique filename
+        * @return string
+        *
+        * temporary files are automatically cleaned up after the script is finished
+        */
+       public static function tmpFolder(){
+               return(\OC_Helper::tmpFolder());
+       }
+
+       /**
+        * Adds a suffix to the name in case the file exists
+        *
+        * @param $path
+        * @param $filename
+        * @return string
+        */
+       public static function buildNotExistingFileName($path, $filename){
+               return(\OC_Helper::buildNotExistingFileName($path, $filename));
+       }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+?>
index 05be41a2a058b271c171322f0045720714b904c3..a65b9aa262723fa41baa6518ad4b691313643426 100644 (file)
@@ -193,80 +193,6 @@ class Util {
 
 
 
-       /**
-        * @brief Recusive deletion of folders
-        * @param string $dir path to the folder
-        *
-        */
-       static function rmdirr($dir) {
-               \OC_Helper::rmdirr( $dir );
-       }
-
-
-       /**
-        * get the mimetype form a local file
-        * @param string path
-        * @return string
-        * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
-        */
-       static function getMimeType($path){
-               return(\OC_Helper::getMimeType( $path ));
-       }
-
-       /**
-        * copy the contents of one stream to another
-        * @param resource source
-        * @param resource target
-        * @return int the number of bytes copied
-        */
-       public static function streamCopy($source,$target){
-               return(\OC_Helper::streamCopy($source,$target));
-       }
-
-
-       /**
-        * create a temporary file with an unique filename
-        * @param string postfix
-        * @return string
-        *
-        * temporary files are automatically cleaned up after the script is finished
-        */
-       public static function tmpFile($postfix=''){
-               return(\OC_Helper::tmpFile($postfix));
-       }
-
-       /**
-        * create a temporary folder with an unique filename
-        * @return string
-        *
-        * temporary files are automatically cleaned up after the script is finished
-        */
-       public static function tmpFolder(){
-               return(\OC_Helper::tmpFolder());
-       }
-
-       /**
-        * Adds a suffix to the name in case the file exists
-        *
-        * @param $path
-        * @param $filename
-        * @return string
-        */
-       public static function buildNotExistingFileName($path, $filename){
-               return(\OC_Helper::buildNotExistingFileName($path, $filename));
-       }
-
-
-
-
-
-
-
-
-
-
-
-
 
 
 }