diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index c50f6233a4..ca64f58e14 100755 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -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)); diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index 7a4ae33962..086a338db2 100755 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -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{ diff --git a/apps/files_archive/lib/tar.php b/apps/files_archive/lib/tar.php index 3a07a28906..2cb8dc2a8a 100755 --- a/apps/files_archive/lib/tar.php +++ b/apps/files_archive/lib/tar.php @@ -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'){ diff --git a/apps/files_archive/lib/zip.php b/apps/files_archive/lib/zip.php index 16f722a734..22ab48937e 100755 --- a/apps/files_archive/lib/zip.php +++ b/apps/files_archive/lib/zip.php @@ -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); diff --git a/apps/files_archive/tests/archive.php b/apps/files_archive/tests/archive.php index 512afe9e91..1779127c93 100755 --- a/apps/files_archive/tests/archive.php +++ b/apps/files_archive/tests/archive.php @@ -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'; diff --git a/apps/files_archive/tests/storage.php b/apps/files_archive/tests/storage.php index 52d6a4296e..7ebcce4ac6 100755 --- a/apps/files_archive/tests/storage.php +++ b/apps/files_archive/tests/storage.php @@ -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)); } diff --git a/apps/files_archive/tests/tar.php b/apps/files_archive/tests/tar.php index c543c226be..c138a51a65 100755 --- a/apps/files_archive/tests/tar.php +++ b/apps/files_archive/tests/tar.php @@ -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{ diff --git a/apps/files_archive/tests/zip.php b/apps/files_archive/tests/zip.php index b22ea3b79e..615c9e3c7e 100755 --- a/apps/files_archive/tests/zip.php +++ b/apps/files_archive/tests/zip.php @@ -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{ diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index cbe88adb5e..ba357f2350 100755 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -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; } diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php index 24b3bbcaf4..00466cc671 100755 --- a/apps/files_encryption/tests/encryption.php +++ b/apps/files_encryption/tests/encryption.php @@ -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); diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 225e82c99e..b23805d60b 100755 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -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]; diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index 1618a22ba8..981eeab58b 100755 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -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); diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 24a9d6c3d5..a133d35e73 100755 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -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); diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index aaba79d9b7..e3ba9c240c 100755 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -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{ diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 75e5f80d21..07c90d4878 100755 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -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); diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/ftp.php index d2d3622fa7..68481b4e66 100755 --- a/apps/files_external/tests/ftp.php +++ b/apps/files_external/tests/ftp.php @@ -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 index 0000000000..f2153f33b9 --- /dev/null +++ b/lib/public/files.php @@ -0,0 +1,114 @@ +. +* +*/ + +/** + * 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)); + } + + + + + + + + + + + + + + +} + +?> diff --git a/lib/public/util.php b/lib/public/util.php index 05be41a2a0..a65b9aa262 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -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)); - } - - - - - - - - - - - - }