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));
}
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{
*/
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;
* @return bool
*/
function extractFile($path,$dest){
- $tmp=OCP\Util::tmpFolder();
+ $tmp=OCP\Files::tmpFolder();
if(!$this->fileExists($path)){
return false;
}
if($success){
rename($tmp.$path,$dest);
}
- OCP\Util::rmdirr($tmp);
+ OCP\Files::rmdirr($tmp);
return $success;
}
/**
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();
}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'){
}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);
$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));
}
$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'));
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';
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));
}
}
protected function getNew(){
- return new OC_Archive_TAR(OCP\Util::tmpFile('.tar.gz'));
+ return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
}
}
}else{
}
protected function getNew(){
- return new OC_Archive_ZIP(OCP\Util::tmpFile('.zip'));
+ return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
}
}
}else{
//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);
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;
}
$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);
$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);
$id=uniqid();
}
if(!isset($this->tmpFiles[$id])){
- $file=OCP\Util::tmpFile();
+ $file=OCP\Files::tmpFile();
$this->tmpFiles[$id]=$file;
}else{
$file=$this->tmpFiles[$id];
}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);
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);
* @return array
*/
private function getSubContainers($container){
- $tmpFile=OCP\Util::tmpFile();
+ $tmpFile=OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
if(!$name){
return false;
}
- $tmpFile=OCP\Util::tmpFile();
+ $tmpFile=OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
if(!$name){
return false;
}
- $tmpFile=OCP\Util::tmpFile();
+ $tmpFile=OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
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{
}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);
}
public function tearDown(){
- OCP\Util::rmdirr($this->instance->constructUrl(''));
+ OCP\Files::rmdirr($this->instance->constructUrl(''));
}
}
}
--- /dev/null
+<?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));
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+?>
- /**
- * @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));
- }
-
-
-
-
-
-
-
-
-
-
-
-
}