summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/ajax/autocomplete.php6
-rw-r--r--apps/files/ajax/delete.php23
-rw-r--r--apps/files/ajax/list.php2
-rw-r--r--apps/files/ajax/move.php13
-rw-r--r--apps/files/ajax/newfile.php20
-rw-r--r--apps/files/ajax/newfolder.php5
-rw-r--r--apps/files/ajax/rawlist.php2
-rw-r--r--apps/files/ajax/rename.php14
-rw-r--r--apps/files/ajax/upload.php8
-rw-r--r--apps/files/appinfo/filesync.php4
-rw-r--r--apps/files/download.php8
-rw-r--r--apps/files/index.php16
-rw-r--r--apps/files/settings.php2
-rw-r--r--apps/files_encryption/lib/crypt.php6
-rw-r--r--apps/files_encryption/lib/cryptstream.php4
-rw-r--r--apps/files_encryption/lib/proxy.php16
-rw-r--r--apps/files_encryption/tests/proxy.php30
-rw-r--r--apps/files_external/ajax/addRootCertificate.php2
-rw-r--r--apps/files_external/appinfo/app.php16
-rw-r--r--apps/files_external/lib/amazons3.php22
-rwxr-xr-xapps/files_external/lib/config.php22
-rwxr-xr-xapps/files_external/lib/dropbox.php61
-rw-r--r--apps/files_external/lib/ftp.php19
-rw-r--r--apps/files_external/lib/google.php35
-rw-r--r--apps/files_external/lib/smb.php14
-rw-r--r--apps/files_external/lib/streamwrapper.php31
-rw-r--r--apps/files_external/lib/swift.php111
-rw-r--r--apps/files_external/lib/webdav.php74
-rwxr-xr-xapps/files_external/personal.php2
-rw-r--r--apps/files_external/tests/amazons3.php8
-rw-r--r--apps/files_external/tests/config.php4
-rw-r--r--apps/files_external/tests/dropbox.php6
-rw-r--r--apps/files_external/tests/ftp.php8
-rw-r--r--apps/files_external/tests/google.php5
-rw-r--r--apps/files_external/tests/smb.php9
-rw-r--r--apps/files_external/tests/swift.php6
-rw-r--r--apps/files_external/tests/webdav.php7
-rw-r--r--apps/files_sharing/appinfo/app.php4
-rw-r--r--apps/files_sharing/appinfo/update.php3
-rw-r--r--apps/files_sharing/lib/sharedstorage.php165
-rw-r--r--apps/files_versions/lib/hooks.php4
-rw-r--r--apps/files_versions/lib/versions.php17
-rw-r--r--db_structure.xml124
-rwxr-xr-xlib/app.php6
-rw-r--r--lib/base.php6
-rw-r--r--lib/cache/file.php4
-rw-r--r--lib/connector/sabre/directory.php16
-rw-r--r--lib/connector/sabre/file.php10
-rw-r--r--lib/connector/sabre/node.php10
-rw-r--r--lib/filecache.php518
-rw-r--r--lib/filecache/cached.php81
-rw-r--r--lib/filecache/update.php227
-rw-r--r--lib/filechunking.php38
-rw-r--r--lib/fileproxy/fileoperations.php4
-rw-r--r--lib/fileproxy/quota.php14
-rw-r--r--lib/files.php452
-rw-r--r--lib/files/cache/cache.php304
-rw-r--r--lib/files/cache/permissions.php85
-rw-r--r--lib/files/cache/scanner.php110
-rw-r--r--lib/files/file.php61
-rw-r--r--lib/files/filesystem.php658
-rw-r--r--lib/files/storage/common.php (renamed from lib/filestorage/common.php)155
-rw-r--r--lib/files/storage/commontest.php (renamed from lib/filestorage/commontest.php)13
-rw-r--r--lib/files/storage/local.php (renamed from lib/filestorage/local.php)23
-rw-r--r--lib/files/storage/storage.php66
-rw-r--r--lib/files/storage/temporary.php26
-rw-r--r--lib/files/view.php817
-rw-r--r--lib/filestorage.php67
-rw-r--r--lib/filestorage/temporary.php17
-rw-r--r--lib/filesystem.php685
-rw-r--r--lib/filesystemview.php636
-rw-r--r--lib/helper.php2
-rw-r--r--lib/image.php2
-rw-r--r--lib/ocs.php8
-rw-r--r--lib/public/files.php2
-rw-r--r--lib/public/share.php15
-rw-r--r--lib/search/provider/file.php2
-rwxr-xr-xlib/util.php22
-rw-r--r--settings/personal.php6
-rw-r--r--tests/lib/cache/file.php6
-rw-r--r--tests/lib/files/cache/cache.php142
-rw-r--r--tests/lib/files/cache/permissions.php47
-rw-r--r--tests/lib/files/cache/scanner.php113
-rw-r--r--tests/lib/files/filesystem.php110
-rw-r--r--tests/lib/files/storage/commontest.php (renamed from tests/lib/filestorage/commontest.php)10
-rw-r--r--tests/lib/files/storage/local.php (renamed from tests/lib/filestorage/local.php)12
-rw-r--r--tests/lib/files/storage/storage.php (renamed from tests/lib/filestorage.php)32
-rw-r--r--tests/lib/files/view.php164
-rw-r--r--tests/lib/filesystem.php105
89 files changed, 3825 insertions, 3042 deletions
diff --git a/apps/files/ajax/autocomplete.php b/apps/files/ajax/autocomplete.php
index fae38368a85..d0dab9c2bd7 100644
--- a/apps/files/ajax/autocomplete.php
+++ b/apps/files/ajax/autocomplete.php
@@ -33,8 +33,8 @@ $query=strtolower($query);
$files=array();
-if(OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)) {
- $dh = OC_Filesystem::opendir($base);
+if(\OC\Files\Filesystem::file_exists($base) and \OC\Files\Filesystem::is_dir($base)) {
+ $dh = \OC\Files\Filesystem::opendir($base);
if($dh) {
if(substr($base, -1, 1)!='/') {
$base=$base.'/';
@@ -43,7 +43,7 @@ if(OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)) {
if ($file != "." && $file != "..") {
if(substr(strtolower($file), 0, $queryLen)==$query) {
$item=$base.$file;
- if((!$dirOnly or OC_Filesystem::is_dir($item))) {
+ if((!$dirOnly or \OC\Files\Filesystem::is_dir($item))) {
$files[]=(object)array('id'=>$item,'label'=>$item,'name'=>$item);
}
}
diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php
index 57c8c15c197..ae6158a05aa 100644
--- a/apps/files/ajax/delete.php
+++ b/apps/files/ajax/delete.php
@@ -12,17 +12,22 @@ $files = isset($_POST["file"]) ? stripslashes($_POST["file"]) : stripslashes($_P
$files = explode(';', $files);
$filesWithError = '';
-$success = true;
-//Now delete
-foreach($files as $file) {
- if( !OC_Files::delete( $dir, $file )) {
- $filesWithError .= $file . "\n";
- $success = false;
+if (OC_User::isLoggedIn()) {
+ $success = true;
+
+ //Now delete
+ foreach ($files as $file) {
+ if ($dir != '' || $file != 'Shared' && !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
+ $filesWithError .= $file . "\n";
+ $success = false;
+ }
}
+} else {
+ $success = false;
}
-if($success) {
- OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $files )));
+if ($success) {
+ OCP\JSON::success(array("data" => array("dir" => $dir, "files" => $files)));
} else {
- OCP\JSON::error(array("data" => array( "message" => "Could not delete:\n" . $filesWithError )));
+ OCP\JSON::error(array("data" => array("message" => "Could not delete:\n" . $filesWithError)));
}
diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php
index 568fe754c02..92091f42135 100644
--- a/apps/files/ajax/list.php
+++ b/apps/files/ajax/list.php
@@ -32,7 +32,7 @@ if($doBreadcrumb) {
// make filelist
$files = array();
-foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
+foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] );
$files[] = $i;
}
diff --git a/apps/files/ajax/move.php b/apps/files/ajax/move.php
index ddcda553e3d..e8b0aea063f 100644
--- a/apps/files/ajax/move.php
+++ b/apps/files/ajax/move.php
@@ -11,9 +11,14 @@ $dir = stripslashes($_GET["dir"]);
$file = stripslashes($_GET["file"]);
$target = stripslashes(urldecode($_GET["target"]));
-
-if(OC_Files::move($dir, $file, $target, $file)) {
- OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
-} else {
+if (OC_User::isLoggedIn() && ($dir != '' || $file != 'Shared')) {
+ $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
+ $sourceFile = \OC\Files\Filesystem::normalizePath($target . '/' . $file);
+ if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
+ OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
+ } else {
+ OCP\JSON::error(array("data" => array( "message" => "Could not move $file" )));
+ }
+}else{
OCP\JSON::error(array("data" => array( "message" => "Could not move $file" )));
}
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php
index b87079f2712..38714f34a63 100644
--- a/apps/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -63,12 +63,12 @@ if($source) {
$ctx = stream_context_create(null, array('notification' =>'progress'));
$sourceStream=fopen($source, 'rb', false, $ctx);
$target=$dir.'/'.$filename;
- $result=OC_Filesystem::file_put_contents($target, $sourceStream);
+ $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream);
if($result) {
- $meta = OC_FileCache::get($target);
+ $meta = \OC\Files\Filesystem::getFileInfo($target);
$mime=$meta['mimetype'];
- $id = OC_FileCache::getId($target);
- $eventSource->send('success', array('mime'=>$mime, 'size'=>OC_Filesystem::filesize($target), 'id' => $id));
+ $id = $meta['fileid'];
+ $eventSource->send('success', array('mime'=>$mime, 'size'=>\OC\Files\Filesystem::filesize($target), 'id' => $id));
} else {
$eventSource->send('error', "Error while downloading ".$source. ' to '.$target);
}
@@ -76,15 +76,15 @@ if($source) {
exit();
} else {
if($content) {
- if(OC_Filesystem::file_put_contents($dir.'/'.$filename, $content)) {
- $meta = OC_FileCache::get($dir.'/'.$filename);
- $id = OC_FileCache::getId($dir.'/'.$filename);
+ if(\OC\Files\Filesystem::file_put_contents($dir.'/'.$filename, $content)) {
+ $meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename);
+ $id = $meta['fileid'];
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit();
}
- }elseif(OC_Files::newFile($dir, $filename, 'file')) {
- $meta = OC_FileCache::get($dir.'/'.$filename);
- $id = OC_FileCache::getId($dir.'/'.$filename);
+ }elseif(\OC\Files\Filesystem::touch($dir . '/' . $filename)) {
+ $meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename);
+ $id = $meta['fileid'];
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit();
}
diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php
index 0f1f2f14eb0..e26e1238bc6 100644
--- a/apps/files/ajax/newfolder.php
+++ b/apps/files/ajax/newfolder.php
@@ -19,13 +19,14 @@ if(strpos($foldername, '/')!==false) {
exit();
}
-if(OC_Files::newFile($dir, stripslashes($foldername), 'dir')) {
+if(\OC\Files\Filesystem::mkdir($dir . '/' . stripslashes($foldername))) {
if ( $dir != '/') {
$path = $dir.'/'.$foldername;
} else {
$path = '/'.$foldername;
}
- $id = OC_FileCache::getId($path);
+ $meta = \OC\Files\Filesystem::getFileInfo($path);
+ $id = $meta['fileid'];
OCP\JSON::success(array("data" => array('id'=>$id)));
exit();
}
diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php
index e0aa0bdac52..1cd2944483c 100644
--- a/apps/files/ajax/rawlist.php
+++ b/apps/files/ajax/rawlist.php
@@ -15,7 +15,7 @@ $mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : '';
// make filelist
$files = array();
-foreach( OC_Files::getdirectorycontent( $dir, $mimetype ) as $i ) {
+foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $i ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] );
$i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']);
$files[] = $i;
diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php
index 45448279fa1..a2b9b8de257 100644
--- a/apps/files/ajax/rename.php
+++ b/apps/files/ajax/rename.php
@@ -11,10 +11,14 @@ $dir = stripslashes($_GET["dir"]);
$file = stripslashes($_GET["file"]);
$newname = stripslashes($_GET["newname"]);
-// Delete
-if( OC_Files::move( $dir, $file, $dir, $newname )) {
- OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
-}
-else{
+if (OC_User::isLoggedIn() && ($dir != '' || $file != 'Shared')) {
+ $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
+ $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
+ if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
+ OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
+ } else {
+ OCP\JSON::error(array("data" => array( "message" => "Unable to rename file" )));
+ }
+}else{
OCP\JSON::error(array("data" => array( "message" => "Unable to rename file" )));
}
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index dc830570403..2a784d61691 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -38,7 +38,7 @@ $totalSize=0;
foreach($files['size'] as $size) {
$totalSize+=$size;
}
-if($totalSize>OC_Filesystem::free_space($dir)){
+if($totalSize > \OC\Files\Filesystem::free_space($dir)) {
OCP\JSON::error(array("data" => array( "message" => "Not enough space available" )));
exit();
}
@@ -48,9 +48,9 @@ if(strpos($dir, '..') === false) {
$fileCount=count($files['name']);
for($i=0;$i<$fileCount;$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::get($target);
- $id = OC_FileCache::getId($target);
+ if(is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
+ $meta = \OC\Files\Filesystem::getFileInfo($target);
+ $id = $meta['fileid'];
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target));
}
}
diff --git a/apps/files/appinfo/filesync.php b/apps/files/appinfo/filesync.php
index c1fe444cec7..e755771de64 100644
--- a/apps/files/appinfo/filesync.php
+++ b/apps/files/appinfo/filesync.php
@@ -43,7 +43,7 @@ if ($type != 'oc_chunked') {
die;
}
-if (!OC_Filesystem::is_file($file)) {
+if (!\OC\Files\Filesystem::is_file($file)) {
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
die;
}
@@ -51,7 +51,7 @@ if (!OC_Filesystem::is_file($file)) {
switch($_SERVER['REQUEST_METHOD']) {
case 'PUT':
$input = fopen("php://input", "r");
- $org_file = OC_Filesystem::fopen($file, 'rb');
+ $org_file = \OC\Files\Filesystem::fopen($file, 'rb');
$info = array(
'name' => basename($file),
);
diff --git a/apps/files/download.php b/apps/files/download.php
index ff6aefbbe0f..b00a50a0452 100644
--- a/apps/files/download.php
+++ b/apps/files/download.php
@@ -29,7 +29,7 @@ OCP\User::checkLoggedIn();
$filename = $_GET["file"];
-if(!OC_Filesystem::file_exists($filename)) {
+if(!\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OCP\Template( '', '404', 'guest' );
$tmpl->assign('file',$filename);
@@ -37,12 +37,12 @@ if(!OC_Filesystem::file_exists($filename)) {
exit;
}
-$ftype=OC_Filesystem::getMimeType( $filename );
+$ftype=\OC\Files\Filesystem::getMimeType( $filename );
header('Content-Type:'.$ftype);
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
OCP\Response::disableCaching();
-header('Content-Length: '.OC_Filesystem::filesize($filename));
+header('Content-Length: '.\OC\Files\Filesystem::filesize($filename));
@ob_end_clean();
-OC_Filesystem::readfile( $filename );
+\OC\Files\Filesystem::readfile( $filename );
diff --git a/apps/files/index.php b/apps/files/index.php
index 92fda5b21e5..4676ebc6021 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -38,13 +38,13 @@ OCP\App::setActiveNavigationEntry( 'files_index' );
// Load the files
$dir = isset( $_GET['dir'] ) ? urldecode(stripslashes($_GET['dir'])) : '';
// Redirect if directory does not exist
-if(!OC_Filesystem::is_dir($dir.'/')) {
+if(!\OC\Files\Filesystem::is_dir($dir.'/')) {
header('Location: '.$_SERVER['SCRIPT_NAME'].'');
exit();
}
$files = array();
-foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
+foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i['date'] = OCP\Util::formatDate($i['mtime'] );
if($i['type']=='file') {
$fileinfo=pathinfo($i['name']);
@@ -85,26 +85,26 @@ $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')
$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
-$freeSpace=OC_Filesystem::free_space($dir);
+$freeSpace=\OC\Files\Filesystem::free_space($dir);
$freeSpace=max($freeSpace,0);
$maxUploadFilesize = min($maxUploadFilesize, $freeSpace);
$permissions = OCP\Share::PERMISSION_READ;
-if (OC_Filesystem::isUpdatable($dir.'/')) {
+if (\OC\Files\Filesystem::isUpdatable($dir.'/')) {
$permissions |= OCP\Share::PERMISSION_UPDATE;
}
-if (OC_Filesystem::isDeletable($dir.'/')) {
+if (\OC\Files\Filesystem::isDeletable($dir.'/')) {
$permissions |= OCP\Share::PERMISSION_DELETE;
}
-if (OC_Filesystem::isSharable($dir.'/')) {
+if (\OC\Files\Filesystem::isSharable($dir.'/')) {
$permissions |= OCP\Share::PERMISSION_SHARE;
}
$tmpl = new OCP\Template( 'files', 'index', 'user' );
$tmpl->assign( 'fileList', $list->fetchPage(), false );
$tmpl->assign( 'breadcrumb', $breadcrumbNav->fetchPage(), false );
-$tmpl->assign( 'dir', OC_Filesystem::normalizePath($dir));
-$tmpl->assign( 'isCreatable', OC_Filesystem::isCreatable($dir.'/'));
+$tmpl->assign( 'dir', \OC\Files\Filesystem::normalizePath($dir));
+$tmpl->assign( 'isCreatable', \OC\Files\Filesystem::isCreatable($dir.'/'));
$tmpl->assign('permissions', $permissions);
$tmpl->assign( 'files', $files );
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
diff --git a/apps/files/settings.php b/apps/files/settings.php
index 52ec9fd0fe3..30463210f71 100644
--- a/apps/files/settings.php
+++ b/apps/files/settings.php
@@ -36,7 +36,7 @@ OCP\Util::addscript( "files", "files" );
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$files = array();
-foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
+foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] );
$files[] = $i;
}
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index d057c1ed194..c9d4ff27104 100644
--- a/apps/files_encryption/lib/crypt.php
+++ b/apps/files_encryption/lib/crypt.php
@@ -44,7 +44,7 @@ class OC_Crypt {
}
public static function init($login,$password) {
- $view=new OC_FilesystemView('/');
+ $view=new \OC\Files\View('/');
if(!$view->file_exists('/'.$login)) {
$view->mkdir('/'.$login);
}
@@ -90,7 +90,7 @@ class OC_Crypt {
// Write the file
$proxyEnabled=OC_FileProxy::$enabled;
OC_FileProxy::$enabled=false;
- $view=new OC_FilesystemView('/'.$username);
+ $view=new \OC\Files\View('/'.$username);
$view->file_put_contents('/encryption.key',$enckey);
OC_FileProxy::$enabled=$proxyEnabled;
}
@@ -98,7 +98,7 @@ class OC_Crypt {
public static function changekeypasscode($oldPassword, $newPassword) {
if(OCP\User::isLoggedIn()) {
$username=OCP\USER::getUser();
- $view=new OC_FilesystemView('/'.$username);
+ $view=new \OC\Files\View('/'.$username);
// read old key
$key=$view->file_get_contents('/encryption.key');
diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php
index 95b58b8cce7..c4298382646 100644
--- a/apps/files_encryption/lib/cryptstream.php
+++ b/apps/files_encryption/lib/cryptstream.php
@@ -38,7 +38,7 @@ class OC_CryptStream{
public function stream_open($path, $mode, $options, &$opened_path) {
if(!self::$rootView) {
- self::$rootView=new OC_FilesystemView('');
+ self::$rootView=new \OC\Files\View('');
}
$path=str_replace('crypt://','',$path);
if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) {
@@ -167,7 +167,7 @@ class OC_CryptStream{
public function stream_close() {
$this->flush();
if($this->meta['mode']!='r' and $this->meta['mode']!='rb') {
- OC_FileCache::put($this->path, array('encrypted'=>true,'size'=>$this->size),'');
+ \OC\Files\Filesystem::putFileInfo($this->path, array('encrypted'=>true,'size'=>$this->size),'');
}
return fclose($this->source);
}
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 61b87ab5463..49fb30ac291 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -59,7 +59,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @return bool
*/
private static function isEncrypted($path) {
- $metadata=OC_FileCache_Cached::get($path,'');
+ $metadata=\OC\Files\Filesystem::getFileInfo($path,'');
return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
}
@@ -68,14 +68,14 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if (!is_resource($data)) {//stream put contents should have been converter to fopen
$size=strlen($data);
$data=OC_Crypt::blockEncrypt($data);
- OC_FileCache::put($path, array('encrypted'=>true,'size'=>$size),'');
+ \OC\Files\Filesystem::putFileInfo($path, array('encrypted'=>true,'size'=>$size),'');
}
}
}
public function postFile_get_contents($path,$data) {
if(self::isEncrypted($path)) {
- $cached=OC_FileCache_Cached::get($path,'');
+ $cached=\OC\Files\Filesystem::getFileInfo($path,'');
$data=OC_Crypt::blockDecrypt($data,'',$cached['size']);
}
return $data;
@@ -90,13 +90,13 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
fclose($result);
$result=fopen('crypt://'.$path,$meta['mode']);
}elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') {
- if(OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0) {
+ if(\OC\Files\Filesystem::file_exists($path) and \OC\Files\Filesystem::filesize($path)>0) {
//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');
+ $tmp=fopen('php://temp', 'w+');
OCP\Files::streamCopy($result,$tmp);
fclose($result);
- OC_Filesystem::file_put_contents($path,$tmp);
+ \OC\Files\Filesystem::file_put_contents($path,$tmp);
fclose($tmp);
}
$result=fopen('crypt://'.$path,$meta['mode']);
@@ -113,7 +113,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postStat($path,$data) {
if(self::isEncrypted($path)) {
- $cached=OC_FileCache_Cached::get($path,'');
+ $cached=\OC\Files\Filesystem::getFileInfo($path,'');
$data['size']=$cached['size'];
}
return $data;
@@ -121,7 +121,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postFileSize($path,$size) {
if(self::isEncrypted($path)) {
- $cached=OC_FileCache_Cached::get($path,'');
+ $cached=\OC\Files\Filesystem::getFileInfo($path,'');
return $cached['size'];
}else{
return $size;
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index c3c8f4a2db0..c27964699a2 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -29,13 +29,13 @@ class Test_CryptProxy extends UnitTestCase {
OC_FileProxy::register(new OC_FileProxy_Encryption());
//set up temporary storage
- OC_Filesystem::clearMounts();
- OC_Filesystem::mount('OC_Filestorage_Temporary', array(),'/');
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Temporary' ,array(), '/');
- OC_Filesystem::init('/'.$user.'/files');
+ \OC\Files\Filesystem::init('/'.$user.'/files');
//set up the users home folder in the temp storage
- $rootView=new OC_FilesystemView('');
+ $rootView=new \OC\Files\View('');
$rootView->mkdir('/'.$user);
$rootView->mkdir('/'.$user.'/files');
}
@@ -51,13 +51,13 @@ class Test_CryptProxy extends UnitTestCase {
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$original=file_get_contents($file);
- OC_Filesystem::file_put_contents('/file',$original);
+ \OC\Files\Filesystem::file_put_contents('/file',$original);
OC_FileProxy::$enabled=false;
- $stored=OC_Filesystem::file_get_contents('/file');
+ $stored=\OC\Files\Filesystem::file_get_contents('/file');
OC_FileProxy::$enabled=true;
- $fromFile=OC_Filesystem::file_get_contents('/file');
+ $fromFile=\OC\Files\Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original), strlen($fromFile));
$this->assertEqual($original,$fromFile);
@@ -68,8 +68,8 @@ class Test_CryptProxy extends UnitTestCase {
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$original=file_get_contents($file);
- $rootView=new OC_FilesystemView('');
- $view=new OC_FilesystemView('/'.OC_User::getUser());
+ $rootView=new \OC\Files\View('');
+ $view=new \OC\Files\View('/'.OC_User::getUser());
$userDir='/'.OC_User::getUser().'/files';
$rootView->file_put_contents($userDir.'/file',$original);
@@ -90,13 +90,13 @@ class Test_CryptProxy extends UnitTestCase {
$file=__DIR__.'/binary';
$original=file_get_contents($file);
- OC_Filesystem::file_put_contents('/file',$original);
+ \OC\Files\Filesystem::file_put_contents('/file',$original);
OC_FileProxy::$enabled=false;
- $stored=OC_Filesystem::file_get_contents('/file');
+ $stored=\OC\Files\Filesystem::file_get_contents('/file');
OC_FileProxy::$enabled=true;
- $fromFile=OC_Filesystem::file_get_contents('/file');
+ $fromFile=\OC\Files\Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original), strlen($fromFile));
$this->assertEqual($original,$fromFile);
@@ -104,13 +104,13 @@ class Test_CryptProxy extends UnitTestCase {
$file=__DIR__.'/zeros';
$original=file_get_contents($file);
- OC_Filesystem::file_put_contents('/file',$original);
+ \OC\Files\Filesystem::file_put_contents('/file',$original);
OC_FileProxy::$enabled=false;
- $stored=OC_Filesystem::file_get_contents('/file');
+ $stored=\OC\Files\Filesystem::file_get_contents('/file');
OC_FileProxy::$enabled=true;
- $fromFile=OC_Filesystem::file_get_contents('/file');
+ $fromFile=\OC\Files\Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original), strlen($fromFile));
}
diff --git a/apps/files_external/ajax/addRootCertificate.php b/apps/files_external/ajax/addRootCertificate.php
index 72eb30009d1..6fef9aac1ed 100644
--- a/apps/files_external/ajax/addRootCertificate.php
+++ b/apps/files_external/ajax/addRootCertificate.php
@@ -12,7 +12,7 @@ $data = fread($fh, filesize($_FILES['rootcert_import']['tmp_name']));
fclose($fh);
$filename = $_FILES['rootcert_import']['name'];
-$view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_external/uploads');
+$view = new \OC\Files\View('/'.\OCP\User::getUser().'/files_external/uploads');
if (!$view->file_exists('')) $view->mkdir('');
$isValid = openssl_pkey_get_public($data);
diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php
index 837d35c9c63..c58cfcd0f5e 100644
--- a/apps/files_external/appinfo/app.php
+++ b/apps/files_external/appinfo/app.php
@@ -6,14 +6,14 @@
* See the COPYING-README file.
*/
-OC::$CLASSPATH['OC_FileStorage_StreamWrapper']='apps/files_external/lib/streamwrapper.php';
-OC::$CLASSPATH['OC_Filestorage_FTP']='apps/files_external/lib/ftp.php';
-OC::$CLASSPATH['OC_Filestorage_DAV']='apps/files_external/lib/webdav.php';
-OC::$CLASSPATH['OC_Filestorage_Google']='apps/files_external/lib/google.php';
-OC::$CLASSPATH['OC_Filestorage_SWIFT']='apps/files_external/lib/swift.php';
-OC::$CLASSPATH['OC_Filestorage_SMB']='apps/files_external/lib/smb.php';
-OC::$CLASSPATH['OC_Filestorage_AmazonS3']='apps/files_external/lib/amazons3.php';
-OC::$CLASSPATH['OC_Filestorage_Dropbox']='apps/files_external/lib/dropbox.php';
+OC::$CLASSPATH['OC\Files\Storage\StreamWrapper']='apps/files_external/lib/streamwrapper.php';
+OC::$CLASSPATH['OC\Files\Storage\FTP']='apps/files_external/lib/ftp.php';
+OC::$CLASSPATH['OC\Files\Storage\DAV']='apps/files_external/lib/webdav.php';
+OC::$CLASSPATH['OC\Files\Storage\Google']='apps/files_external/lib/google.php';
+OC::$CLASSPATH['OC\Files\Storage\SWIFT']='apps/files_external/lib/swift.php';
+OC::$CLASSPATH['OC\Files\Storage\SMB']='apps/files_external/lib/smb.php';
+OC::$CLASSPATH['OC\Files\Storage\AmazonS3']='apps/files_external/lib/amazons3.php';
+OC::$CLASSPATH['OC\Files\Storage\Dropbox']='apps/files_external/lib/dropbox.php';
OC::$CLASSPATH['OC_Mount_Config']='apps/files_external/lib/config.php';
OCP\App::registerAdmin('files_external', 'settings');
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index 41ec3c70b45..c3fa4651f64 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -20,20 +20,24 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace OC\Files\Storage;
+
require_once 'aws-sdk/sdk.class.php';
-class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
+class AmazonS3 extends \OC\Files\Storage\Common {
private $s3;
private $bucket;
private $objects = array();
+ private $id;
private static $tempFiles = array();
// TODO options: storage class, encryption server side, encrypt before upload?
public function __construct($params) {
- $this->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret']));
+ $this->id = 'amazon::'.$params['key'] . md5($params['secret']);
+ $this->s3 = new \AmazonS3(array('key' => $params['key'], 'secret' => $params['secret']));
$this->bucket = $params['bucket'];
}
@@ -57,6 +61,10 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
return false;
}
+ public function getId(){
+ return $this->id;
+ }
+
public function mkdir($path) {
// Folders in Amazon S3 are 0 byte objects with a '/' at the end of the name
if (substr($path, -1) != '/') {
@@ -96,7 +104,7 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
foreach ($response->body->CommonPrefixes as $object) {
$files[] = basename($object->Prefix);
}
- OC_FakeDirStream::$dirs['amazons3'.$path] = $files;
+ \OC_FakeDirStream::$dirs['amazons3'.$path] = $files;
return opendir('fakedir://amazons3'.$path);
}
return false;
@@ -107,12 +115,10 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
$stat['size'] = $this->s3->get_bucket_filesize($this->bucket);
$stat['atime'] = time();
$stat['mtime'] = $stat['atime'];
- $stat['ctime'] = $stat['atime'];
} else if ($object = $this->getObject($path)) {
$stat['size'] = $object['Size'];
$stat['atime'] = time();
$stat['mtime'] = strtotime($object['LastModified']);
- $stat['ctime'] = $stat['mtime'];
}
if (isset($stat)) {
return $stat;
@@ -160,7 +166,7 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
switch ($mode) {
case 'r':
case 'rb':
- $tmpFile = OC_Helper::tmpFile();
+ $tmpFile = \OC_Helper::tmpFile();
$handle = fopen($tmpFile, 'w');
$response = $this->s3->get_object($this->bucket, $path, array('fileDownload' => $handle));
if ($response->isOK()) {
@@ -184,8 +190,8 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
} else {
$ext = '';
}
- $tmpFile = OC_Helper::tmpFile($ext);
- OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
+ $tmpFile = \OC_Helper::tmpFile($ext);
+ \OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 9dc3cdd7147..14370d5f1fe 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -39,14 +39,14 @@ class OC_Mount_Config {
*/
public static function getBackends() {
return array(
- 'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
- 'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
- 'OC_Filestorage_Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('configured' => '#configured','app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'),
- 'OC_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
- 'OC_Filestorage_Google' => array('backend' => 'Google Drive', 'configuration' => array('configured' => '#configured', 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
- 'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
- 'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')),
- 'OC_Filestorage_DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
+ '\OC\Files\Storage\Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
+ '\OC\Files\Storage\AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
+ '\OC\Files\Storage\Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('configured' => '#configured','app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'),
+ '\OC\Files\Storage\FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
+ '\OC\Files\Storage\Google' => array('backend' => 'Google Drive', 'configuration' => array('configured' => '#configured', 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
+ '\OC\Files\Storage\SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
+ '\OC\Files\Storage\SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')),
+ '\OC\Files\Storage\DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
);
}
@@ -139,14 +139,14 @@ class OC_Mount_Config {
if ($isPersonal) {
// Verify that the mount point applies for the current user
// Prevent non-admin users from mounting local storage
- if ($applicable != OCP\User::getUser() || $class == 'OC_Filestorage_Local') {
+ if ($applicable != OCP\User::getUser() || $class == '\OC\Files\Storage\Local') {
return false;
}
- $view = new OC_FilesystemView('/'.OCP\User::getUser().'/files');
+ $view = new \OC\Files\View('/'.OCP\User::getUser().'/files');
self::addMountPointDirectory($view, ltrim($mountPoint, '/'));
$mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/');
} else {
- $view = new OC_FilesystemView('/');
+ $view = new \OC\Files\View('/');
switch ($mountType) {
case 'user':
if ($applicable == "all") {
diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php
index c8220832702..0e82f80668f 100755
--- a/apps/files_external/lib/dropbox.php
+++ b/apps/files_external/lib/dropbox.php
@@ -20,25 +20,29 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace OC\Files\Storage;
+
require_once 'Dropbox/autoload.php';
-class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
+class Dropbox extends \OC\Files\Storage\Common {
private $dropbox;
private $root;
+ private $id;
private $metaData = array();
private static $tempFiles = array();
public function __construct($params) {
if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['app_key']) && isset($params['app_secret']) && isset($params['token']) && isset($params['token_secret'])) {
+ $this->id = 'dropbox::'.$params['app_key'] . $params['token']. '/' . $params['root'];
$this->root=isset($params['root'])?$params['root']:'';
- $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
+ $oauth = new \Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
$oauth->setToken($params['token'], $params['token_secret']);
- $this->dropbox = new Dropbox_API($oauth, 'dropbox');
+ $this->dropbox = new \Dropbox_API($oauth, 'dropbox');
$this->mkdir('');
} else {
- throw new Exception('Creating OC_Filestorage_Dropbox storage failed');
+ throw new \Exception('Creating \OC\Files\Storage\Dropbox storage failed');
}
}
@@ -50,8 +54,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
if ($list) {
try {
$response = $this->dropbox->getMetaData($path);
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
if ($response && isset($response['contents'])) {
@@ -71,21 +75,25 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
$response = $this->dropbox->getMetaData($path, 'false');
$this->metaData[$path] = $response;
return $response;
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
}
}
}
+ public function getId(){
+ return $this->id;
+ }
+
public function mkdir($path) {
$path = $this->root.$path;
try {
$this->dropbox->createFolder($path);
return true;
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
}
@@ -100,7 +108,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
foreach ($contents as $file) {
$files[] = basename($file['path']);
}
- OC_FakeDirStream::$dirs['dropbox'.$path] = $files;
+ \OC_FakeDirStream::$dirs['dropbox'.$path] = $files;
return opendir('fakedir://dropbox'.$path);
}
return false;
@@ -111,7 +119,6 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
$stat['size'] = $metaData['bytes'];
$stat['atime'] = time();
$stat['mtime'] = (isset($metaData['modified'])) ? strtotime($metaData['modified']) : time();
- $stat['ctime'] = $stat['mtime'];
return $stat;
}
return false;
@@ -153,8 +160,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
try {
$this->dropbox->delete($path);
return true;
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
}
@@ -165,8 +172,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
try {
$this->dropbox->move($path1, $path2);
return true;
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
}
@@ -177,8 +184,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
try {
$this->dropbox->copy($path1, $path2);
return true;
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
}
@@ -188,13 +195,13 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
switch ($mode) {
case 'r':
case 'rb':
- $tmpFile = OC_Helper::tmpFile();
+ $tmpFile = \OC_Helper::tmpFile();
try {
$data = $this->dropbox->getFile($path);
file_put_contents($tmpFile, $data);
return fopen($tmpFile, 'r');
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
case 'w':
@@ -214,8 +221,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} else {
$ext = '';
}
- $tmpFile = OC_Helper::tmpFile($ext);
- OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
+ $tmpFile = \OC_Helper::tmpFile($ext);
+ \OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
@@ -232,8 +239,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
try {
$this->dropbox->putFile(self::$tempFiles[$tmpFile], $handle);
unlink($tmpFile);
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
}
}
}
@@ -251,8 +258,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
try {
$info = $this->dropbox->getAccountInfo();
return $info['quota_info']['quota'] - $info['quota_info']['normal'];
- } catch (Exception $exception) {
- OCP\Util::writeLog('files_external', $exception->getMessage(), OCP\Util::ERROR);
+ } catch (\Exception $exception) {
+ \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
}
diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index 13d1387f287..a3677e82e2e 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -6,7 +6,9 @@
* See the COPYING-README file.
*/
-class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
+namespace OC\Files\Storage;
+
+class FTP extends \OC\Files\Storage\StreamWrapper{
private $password;
private $user;
private $host;
@@ -24,15 +26,19 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
- //create the root folder if necesary
+ //create the root folder if necessary
if (!$this->is_dir('')) {
$this->mkdir('');
}
}
+ public function getId(){
+ return 'ftp::' . $this->user . '@' . $this->host . '/' . $this->root;
+ }
+
/**
* construct the ftp url
- * @param string path
+ * @param string $path
* @return string
*/
public function constructUrl($path) {
@@ -44,6 +50,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
return $url;
}
public function fopen($path,$mode) {
+ $this->init();
switch($mode) {
case 'r':
case 'rb':
@@ -68,17 +75,19 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
}else{
$ext='';
}
- $tmpFile=OCP\Files::tmpFile($ext);
- OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
+ $tmpFile=\OCP\Files::tmpFile($ext);
+ \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
if($this->file_exists($path)) {
$this->getFile($path,$tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile,$mode);
}
+ return false;
}
public function writeBack($tmpFile) {
+ $this->init();
if(isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]);
unlink($tmpFile);
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index 32d57ed3cef..3c88a70bc10 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -20,14 +20,17 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace OC\Files\Storage;
+
require_once 'Google/common.inc.php';
-class OC_Filestorage_Google extends OC_Filestorage_Common {
+class Google extends \OC\Files\Storage\Common {
private $consumer;
private $oauth_token;
private $sig_method;
private $entries;
+ private $id;
private static $tempFiles = array();
@@ -35,12 +38,13 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['token']) && isset($params['token_secret'])) {
$consumer_key = isset($params['consumer_key']) ? $params['consumer_key'] : 'anonymous';
$consumer_secret = isset($params['consumer_secret']) ? $params['consumer_secret'] : 'anonymous';
- $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
- $this->oauth_token = new OAuthToken($params['token'], $params['token_secret']);
- $this->sig_method = new OAuthSignatureMethod_HMAC_SHA1();
+ $this->id = 'google::' . $consumer_key . $consumer_secret;
+ $this->consumer = new \OAuthConsumer($consumer_key, $consumer_secret);
+ $this->oauth_token = new \OAuthToken($params['token'], $params['token_secret']);
+ $this->sig_method = new \OAuthSignatureMethod_HMAC_SHA1();
$this->entries = array();
} else {
- throw new Exception('Creating OC_Filestorage_Google storage failed');
+ throw new \Exception('Creating \OC\Files\Storage\Google storage failed');
}
}
@@ -58,7 +62,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$tempStr .= '&' . urlencode($key) . '=' . urlencode($value);
}
$uri = preg_replace('/&/', '?', $tempStr, 1);
- $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params);
+ $request = \OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params);
$request->sign_request($this->sig_method, $this->consumer, $this->oauth_token);
$auth_header = $request->to_header();
$headers = array($auth_header, 'GData-Version: 3.0');
@@ -96,7 +100,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
if ($isDownload) {
- $tmpFile = OC_Helper::tmpFile();
+ $tmpFile = \OC_Helper::tmpFile();
$handle = fopen($tmpFile, 'w');
curl_setopt($curl, CURLOPT_FILE, $handle);
}
@@ -125,7 +129,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
private function getFeed($feedUri, $httpMethod, $postData = null) {
$result = $this->sendRequest($feedUri, $httpMethod, $postData);
if ($result) {
- $dom = new DOMDocument();
+ $dom = new \DOMDocument();
$dom->loadXML($result);
return $dom;
}
@@ -175,6 +179,9 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
}
+ public function getId(){
+ return $this->id;
+ }
public function mkdir($path) {
$collection = dirname($path);
@@ -241,7 +248,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$this->entries[$name] = $entry;
}
}
- OC_FakeDirStream::$dirs['google'.$path] = $files;
+ \OC_FakeDirStream::$dirs['google'.$path] = $files;
return opendir('fakedir://google'.$path);
}
@@ -250,14 +257,12 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$stat['size'] = $this->free_space($path);
$stat['atime'] = time();
$stat['mtime'] = time();
- $stat['ctime'] = time();
} else if ($entry = $this->getResource($path)) {
// NOTE: Native resources don't have a file size
$stat['size'] = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'quotaBytesUsed')->item(0)->nodeValue;
// if (isset($atime = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'lastViewed')->item(0)->nodeValue))
// $stat['atime'] = strtotime($entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'lastViewed')->item(0)->nodeValue);
$stat['mtime'] = strtotime($entry->getElementsByTagName('updated')->item(0)->nodeValue);
- $stat['ctime'] = strtotime($entry->getElementsByTagName('published')->item(0)->nodeValue);
}
if (isset($stat)) {
return $stat;
@@ -399,8 +404,8 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
} else {
$ext = '';
}
- $tmpFile = OC_Helper::tmpFile($ext);
- OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
+ $tmpFile = \OC_Helper::tmpFile($ext);
+ \OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
@@ -438,7 +443,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
if (isset($uploadUri) && $handle = fopen($path, 'r')) {
$uploadUri .= '?convert=false';
- $mimetype = OC_Helper::getMimeType($path);
+ $mimetype = \OC_Helper::getMimeType($path);
$size = filesize($path);
$headers = array('X-Upload-Content-Type: ' => $mimetype, 'X-Upload-Content-Length: ' => $size);
$postData = '<?xml version="1.0" encoding="UTF-8"?>';
@@ -537,4 +542,4 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
-} \ No newline at end of file
+}
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index eed2582dc99..4382f630031 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -6,9 +6,11 @@
* See the COPYING-README file.
*/
+namespace OC\Files\Storage;
+
require_once 'smb4php/smb.php';
-class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
+class SMB extends \OC\Files\Storage\StreamWrapper{
private $password;
private $user;
private $host;
@@ -33,11 +35,10 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
if(substr($this->share,-1,1)=='/') {
$this->share=substr($this->share,0,-1);
}
+ }
- //create the root folder if necesary
- if(!$this->is_dir('')) {
- $this->mkdir('');
- }
+ public function getId(){
+ return 'smb::' . $this->user . '@' . $this->host . '/' . $this->share . '/' . $this->root;
}
public function constructUrl($path) {
@@ -48,6 +49,7 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
}
public function stat($path) {
+ $this->init();
if(!$path and $this->root=='/') {//mtime doesn't work for shares
$mtime=$this->shareMTime();
$stat=stat($this->constructUrl($path));
@@ -64,10 +66,12 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
/**
* check if a file or folder has been updated since $time
+ * @param string $path
* @param int $time
* @return bool
*/
public function hasUpdated($path,$time) {
+ $this->init();
if(!$path and $this->root=='/') {
//mtime doesn't work for shares, but giving the nature of the backend, doing a full update is still just fast enough
return true;
diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index 7263ef23253..bc1c95c5e8f 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -6,15 +6,32 @@
* See the COPYING-README file.
*/
+namespace OC\Files\Storage;
+
+abstract class StreamWrapper extends \OC\Files\Storage\Common{
+ private $ready = false;
+
+ protected function init(){
+ if($this->ready){
+ return;
+ }
+ $this->ready = true;
+
+ //create the root folder if necesary
+ if(!$this->is_dir('')) {
+ $this->mkdir('');
+ }
+ }
-abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
abstract public function constructUrl($path);
public function mkdir($path) {
+ $this->init();
return mkdir($this->constructUrl($path));
}
public function rmdir($path) {
+ $this->init();
if($this->file_exists($path)) {
$succes=rmdir($this->constructUrl($path));
clearstatcache();
@@ -25,10 +42,12 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
}
public function opendir($path) {
+ $this->init();
return opendir($this->constructUrl($path));
}
public function filetype($path) {
+ $this->init();
return filetype($this->constructUrl($path));
}
@@ -41,16 +60,19 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
}
public function file_exists($path) {
+ $this->init();
return file_exists($this->constructUrl($path));
}
public function unlink($path) {
+ $this->init();
$succes=unlink($this->constructUrl($path));
clearstatcache();
return $succes;
}
public function fopen($path,$mode) {
+ $this->init();
return fopen($this->constructUrl($path),$mode);
}
@@ -59,6 +81,7 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
}
public function touch($path,$mtime=null) {
+ $this->init();
if(is_null($mtime)) {
$fh=$this->fopen($path,'a');
fwrite($fh,'');
@@ -69,21 +92,23 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
}
public function getFile($path,$target) {
+ $this->init();
return copy($this->constructUrl($path),$target);
}
public function uploadFile($path,$target) {
+ $this->init();
return copy($path,$this->constructUrl($target));
}
public function rename($path1,$path2) {
+ $this->init();
return rename($this->constructUrl($path1),$this->constructUrl($path2));
}
public function stat($path) {
+ $this->init();
return stat($this->constructUrl($path));
}
-
-
}
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index 632c72c280f..7fb9b7e640d 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -6,24 +6,28 @@
* See the COPYING-README file.
*/
+namespace OC\Files\Storage;
+
require_once 'php-cloudfiles/cloudfiles.php';
-class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
+class SWIFT extends \OC\Files\Storage\Common{
+ private $id;
private $host;
private $root;
private $user;
private $token;
private $secure;
+ private $ready = false;
/**
- * @var CF_Authentication auth
+ * @var \CF_Authentication auth
*/
private $auth;
/**
- * @var CF_Connection conn
+ * @var \CF_Connection conn
*/
private $conn;
/**
- * @var CF_Container rootContainer
+ * @var \CF_Container rootContainer
*/
private $rootContainer;
@@ -35,7 +39,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* translate directory path to container name
- * @param string path
+ * @param string $path
* @return string
*/
private function getContainerName($path) {
@@ -45,8 +49,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* get container by path
- * @param string path
- * @return CF_Container
+ * @param string $path
+ * @return \CF_Container
*/
private function getContainer($path) {
if($path=='' or $path=='/') {
@@ -59,15 +63,15 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$container=$this->conn->get_container($this->getContainerName($path));
$this->containers[$path]=$container;
return $container;
- }catch(NoSuchContainerException $e) {
+ }catch(\NoSuchContainerException $e) {
return null;
}
}
/**
* create container
- * @param string path
- * @return CF_Container
+ * @param string $path
+ * @return \CF_Container
*/
private function createContainer($path) {
if($path=='' or $path=='/' or $path=='.') {
@@ -89,8 +93,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* get object by path
- * @param string path
- * @return CF_Object
+ * @param string $path
+ * @return \CF_Object
*/
private function getObject($path) {
if(isset($this->objects[$path])) {
@@ -107,7 +111,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$obj=$container->get_object(basename($path));
$this->objects[$path]=$obj;
return $obj;
- }catch(NoSuchObjectException $e) {
+ }catch(\NoSuchObjectException $e) {
return null;
}
}
@@ -132,8 +136,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* create object
- * @param string path
- * @return CF_Object
+ * @param string $path
+ * @return \CF_Object
*/
private function createObject($path) {
$container=$this->getContainer(dirname($path));
@@ -154,7 +158,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* check if container for path exists
- * @param string path
+ * @param string $path
* @return bool
*/
private function containerExists($path) {
@@ -163,15 +167,15 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* get the list of emulated sub containers
- * @param CF_Container container
+ * @param \CF_Container $container
* @return array
*/
private function getSubContainers($container) {
- $tmpFile=OCP\Files::tmpFile();
+ $tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return array();
}
$obj->save_to_filename($tmpFile);
@@ -185,15 +189,15 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* add an emulated sub container
- * @param CF_Container container
- * @param string name
+ * @param \CF_Container $container
+ * @param string $name
* @return bool
*/
private function addSubContainer($container,$name) {
if(!$name) {
return false;
}
- $tmpFile=OCP\Files::tmpFile();
+ $tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
@@ -208,8 +212,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$fh=fopen($tmpFile,'a');
fwrite($fh,$name."\n");
}
- }catch(Exception $e) {
- $containers=array();
+ }catch(\Exception $e) {
file_put_contents($tmpFile,$name."\n");
}
@@ -220,20 +223,20 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* remove an emulated sub container
- * @param CF_Container container
- * @param string name
+ * @param \CF_Container $container
+ * @param string $name
* @return bool
*/
private function removeSubContainer($container,$name) {
if(!$name) {
return false;
}
- $tmpFile=OCP\Files::tmpFile();
+ $tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return false;
}
foreach($containers as &$sub) {
@@ -255,13 +258,13 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* ensure a subcontainer file exists and return it's object
- * @param CF_Container container
- * @return CF_Object
+ * @param \CF_Container $container
+ * @return \CF_Object
*/
private function getSubContainerFile($container) {
try{
return $container->get_object(self::SUBCONTAINER_FILE);
- }catch(NoSuchObjectException $e) {
+ }catch(\NoSuchObjectException $e) {
return $container->create_object(self::SUBCONTAINER_FILE);
}
}
@@ -272,13 +275,24 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$this->user=$params['user'];
$this->root=isset($params['root'])?$params['root']:'/';
$this->secure=isset($params['secure'])?(bool)$params['secure']:true;
+
+ $this->id = 'swift::' . $this->user . '@' . $this->host . '/' . $this->root;
if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
- $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host);
+
+ }
+
+ private function init(){
+ if($this->ready){
+ return;
+ }
+ $this->ready = true;
+
+ $this->auth = new \CF_Authentication($this->user, $this->token, null, $this->host);
$this->auth->authenticate();
- $this->conn = new CF_Connection($this->auth);
+ $this->conn = new \CF_Connection($this->auth);
if(!$this->containerExists('/')) {
$this->rootContainer=$this->createContainer('/');
@@ -287,8 +301,13 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
+ public function getId(){
+ return $this->id;
+ }
+
public function mkdir($path) {
+ $this->init();
if($this->containerExists($path)) {
return false;
}else{
@@ -298,6 +317,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function rmdir($path) {
+ $this->init();
if(!$this->containerExists($path)) {
return false;
}else{
@@ -335,6 +355,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function opendir($path) {
+ $this->init();
$container=$this->getContainer($path);
$files=$this->getObjects($container);
$i=array_search(self::SUBCONTAINER_FILE,$files);
@@ -344,11 +365,12 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$subContainers=$this->getSubContainers($container);
$files=array_merge($files,$subContainers);
$id=$this->getContainerName($path);
- OC_FakeDirStream::$dirs[$id]=$files;
+ \OC_FakeDirStream::$dirs[$id]=$files;
return opendir('fakedir://'.$id);
}
public function filetype($path) {
+ $this->init();
if($this->containerExists($path)) {
return 'dir';
}else{
@@ -365,6 +387,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function file_exists($path) {
+ $this->init();
if($this->is_dir($path)) {
return true;
}else{
@@ -373,6 +396,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function file_get_contents($path) {
+ $this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
return false;
@@ -381,6 +405,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function file_put_contents($path,$content) {
+ $this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
$container=$this->getContainer(dirname($path));
@@ -394,6 +419,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function unlink($path) {
+ $this->init();
if($this->containerExists($path)) {
return $this->rmdir($path);
}
@@ -407,6 +433,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function fopen($path,$mode) {
+ $this->init();
switch($mode) {
case 'r':
case 'rb':
@@ -432,7 +459,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
case 'c':
case 'c+':
$tmpFile=$this->getTmpFile($path);
- OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
+ \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile,$mode);
}
@@ -450,6 +477,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function touch($path,$mtime=null) {
+ $this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
return false;
@@ -464,6 +492,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function rename($path1,$path2) {
+ $this->init();
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
$result=$sourceContainer->move_object_to(basename($path1),$targetContainer, basename($path2));
@@ -476,6 +505,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function copy($path1,$path2) {
+ $this->init();
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
$result=$sourceContainer->copy_object_to(basename($path1),$targetContainer, basename($path2));
@@ -487,12 +517,12 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function stat($path) {
+ $this->init();
$container=$this->getContainer($path);
if (!is_null($container)) {
return array(
'mtime'=>-1,
'size'=>$container->bytes_used,
- 'ctime'=>-1
);
}
@@ -510,22 +540,23 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
return array(
'mtime'=>$mtime,
'size'=>$obj->content_length,
- 'ctime'=>-1,
);
}
private function getTmpFile($path) {
+ $this->init();
$obj=$this->getObject($path);
if(!is_null($obj)) {
- $tmpFile=OCP\Files::tmpFile();
+ $tmpFile=\OCP\Files::tmpFile();
$obj->save_to_filename($tmpFile);
return $tmpFile;
}else{
- return OCP\Files::tmpFile();
+ return \OCP\Files::tmpFile();
}
}
private function fromTmpFile($tmpFile,$path) {
+ $this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
$obj=$this->createObject($path);
@@ -536,7 +567,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
/**
* remove custom mtime metadata
- * @param CF_Object obj
+ * @param \CF_Object $obj
*/
private function resetMTime($obj) {
if(isset($obj->metadata['Mtime'])) {
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 74e468a2838..aafecdab672 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -6,14 +6,17 @@
* See the COPYING-README file.
*/
-class OC_FileStorage_DAV extends OC_Filestorage_Common{
+namespace OC\Files\Storage;
+
+class DAV extends \OC\Files\Storage\Common{
private $password;
private $user;
private $host;
private $secure;
private $root;
+ private $ready;
/**
- * @var Sabre_DAV_Client
+ * @var \Sabre_DAV_Client
*/
private $client;
@@ -35,6 +38,13 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
if(substr($this->root,-1,1)!='/') {
$this->root.='/';
}
+ }
+
+ private function init(){
+ if($this->ready){
+ return;
+ }
+ $this->ready = true;
$settings = array(
'baseUri' => $this->createBaseUri(),
@@ -42,7 +52,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
'password' => $this->password,
);
- $this->client = new OC_Connector_Sabre_Client($settings);
+ $this->client = new \OC_Connector_Sabre_Client($settings);
if($caview = \OCP\Files::getStorage('files_external')) {
$certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
@@ -54,6 +64,10 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->mkdir('');
}
+ public function getId(){
+ return 'webdav::' . $this->user . '@' . $this->host . '/' . $this->root;
+ }
+
private function createBaseUri() {
$baseUri='http';
if($this->secure) {
@@ -64,40 +78,44 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
public function mkdir($path) {
+ $this->init();
$path=$this->cleanPath($path);
return $this->simpleResponse('MKCOL',$path, null,201);
}
public function rmdir($path) {
+ $this->init();
$path=$this->cleanPath($path);
return $this->simpleResponse('DELETE',$path, null,204);
}
public function opendir($path) {
+ $this->init();
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array(),1);
$id=md5('webdav'.$this->root.$path);
- OC_FakeDirStream::$dirs[$id]=array();
+ \OC_FakeDirStream::$dirs[$id]=array();
$files=array_keys($response);
array_shift($files);//the first entry is the current directory
foreach($files as $file) {
$file = urldecode(basename($file));
- OC_FakeDirStream::$dirs[$id][]=$file;
+ \OC_FakeDirStream::$dirs[$id][]=$file;
}
return opendir('fakedir://'.$id);
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return false;
}
}
public function filetype($path) {
+ $this->init();
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}resourcetype'));
$responseType=$response["{DAV:}resourcetype"]->resourceType;
return (count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file';
- }catch(Exception $e) {
+ }catch(\Exception $e) {
error_log($e->getMessage());
\OCP\Util::writeLog("webdav client", \OCP\Util::sanitizeHTML($e->getMessage()), \OCP\Util::ERROR);
return false;
@@ -113,20 +131,23 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
public function file_exists($path) {
+ $this->init();
$path=$this->cleanPath($path);
try{
$this->client->propfind($path, array('{DAV:}resourcetype'));
return true;//no 404 exception
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return false;
}
}
public function unlink($path) {
- return $this->simpleResponse('DELETE',$path, null,204);
+ $this->init();
+ return $this->simpleResponse('DELETE', $path, null ,204);
}
public function fopen($path,$mode) {
+ $this->init();
$path=$this->cleanPath($path);
switch($mode) {
case 'r':
@@ -163,8 +184,8 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}else{
$ext='';
}
- $tmpFile=OCP\Files::tmpFile($ext);
- OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
+ $tmpFile=\OCP\Files::tmpFile($ext);
+ \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
if($this->file_exists($path)) {
$this->getFile($path,$tmpFile);
}
@@ -181,6 +202,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
public function free_space($path) {
+ $this->init();
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}quota-available-bytes'));
@@ -189,12 +211,13 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}else{
return 0;
}
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return 0;
}
}
public function touch($path,$mtime=null) {
+ $this->init();
if(is_null($mtime)) {
$mtime=time();
}
@@ -203,11 +226,13 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
public function getFile($path,$target) {
+ $this->init();
$source=$this->fopen($path,'r');
file_put_contents($target,$source);
}
public function uploadFile($path,$target) {
+ $this->init();
$source=fopen($path,'r');
$curl = curl_init();
@@ -222,48 +247,45 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
public function rename($path1,$path2) {
+ $this->init();
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
try{
- $response=$this->client->request('MOVE', $path1, null, array('Destination'=>$path2));
+ $this->client->request('MOVE', $path1, null, array('Destination' => $path2));
return true;
- }catch(Exception $e) {
- echo $e;
- echo 'fail';
- var_dump($response);
+ }catch(\Exception $e) {
return false;
}
}
public function copy($path1,$path2) {
+ $this->init();
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
try{
- $response=$this->client->request('COPY', $path1, null, array('Destination'=>$path2));
+ $this->client->request('COPY', $path1, null, array('Destination' => $path2));
return true;
- }catch(Exception $e) {
- echo $e;
- echo 'fail';
- var_dump($response);
+ }catch(\Exception $e) {
return false;
}
}
public function stat($path) {
+ $this->init();
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}getlastmodified','{DAV:}getcontentlength'));
return array(
'mtime'=>strtotime($response['{DAV:}getlastmodified']),
'size'=>(int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0,
- 'ctime'=>-1,
);
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return array();
}
}
public function getMimeType($path) {
+ $this->init();
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}getcontenttype','{DAV:}resourcetype'));
@@ -276,7 +298,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}else{
return false;
}
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return false;
}
}
@@ -294,7 +316,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
try{
$response=$this->client->request($method,$path,$body);
return $response['statusCode']==$expected;
- }catch(Exception $e) {
+ }catch(\Exception $e) {
return false;
}
}
diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php
index f0d76460f54..a678f345c8e 100755
--- a/apps/files_external/personal.php
+++ b/apps/files_external/personal.php
@@ -24,7 +24,7 @@ OCP\Util::addScript('files_external', 'settings');
OCP\Util::addStyle('files_external', 'settings');
$backends = OC_Mount_Config::getBackends();
// Remove local storage
-unset($backends['OC_Filestorage_Local']);
+unset($backends['\OC\Files\Storage\Local']);
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('isAdminPage', false, false);
$tmpl->assign('mounts', OC_Mount_Config::getPersonalMountPoints());
diff --git a/apps/files_external/tests/amazons3.php b/apps/files_external/tests/amazons3.php
index 725f4ba05da..9fb377af3ba 100644
--- a/apps/files_external/tests/amazons3.php
+++ b/apps/files_external/tests/amazons3.php
@@ -20,7 +20,9 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-class Test_Filestorage_AmazonS3 extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class AmazonS3 extends Storage {
private $config;
private $id;
@@ -32,12 +34,12 @@ class Test_Filestorage_AmazonS3 extends Test_FileStorage {
$this->markTestSkipped('AmazonS3 backend not configured');
}
$this->config['amazons3']['bucket'] = $id; // Make sure we have a new empty bucket to work in
- $this->instance = new OC_Filestorage_AmazonS3($this->config['amazons3']);
+ $this->instance = new \OC\Files\Storage\AmazonS3($this->config['amazons3']);
}
public function tearDown() {
if ($this->instance) {
- $s3 = new AmazonS3(array('key' => $this->config['amazons3']['key'], 'secret' => $this->config['amazons3']['secret']));
+ $s3 = new \AmazonS3(array('key' => $this->config['amazons3']['key'], 'secret' => $this->config['amazons3']['secret']));
if ($s3->delete_all_objects($this->id)) {
$s3->delete_bucket($this->id);
}
diff --git a/apps/files_external/tests/config.php b/apps/files_external/tests/config.php
index ff16b1c1d8a..65127175ad7 100644
--- a/apps/files_external/tests/config.php
+++ b/apps/files_external/tests/config.php
@@ -8,7 +8,7 @@ return array(
'root'=>'/test',
),
'webdav'=>array(
- 'run'=>false,
+ 'run'=>true,
'host'=>'localhost',
'user'=>'test',
'password'=>'test',
@@ -30,7 +30,7 @@ return array(
'root'=>'/',
),
'smb'=>array(
- 'run'=>false,
+ 'run'=>true,
'user'=>'test',
'password'=>'test',
'host'=>'localhost',
diff --git a/apps/files_external/tests/dropbox.php b/apps/files_external/tests/dropbox.php
index 56319b9f5d7..c517ef4cbb7 100644
--- a/apps/files_external/tests/dropbox.php
+++ b/apps/files_external/tests/dropbox.php
@@ -6,7 +6,9 @@
* See the COPYING-README file.
*/
-class Test_Filestorage_Dropbox extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class Dropbox extends Storage {
private $config;
public function setUp() {
@@ -16,7 +18,7 @@ class Test_Filestorage_Dropbox extends Test_FileStorage {
$this->markTestSkipped('Dropbox backend not configured');
}
$this->config['dropbox']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
- $this->instance = new OC_Filestorage_Dropbox($this->config['dropbox']);
+ $this->instance = new \OC\Files\Storage\Dropbox($this->config['dropbox']);
}
public function tearDown() {
diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/ftp.php
index 4549c420410..3e6208e4a0d 100644
--- a/apps/files_external/tests/ftp.php
+++ b/apps/files_external/tests/ftp.php
@@ -6,7 +6,9 @@
* See the COPYING-README file.
*/
-class Test_Filestorage_FTP extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class FTP extends Storage {
private $config;
public function setUp() {
@@ -16,12 +18,12 @@ class Test_Filestorage_FTP extends Test_FileStorage {
$this->markTestSkipped('FTP backend not configured');
}
$this->config['ftp']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
- $this->instance = new OC_Filestorage_FTP($this->config['ftp']);
+ $this->instance = new \OC\Files\Storage\FTP($this->config['ftp']);
}
public function tearDown() {
if ($this->instance) {
- OCP\Files::rmdirr($this->instance->constructUrl(''));
+ \OCP\Files::rmdirr($this->instance->constructUrl(''));
}
}
}
diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/google.php
index 46e622cc180..87b3ae4e4cc 100644
--- a/apps/files_external/tests/google.php
+++ b/apps/files_external/tests/google.php
@@ -20,8 +20,9 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-class Test_Filestorage_Google extends Test_FileStorage {
+namespace Test\Files\Storage;
+class Google extends Storage {
private $config;
public function setUp() {
@@ -31,7 +32,7 @@ class Test_Filestorage_Google extends Test_FileStorage {
$this->markTestSkipped('Google backend not configured');
}
$this->config['google']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
- $this->instance = new OC_Filestorage_Google($this->config['google']);
+ $this->instance = new \OC\Files\Storage\Google($this->config['google']);
}
public function tearDown() {
diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php
index 2c03ef5dbd0..b4ac6db1187 100644
--- a/apps/files_external/tests/smb.php
+++ b/apps/files_external/tests/smb.php
@@ -6,7 +6,10 @@
* See the COPYING-README file.
*/
-class Test_Filestorage_SMB extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class SMB extends Storage {
+
private $config;
public function setUp() {
@@ -16,12 +19,12 @@ class Test_Filestorage_SMB extends Test_FileStorage {
$this->markTestSkipped('Samba backend not configured');
}
$this->config['smb']['root'] .= $id; //make sure we have an new empty folder to work in
- $this->instance = new OC_Filestorage_SMB($this->config['smb']);
+ $this->instance = new \OC\Files\Storage\SMB($this->config['smb']);
}
public function tearDown() {
if ($this->instance) {
- OCP\Files::rmdirr($this->instance->constructUrl(''));
+ \OCP\Files::rmdirr($this->instance->constructUrl(''));
}
}
}
diff --git a/apps/files_external/tests/swift.php b/apps/files_external/tests/swift.php
index 8cf2a3abc76..4899d44acad 100644
--- a/apps/files_external/tests/swift.php
+++ b/apps/files_external/tests/swift.php
@@ -6,7 +6,9 @@
* See the COPYING-README file.
*/
-class Test_Filestorage_SWIFT extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class SWIFT extends Storage {
private $config;
public function setUp() {
@@ -16,7 +18,7 @@ class Test_Filestorage_SWIFT extends Test_FileStorage {
$this->markTestSkipped('OpenStack SWIFT backend not configured');
}
$this->config['swift']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
- $this->instance = new OC_Filestorage_SWIFT($this->config['swift']);
+ $this->instance = new \OC\Files\Storage\SWIFT($this->config['swift']);
}
diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/webdav.php
index 2da88f63edd..13e3be42948 100644
--- a/apps/files_external/tests/webdav.php
+++ b/apps/files_external/tests/webdav.php
@@ -6,7 +6,10 @@
* See the COPYING-README file.
*/
-class Test_Filestorage_DAV extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class DAV extends Storage {
+
private $config;
public function setUp() {
@@ -16,7 +19,7 @@ class Test_Filestorage_DAV extends Test_FileStorage {
$this->markTestSkipped('WebDAV backend not configured');
}
$this->config['webdav']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
- $this->instance = new OC_Filestorage_DAV($this->config['webdav']);
+ $this->instance = new \OC\Files\Storage\DAV($this->config['webdav']);
}
public function tearDown() {
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 109f86b2e87..210c78ad174 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -2,8 +2,8 @@
OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php";
OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php';
-OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/lib/sharedstorage.php";
-OCP\Util::connectHook('OC_Filesystem', 'setup', 'OC_Filestorage_Shared', 'setup');
+OC::$CLASSPATH['OC\Files\Storage\Shared'] = "apps/files_sharing/lib/sharedstorage.php";
+OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
OCP\Util::addScript('files_sharing', 'share');
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php
index e75c538b150..51048bd178c 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -10,6 +10,7 @@ if (version_compare($installedVersion, '0.3', '<')) {
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
while ($row = $result->fetchRow()) {
+ $meta = \OC\Files\Filesystem::getId($path, '');
$itemSource = OC_FileCache::getId($row['source'], '');
if ($itemSource != -1) {
$file = OC_FileCache::get($row['source'], '');
@@ -70,4 +71,4 @@ if (version_compare($installedVersion, '0.3.3', '<')) {
foreach ($users as $user) {
OC_FileCache::delete('Shared', '/'.$user.'/files/');
}
-} \ No newline at end of file
+}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 7271dcc930b..f40bb95b659 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -20,10 +20,12 @@
*
*/
+namespace OC\Files\Storage;
+
/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
-class OC_Filestorage_Shared extends OC_Filestorage_Common {
+class Shared extends \OC\Files\Storage\Common {
private $sharedFolder;
private $files = array();
@@ -35,7 +37,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
/**
* @brief Get the source file path and the permissions granted for a shared file
* @param string Shared target file path
- * @return Returns array with the keys path and permissions or false if not found
+ * @return array with the keys path and permissions or false if not found
*/
private function getFile($target) {
$target = '/'.$target;
@@ -50,7 +52,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if (isset($this->files[$folder])) {
$file = $this->files[$folder];
} else {
- $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ $file = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
}
if ($file) {
$this->files[$target]['path'] = $file['path'].substr($target, strlen($folder));
@@ -58,13 +60,13 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return $this->files[$target];
}
} else {
- $file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ $file = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
if ($file) {
$this->files[$target] = $file;
return $this->files[$target];
}
}
- OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR);
+ \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR);
return false;
}
}
@@ -72,13 +74,13 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
/**
* @brief Get the source file path for a shared file
* @param string Shared target file path
- * @return Returns source file path or false if not found
+ * @return string source file path or false if not found
*/
private function getSourcePath($target) {
$file = $this->getFile($target);
if (isset($file['path'])) {
$uid = substr($file['path'], 1, strpos($file['path'], '/', 1) - 1);
- OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => OC_User::getHome($uid)), $uid);
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => \OC_User::getHome($uid)), $uid);
return $file['path'];
}
return false;
@@ -87,9 +89,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
/**
* @brief Get the permissions granted for a shared file
* @param string Shared target file path
- * @return Returns CRUDS permissions granted or false if not found
+ * @return int CRUDS permissions granted or false if not found
*/
- private function getPermissions($target) {
+ public function getPermissions($target) {
$file = $this->getFile($target);
if (isset($file['permissions'])) {
return $file['permissions'];
@@ -97,19 +99,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return false;
}
- /**
- * @brief Get the internal path to pass to the storage filesystem call
- * @param string Source file path
- * @return Source file path with mount point stripped out
- */
- private function getInternalPath($path) {
- $mountPoint = OC_Filesystem::getMountPoint($path);
- $internalPath = substr($path, strlen($mountPoint));
- return $internalPath;
- }
-
public function getOwner($target) {
- $shared_item = OCP\Share::getItemSharedWith('folder', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ $shared_item = \OCP\Share::getItemSharedWith('folder', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
if ($shared_item) {
return $shared_item[0]["uid_owner"];
}
@@ -120,28 +111,28 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
return false;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->mkdir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->mkdir($internalPath);
}
return false;
}
public function rmdir($path) {
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->rmdir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->rmdir($internalPath);
}
return false;
}
public function opendir($path) {
if ($path == '' || $path == '/') {
- $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR);
- OC_FakeDirStream::$dirs['shared'] = $files;
+ $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR);
+ \OC_FakeDirStream::$dirs['shared'] = $files;
return opendir('fakedir://shared');
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->opendir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->opendir($internalPath);
}
return false;
}
@@ -150,16 +141,16 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_dir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->is_dir($internalPath);
}
return false;
}
public function is_file($path) {
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_file($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->is_file($internalPath);
}
return false;
}
@@ -168,11 +159,10 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/') {
$stat['size'] = $this->filesize($path);
$stat['mtime'] = $this->filemtime($path);
- $stat['ctime'] = $this->filectime($path);
return $stat;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->stat($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->stat($internalPath);
}
return false;
}
@@ -181,8 +171,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filetype($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filetype($internalPath);
}
return false;
}
@@ -191,8 +181,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/' || $this->is_dir($path)) {
return 0;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filesize($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filesize($internalPath);
}
return false;
}
@@ -201,7 +191,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE);
+ return ($this->getPermissions($path) & \OCP\Share::PERMISSION_CREATE);
}
public function isReadable($path) {
@@ -212,54 +202,33 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE);
+ return ($this->getPermissions($path) & \OCP\Share::PERMISSION_UPDATE);
}
public function isDeletable($path) {
if ($path == '') {
return true;
}
- return ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE);
+ return ($this->getPermissions($path) & \OCP\Share::PERMISSION_DELETE);
}
public function isSharable($path) {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\Share::PERMISSION_SHARE);
+ return ($this->getPermissions($path) & \OCP\Share::PERMISSION_SHARE);
}
public function file_exists($path) {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_exists($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->file_exists($internalPath);
}
return false;
}
- public function filectime($path) {
- if ($path == '' || $path == '/') {
- $ctime = 0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- $tempctime = $this->filectime($filename);
- if ($tempctime < $ctime) {
- $ctime = $tempctime;
- }
- }
- }
- return $ctime;
- } else {
- $source = $this->getSourcePath($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filectime($this->getInternalPath($source));
- }
- }
- }
-
public function filemtime($path) {
if ($path == '' || $path == '/') {
$mtime = 0;
@@ -275,8 +244,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
} else {
$source = $this->getSourcePath($path);
if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filemtime($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filemtime($internalPath);
}
}
}
@@ -288,9 +257,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
'target' => $this->sharedFolder.$path,
'source' => $source,
);
- OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_get_contents($this->getInternalPath($source));
+ \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->file_get_contents($internalPath);
}
}
@@ -304,9 +273,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
'target' => $this->sharedFolder.$path,
'source' => $source,
);
- OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->file_put_contents($this->getInternalPath($source), $data);
+ \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ $result = $storage->file_put_contents($internalPath, $data);
return $result;
}
return false;
@@ -316,8 +285,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
// Delete the file if DELETE permission is granted
if ($source = $this->getSourcePath($path)) {
if ($this->isDeletable($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->unlink($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->unlink($internalPath);
} else if (dirname($path) == '/' || dirname($path) == '.') {
// Unshare the file from the user if in the root of the Shared folder
if ($this->is_dir($path)) {
@@ -325,7 +294,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
} else {
$itemType = 'file';
}
- return OCP\Share::unshareFromSelf($itemType, $path);
+ return \OCP\Share::unshareFromSelf($itemType, $path);
}
}
return false;
@@ -340,8 +309,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if (dirname($path1) == dirname($path2)) {
// Rename the file if UPDATE permission is granted
if ($this->isUpdatable($path1)) {
- $storage = OC_Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ list($storage, $oldInternalPath)=\OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath)=\OC\Files\Filesystem::resolvePath($newSource);
+ return $storage->rename($oldInternalPath, $newInternalPath);
}
} else {
// Move the file if DELETE and CREATE permissions are granted
@@ -355,8 +325,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return $this->unlink($path1);
}
} else {
- $storage = OC_Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ list($storage, $oldInternalPath)=\OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath)=\OC\Files\Filesystem::resolvePath($newSource);
+ return $storage->rename($oldInternalPath, $newInternalPath);
}
}
}
@@ -369,7 +340,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($this->isCreatable(dirname($path2))) {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
- return OC_Helper::streamCopy($source, $target);
+ return \OC_Helper::streamCopy($source, $target);
}
return false;
}
@@ -400,9 +371,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
'source' => $source,
'mode' => $mode,
);
- OCP\Util::emitHook('OC_Filestorage_Shared', 'fopen', $info);
- $storage = OC_Filesystem::getStorage($source);
- return $storage->fopen($this->getInternalPath($source), $mode);
+ \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->fopen($internalPath, $mode);
}
return false;
}
@@ -412,8 +383,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return 'httpd/unix-directory';
}
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->getMimeType($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->getMimeType($internalPath);
}
return false;
}
@@ -421,29 +392,29 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
public function free_space($path) {
$source = $this->getSourcePath($path);
if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->free_space($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->free_space($internalPath);
}
}
public function getLocalFile($path) {
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->getLocalFile($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->getLocalFile($internalPath);
}
return false;
}
public function touch($path, $mtime = null) {
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->touch($this->getInternalPath($source), $mtime);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->touch($internalPath, $mtime);
}
return false;
}
public static function setup($options) {
$user_dir = $options['user_dir'];
- OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
}
/**
@@ -455,4 +426,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
//TODO
return false;
}
+
+ public function getId(){
+ return 'shared::' . $this->sharedFolder;
+ }
}
diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php
index 822103ebc32..bc3a7fda9f7 100644
--- a/apps/files_versions/lib/hooks.php
+++ b/apps/files_versions/lib/hooks.php
@@ -21,9 +21,9 @@ class Hooks {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
- $versions = new Storage( new \OC_FilesystemView('') );
+ $versions = new Storage( new \OC\Files\View('') );
- $path = $params[\OC_Filesystem::signal_param_path];
+ $path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') $versions->store( $path );
diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php
index 56878b470d1..47e514d9d7e 100644
--- a/apps/files_versions/lib/versions.php
+++ b/apps/files_versions/lib/versions.php
@@ -58,9 +58,10 @@ class Storage {
public function store($filename) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
+
$userHome = \OC_User::getHome($uid);
- $files_view = new \OC_FilesystemView($userHome.'/files');
- $users_view = new \OC_FilesystemView($userHome);
+ $files_view = new \OC\Files\View($userHome.'/files');
+ $users_view = new \OC\Files\View($userHome);
//check if source file already exist as version to avoid recursions.
// todo does this check work?
@@ -95,7 +96,7 @@ class Storage {
// check mininterval if the file is being modified by the owner (all shared files should be versioned despite mininterval)
if ($uid == \OCP\User::getUser()) {
- $versions_fileview = new \OC_FilesystemView($userHome.'/files_versions');
+ $versions_fileview = new \OC\Files\View($userHome.'/files_versions');
$versionsFolderName=\OCP\Config::getSystemValue('datadirectory'). $versions_fileview->getAbsolutePath('');
$matches=glob($versionsFolderName.'/'.$filename.'.v*');
sort($matches);
@@ -128,7 +129,7 @@ class Storage {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
- $users_view = new \OC_FilesystemView(\OC_User::getHome($uid));
+ $users_view = new \OC\Files\View(\OC_User::getHome($uid));
// rollback
if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) {
@@ -151,7 +152,7 @@ class Storage {
public static function isversioned($filename) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
- $versions_fileview = new \OC_FilesystemView(\OC_User::getHome($uid).'/files_versions');
+ $versions_fileview = new \OC\Files\View(\OC_User::getHome($uid).'/files_versions');
$versionsFolderName=\OCP\Config::getSystemValue('datadirectory'). $versions_fileview->getAbsolutePath('');
@@ -179,7 +180,7 @@ class Storage {
if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
list($uid, $filename) = self::getUidAndFilename($filename);
- $versions_fileview = new \OC_FilesystemView(\OC_User::getHome($uid).'/files_versions');
+ $versions_fileview = new \OC\Files\View(\OC_User::getHome($uid).'/files_versions');
$versionsFolderName = \OCP\Config::getSystemValue('datadirectory'). $versions_fileview->getAbsolutePath('');
$versions = array();
@@ -191,7 +192,7 @@ class Storage {
$i = 0;
- $files_view = new \OC_FilesystemView(\OC_User::getHome($uid).'/files');
+ $files_view = new \OC\Files\View(\OC_User::getHome($uid).'/files');
$local_file = $files_view->getLocalFile($filename);
foreach( $matches as $ma ) {
@@ -246,7 +247,7 @@ class Storage {
public static function expire($filename) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
- $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions');
+ $versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions');
$versionsFolderName=\OCP\Config::getSystemValue('datadirectory'). $versions_fileview->getAbsolutePath('');
diff --git a/db_structure.xml b/db_structure.xml
index 99a30cb6137..e420a9f0e44 100644
--- a/db_structure.xml
+++ b/db_structure.xml
@@ -53,20 +53,28 @@
<table>
- <name>*dbprefix*fscache</name>
+ <name>*dbprefix*filecache</name>
<declaration>
<field>
- <name>id</name>
- <autoincrement>1</autoincrement>
+ <name>fileid</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
+ <autoincrement>1</autoincrement>
<length>4</length>
</field>
<field>
+ <name>storage</name>
+ <type>text</type>
+ <default></default>
+ <notnull>true</notnull>
+ <length>64</length>
+ </field>
+
+ <field>
<name>path</name>
<type>text</type>
<default></default>
@@ -85,49 +93,17 @@
<field>
<name>parent</name>
<type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <length>8</length>
- </field>
-
- <field>
- <name>name</name>
- <type>text</type>
<default></default>
<notnull>true</notnull>
- <length>300</length>
+ <length>4</length>
</field>
<field>
- <name>user</name>
+ <name>name</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
- <length>64</length>
- </field>
-
- <field>
- <name>size</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <length>8</length>
- </field>
-
- <field>
- <name>ctime</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <length>8</length>
- </field>
-
- <field>
- <name>mtime</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <length>8</length>
+ <length>250</length>
</field>
<field>
@@ -135,7 +111,7 @@
<type>text</type>
<default></default>
<notnull>true</notnull>
- <length>96</length>
+ <length>64</length>
</field>
<field>
@@ -147,31 +123,36 @@
</field>
<field>
- <name>encrypted</name>
+ <name>size</name>
<type>integer</type>
- <default>0</default>
+ <default></default>
<notnull>true</notnull>
- <length>1</length>
+ <length>4</length>
</field>
<field>
- <name>versioned</name>
+ <name>mtime</name>
<type>integer</type>
- <default>0</default>
+ <default></default>
<notnull>true</notnull>
- <length>1</length>
+ <length>4</length>
</field>
<field>
- <name>writable</name>
+ <name>encrypted</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
- <length>1</length>
+ <length>4</length>
</field>
<index>
- <name>fscache_path_hash_index</name>
+ <name>storage_path_hash</name>
+ <unique>true</unique>
+ <field>
+ <name>storage</name>
+ <sorting>ascending</sorting>
+ </field>
<field>
<name>path_hash</name>
<sorting>ascending</sorting>
@@ -179,29 +160,60 @@
</index>
<index>
- <name>parent_index</name>
+ <name>parent_name_hash</name>
<field>
<name>parent</name>
<sorting>ascending</sorting>
</field>
- </index>
-
- <index>
- <name>name_index</name>
<field>
<name>name</name>
<sorting>ascending</sorting>
</field>
</index>
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>*dbprefix*permissions</name>
+
+ <declaration>
+
+ <field>
+ <name>fileid</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>user</name>
+ <type>text</type>
+ <default></default>
+ <notnull>true</notnull>
+ <length>64</length>
+ </field>
+
+ <field>
+ <name>permissions</name>
+ <type>integer</type>
+ <default>0</default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
<index>
- <name>parent_name_index</name>
+ <name>id_user_index</name>
+ <unique>true</unique>
<field>
- <name>parent</name>
+ <name>fileid</name>
<sorting>ascending</sorting>
</field>
<field>
- <name>name</name>
+ <name>user</name>
<sorting>ascending</sorting>
</field>
</index>
diff --git a/lib/app.php b/lib/app.php
index c9329df91d1..8f5b5fe78f9 100755
--- a/lib/app.php
+++ b/lib/app.php
@@ -714,16 +714,16 @@ class OC_App{
/**
* @param string $appid
- * @return OC_FilesystemView
+ * @return \OC\Files\View
*/
public static function getStorage($appid) {
if(OC_App::isEnabled($appid)) {//sanity check
if(OC_User::isLoggedIn()) {
- $view = new OC_FilesystemView('/'.OC_User::getUser());
+ $view = new \OC\Files\View('/'.OC_User::getUser());
if(!$view->file_exists($appid)) {
$view->mkdir($appid);
}
- return new OC_FilesystemView('/'.OC_User::getUser().'/'.$appid);
+ return new \OC\Files\View('/'.OC_User::getUser().'/'.$appid);
}else{
OC_Log::write('core', 'Can\'t get app storage, app, user not logged in', OC_Log::ERROR);
return false;
diff --git a/lib/base.php b/lib/base.php
index 186ed53e980..778f0fe7326 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -84,6 +84,9 @@ class OC{
elseif(strpos($className, 'OC_')===0) {
$path = strtolower(str_replace('_', '/', substr($className, 3)) . '.php');
}
+ elseif(strpos($className, 'OC\\')===0) {
+ $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
+ }
elseif(strpos($className, 'OCP\\')===0) {
$path = 'public/'.strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
}
@@ -95,6 +98,9 @@ class OC{
}
elseif(strpos($className, 'Test_')===0) {
$path = 'tests/lib/'.strtolower(str_replace('_', '/', substr($className, 5)) . '.php');
+ }
+ elseif(strpos($className, 'Test\\')===0) {
+ $path = 'tests/lib/'.strtolower(str_replace('\\', '/', substr($className, 5)) . '.php');
}else{
return false;
}
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 27d8b19f36e..f9ecf41dcac 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -15,11 +15,11 @@ class OC_Cache_File{
}
if(OC_User::isLoggedIn()) {
$subdir = 'cache';
- $view = new OC_FilesystemView('/'.OC_User::getUser());
+ $view = new \OC\Files\View('/'.OC_User::getUser());
if(!$view->file_exists($subdir)) {
$view->mkdir($subdir);
}
- $this->storage = new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir);
+ $this->storage = new \OC\Files\View('/'.OC_User::getUser().'/'.$subdir);
return $this->storage;
}else{
OC_Log::write('core', 'Can\'t get cache storage, user not logged in', OC_Log::ERROR);
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index b6e02569d2a..d4f58527d21 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -62,7 +62,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
}
} else {
$newPath = $this->path . '/' . $name;
- OC_Filesystem::file_put_contents($newPath, $data);
+ \OC\Files\Filesystem::file_put_contents($newPath, $data);
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
@@ -78,7 +78,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
public function createDirectory($name) {
$newPath = $this->path . '/' . $name;
- OC_Filesystem::mkdir($newPath);
+ \OC\Files\Filesystem::mkdir($newPath);
}
@@ -93,7 +93,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
$path = $this->path . '/' . $name;
if (is_null($info)) {
- $info = OC_Files::getFileInfo($path);
+ $info = \OC\Files\Filesystem::getFileInfo($path);
}
if (!$info) {
@@ -117,7 +117,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/
public function getChildren() {
- $folder_content = OC_Files::getDirectoryContent($this->path);
+ $folder_content = \OC\Files\Filesystem::getDirectoryContent($this->path);
$paths = array();
foreach($folder_content as $info) {
$paths[] = $this->path.'/'.$info['name'];
@@ -154,7 +154,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
public function childExists($name) {
$path = $this->path . '/' . $name;
- return OC_Filesystem::file_exists($path);
+ return \OC\Files\Filesystem::file_exists($path);
}
@@ -167,7 +167,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
if ($this->path != "/Shared") {
foreach($this->getChildren() as $child) $child->delete();
- OC_Filesystem::rmdir($this->path);
+ \OC\Files\Filesystem::rmdir($this->path);
}
}
@@ -178,10 +178,10 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* @return array
*/
public function getQuotaInfo() {
- $rootInfo=OC_FileCache_Cached::get('');
+ $rootInfo=\OC\Files\Filesystem::getFileInfo('');
return array(
$rootInfo['size'],
- OC_Filesystem::free_space()
+ \OC\Files\Filesystem::free_space()
);
}
diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php
index 5bd38240d44..1770b491280 100644
--- a/lib/connector/sabre/file.php
+++ b/lib/connector/sabre/file.php
@@ -45,7 +45,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function put($data) {
- OC_Filesystem::file_put_contents($this->path,$data);
+ \OC\Files\Filesystem::file_put_contents($this->path,$data);
return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
}
@@ -57,7 +57,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function get() {
- return OC_Filesystem::fopen($this->path,'rb');
+ return \OC\Files\Filesystem::fopen($this->path,'rb');
}
@@ -68,7 +68,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function delete() {
- OC_Filesystem::unlink($this->path);
+ \OC\Files\Filesystem::unlink($this->path);
}
@@ -107,7 +107,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
* @return string|null Returns null if the ETag can not effectively be determined
*/
static protected function createETag($path) {
- return OC_Filesystem::hash('md5', $path);
+ return \OC\Files\Filesystem::hash('md5', $path);
}
/**
@@ -122,7 +122,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
return $this->fileinfo_cache['mimetype'];
}
- return OC_Filesystem::getMimeType($this->path);
+ return \OC\Files\Filesystem::getMimeType($this->path);
}
}
diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php
index 72de9723774..2095c956e5f 100644
--- a/lib/connector/sabre/node.php
+++ b/lib/connector/sabre/node.php
@@ -80,7 +80,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
$newPath = $parentPath . '/' . $newName;
$oldPath = $this->path;
- OC_Filesystem::rename($this->path,$newPath);
+ \OC\Files\Filesystem::rename($this->path,$newPath);
$this->path = $newPath;
@@ -95,13 +95,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
}
/**
- * Make sure the fileinfo cache is filled. Uses OC_FileCache or a direct stat
+ * Make sure the fileinfo cache is filled. Uses the file cache or a direct stat
*/
protected function getFileinfoCache() {
if (!isset($this->fileinfo_cache)) {
- if ($fileinfo_cache = OC_FileCache::get($this->path)) {
+ if ($fileinfo_cache = \OC\Files\Filesystem::getFileInfo($this->path)) {
} else {
- $fileinfo_cache = OC_Filesystem::stat($this->path);
+ $fileinfo_cache = \OC\Files\Filesystem::stat($this->path);
}
$this->fileinfo_cache = $fileinfo_cache;
@@ -130,7 +130,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
* Even if the modification time is set to a custom value the access time is set to now.
*/
public function touch($mtime) {
- OC_Filesystem::touch($this->path, $mtime);
+ \OC\Files\Filesystem::touch($this->path, $mtime);
}
/**
diff --git a/lib/filecache.php b/lib/filecache.php
deleted file mode 100644
index fee3b398251..00000000000
--- a/lib/filecache.php
+++ /dev/null
@@ -1,518 +0,0 @@
-<?php
-
-/**
-* @author Robin Appelman
-* @copyright 2011 Robin Appelman icewind1991@gmail.com
-*
-* 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/>.
-*
-*/
-
-/**
- * provide caching for filesystem info in the database
- *
- * not used by OC_Filesystem for reading filesystem info,
- * instread apps should use OC_FileCache::get where possible
- *
- * It will try to keep the data up to date but changes from outside ownCloud can invalidate the cache
- */
-class OC_FileCache{
- /**
- * get the filesystem info from the cache
- * @param string path
- * @param string root (optional)
- * @return array
- *
- * returns an associative array with the following keys:
- * - size
- * - mtime
- * - ctime
- * - mimetype
- * - encrypted
- * - versioned
- */
- public static function get($path,$root=false) {
- if(OC_FileCache_Update::hasUpdated($path, $root)) {
- if($root===false) {//filesystem hooks are only valid for the default root
- OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$path));
- }else{
- OC_FileCache_Update::update($path, $root);
- }
- }
- return OC_FileCache_Cached::get($path, $root);
- }
-
- /**
- * put filesystem info in the cache
- * @param string $path
- * @param array data
- * @param string root (optional)
- *
- * $data is an assiciative array in the same format as returned by get
- */
- public static function put($path,$data,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- $fullpath=OC_Filesystem::normalizePath($root.'/'.$path);
- $parent=self::getParentId($fullpath);
- $id=self::getId($fullpath, '');
- if(isset(OC_FileCache_Cached::$savedData[$fullpath])) {
- $data=array_merge(OC_FileCache_Cached::$savedData[$fullpath], $data);
- unset(OC_FileCache_Cached::$savedData[$fullpath]);
- }
- if($id!=-1) {
- self::update($id, $data);
- return;
- }
-
- // add parent directory to the file cache if it does not exist yet.
- if ($parent == -1 && $fullpath != $root) {
- $parentDir = dirname($path);
- self::scanFile($parentDir);
- $parent = self::getParentId($fullpath);
- }
-
- if(!isset($data['size']) or !isset($data['mtime'])) {//save incomplete data for the next time we write it
- OC_FileCache_Cached::$savedData[$fullpath]=$data;
- return;
- }
- if(!isset($data['encrypted'])) {
- $data['encrypted']=false;
- }
- if(!isset($data['versioned'])) {
- $data['versioned']=false;
- }
- $mimePart=dirname($data['mimetype']);
- $data['size']=(int)$data['size'];
- $data['ctime']=(int)$data['mtime'];
- $data['writable']=(int)$data['writable'];
- $data['encrypted']=(int)$data['encrypted'];
- $data['versioned']=(int)$data['versioned'];
- $user=OC_User::getUser();
- $query=OC_DB::prepare('INSERT INTO `*PREFIX*fscache`(`parent`, `name`, `path`, `path_hash`, `size`, `mtime`, `ctime`, `mimetype`, `mimepart`,`user`,`writable`,`encrypted`,`versioned`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
- $result=$query->execute(array($parent, basename($fullpath), $fullpath, md5($fullpath), $data['size'], $data['mtime'], $data['ctime'], $data['mimetype'], $mimePart, $user, $data['writable'], $data['encrypted'], $data['versioned']));
- if(OC_DB::isError($result)) {
- OC_Log::write('files', 'error while writing file('.$fullpath.') to cache', OC_Log::ERROR);
- }
-
- if($cache=OC_Cache::getUserCache(true)) {
- $cache->remove('fileid/'.$fullpath);//ensure we don't have -1 cached
- }
- }
-
- /**
- * update filesystem info of a file
- * @param int $id
- * @param array $data
- */
- private static function update($id,$data) {
- $arguments=array();
- $queryParts=array();
- foreach(array('size','mtime','ctime','mimetype','encrypted','versioned','writable') as $attribute) {
- if(isset($data[$attribute])) {
- //Convert to int it args are false
- if($data[$attribute] === false) {
- $arguments[] = 0;
- }else{
- $arguments[] = $data[$attribute];
- }
- $queryParts[]='`'.$attribute.'`=?';
- }
- }
- if(isset($data['mimetype'])) {
- $arguments[]=dirname($data['mimetype']);
- $queryParts[]='`mimepart`=?';
- }
- $arguments[]=$id;
-
- $sql = 'UPDATE `*PREFIX*fscache` SET '.implode(' , ', $queryParts).' WHERE `id`=?';
- $query=OC_DB::prepare($sql);
- $result=$query->execute($arguments);
- if(OC_DB::isError($result)) {
- OC_Log::write('files', 'error while updating file('.$id.') in cache', OC_Log::ERROR);
- }
- }
-
- /**
- * register a file move in the cache
- * @param string oldPath
- * @param string newPath
- * @param string root (optional)
- */
- public static function move($oldPath,$newPath,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- // If replacing an existing file, delete the file
- if (self::inCache($newPath, $root)) {
- self::delete($newPath, $root);
- }
- $oldPath=$root.$oldPath;
- $newPath=$root.$newPath;
- $newParent=self::getParentId($newPath);
- $query=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `parent`=? ,`name`=?, `path`=?, `path_hash`=? WHERE `path_hash`=?');
- $query->execute(array($newParent, basename($newPath), $newPath, md5($newPath), md5($oldPath)));
-
- if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$oldPath)) {
- $cache->set('fileid/'.$newPath, $cache->get('fileid/'.$oldPath));
- $cache->remove('fileid/'.$oldPath);
- }
-
- $query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `path` LIKE ?');
- $oldLength=strlen($oldPath);
- $updateQuery=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `path`=?, `path_hash`=? WHERE `path_hash`=?');
- while($row= $query->execute(array($oldPath.'/%'))->fetchRow()) {
- $old=$row['path'];
- $new=$newPath.substr($old, $oldLength);
- $updateQuery->execute(array($new, md5($new), md5($old)));
-
- if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$old)) {
- $cache->set('fileid/'.$new, $cache->get('fileid/'.$old));
- $cache->remove('fileid/'.$old);
- }
- }
- }
-
- /**
- * delete info from the cache
- * @param string path
- * @param string root (optional)
- */
- public static function delete($path,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `path_hash`=?');
- $query->execute(array(md5($root.$path)));
-
- //delete everything inside the folder
- $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `path` LIKE ?');
- $query->execute(array($root.$path.'/%'));
-
- OC_Cache::remove('fileid/'.$root.$path);
- }
-
- /**
- * return array of filenames matching the querty
- * @param string $query
- * @param boolean $returnData
- * @param string root (optional)
- * @return array of filepaths
- */
- public static function search($search,$returnData=false,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- $rootLen=strlen($root);
- if(!$returnData) {
- $select = '`path`';
- }else{
- $select = '*';
- }
- if (OC_Config::getValue('dbtype') === 'oci8') {
- $where = 'LOWER(`name`) LIKE LOWER(?) AND `user`=?';
- } else {
- $where = '`name` LIKE ? AND `user`=?';
- }
- $query=OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*fscache` WHERE '.$where);
- $result=$query->execute(array("%$search%",OC_User::getUser()));
- $names=array();
- while($row=$result->fetchRow()) {
- if(!$returnData) {
- $names[]=substr($row['path'], $rootLen);
- }else{
- $row['path']=substr($row['path'], $rootLen);
- $names[]=$row;
- }
- }
- return $names;
- }
-
- /**
- * get all files and folders in a folder
- * @param string path
- * @param string root (optional)
- * @return array
- *
- * returns an array of assiciative arrays with the following keys:
- * - name
- * - size
- * - mtime
- * - ctime
- * - mimetype
- * - encrypted
- * - versioned
- */
- public static function getFolderContent($path,$root=false,$mimetype_filter='') {
- if(OC_FileCache_Update::hasUpdated($path, $root, true)) {
- OC_FileCache_Update::updateFolder($path, $root);
- }
- return OC_FileCache_Cached::getFolderContent($path, $root, $mimetype_filter);
- }
-
- /**
- * check if a file or folder is in the cache
- * @param string $path
- * @param string root (optional)
- * @return bool
- */
- public static function inCache($path,$root=false) {
- return self::getId($path, $root)!=-1;
- }
-
- /**
- * get the file id as used in the cache
- * @param string path
- * @param string root (optional)
- * @return int
- */
- public static function getId($path,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
-
- $fullPath=$root.$path;
- if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$fullPath)) {
- return $cache->get('fileid/'.$fullPath);
- }
-
- $query=OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `path_hash`=?');
- $result=$query->execute(array(md5($fullPath)));
- if(OC_DB::isError($result)) {
- OC_Log::write('files', 'error while getting file id of '.$path, OC_Log::ERROR);
- return -1;
- }
-
- $result=$result->fetchRow();
- if(is_array($result)) {
- $id=$result['id'];
- }else{
- $id=-1;
- }
- if($cache=OC_Cache::getUserCache(true)) {
- $cache->set('fileid/'.$fullPath, $id);
- }
-
- return $id;
- }
-
- /**
- * get the file path from the id, relative to the home folder of the user
- * @param int id
- * @param string user (optional)
- * @return string
- */
- public static function getPath($id,$user='') {
- if(!$user) {
- $user=OC_User::getUser();
- }
- $query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `id`=? AND `user`=?');
- $result=$query->execute(array($id, $user));
- $row=$result->fetchRow();
- $path=$row['path'];
- $root='/'.$user.'/files';
- if(substr($path, 0, strlen($root))!=$root) {
- return false;
- }
- return substr($path, strlen($root));
- }
-
- /**
- * get the file id of the parent folder, taking into account '/' has no parent
- * @param string $path
- * @return int
- */
- private static function getParentId($path) {
- if($path=='/') {
- return -1;
- }else{
- return self::getId(dirname($path), '');
- }
- }
-
- /**
- * adjust the size of the parent folders
- * @param string $path
- * @param int $sizeDiff
- * @param string root (optinal)
- */
- public static function increaseSize($path,$sizeDiff, $root=false) {
- if($sizeDiff==0) return;
- $id=self::getId($path, $root);
- while($id!=-1) {//walk up the filetree increasing the size of all parent folders
- $query=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `size`=`size`+? WHERE `id`=?');
- $query->execute(array($sizeDiff,$id));
- $id=self::getParentId($path);
- $path=dirname($path);
- }
- }
-
- /**
- * recursively scan the filesystem and fill the cache
- * @param string $path
- * @param OC_EventSource $enventSource (optional)
- * @param int count (optional)
- * @param string root (optional)
- */
- public static function scan($path,$eventSource=false,&$count=0,$root=false) {
- if($eventSource) {
- $eventSource->send('scanning', array('file'=>$path, 'count'=>$count));
- }
- $lastSend=$count;
- // NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache)
- if (substr($path, 0, 7) == '/Shared') {
- return;
- }
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
- self::scanFile($path, $root);
- $dh=$view->opendir($path.'/');
- $totalSize=0;
- if($dh) {
- while (($filename = readdir($dh)) !== false) {
- if($filename != '.' and $filename != '..') {
- $file=$path.'/'.$filename;
- if($view->is_dir($file.'/')) {
- self::scan($file, $eventSource, $count, $root);
- }else{
- $totalSize+=self::scanFile($file, $root);
- $count++;
- if($count>$lastSend+25 and $eventSource) {
- $lastSend=$count;
- $eventSource->send('scanning', array('file'=>$path, 'count'=>$count));
- }
- }
- }
- }
- }
-
- OC_FileCache_Update::cleanFolder($path,$root);
- self::increaseSize($path,$totalSize,$root);
- }
-
- /**
- * scan a single file
- * @param string path
- * @param string root (optional)
- * @return int size of the scanned file
- */
- public static function scanFile($path,$root=false) {
- // NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache)
- if (substr($path, 0, 7) == '/Shared') {
- return;
- }
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
- if(!$view->is_readable($path)) return; //cant read, nothing we can do
- clearstatcache();
- $mimetype=$view->getMimeType($path);
- $stat=$view->stat($path);
- if($mimetype=='httpd/unix-directory') {
- $stat['size'] = 0;
- $writable=$view->is_writable($path.'/');
- }else{
- $writable=$view->is_writable($path);
- }
- $stat['mimetype']=$mimetype;
- $stat['writable']=$writable;
- if($path=='/') {
- $path='';
- }
- self::put($path, $stat, $root);
- return $stat['size'];
- }
-
- /**
- * find files by mimetype
- * @param string $part1
- * @param string $part2 (optional)
- * @param string root (optional)
- * @return array of file paths
- *
- * $part1 and $part2 together form the complete mimetype.
- * e.g. searchByMime('text','plain')
- *
- * seccond mimetype part can be ommited
- * e.g. searchByMime('audio')
- */
- public static function searchByMime($part1,$part2=null,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- $rootLen=strlen($root);
- $root .= '%';
- $user=OC_User::getUser();
- if(!$part2) {
- $query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `mimepart`=? AND `user`=? AND `path` LIKE ?');
- $result=$query->execute(array($part1, $user, $root));
- }else{
- $query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `mimetype`=? AND `user`=? AND `path` LIKE ? ');
- $result=$query->execute(array($part1.'/'.$part2, $user, $root));
- }
- $names=array();
- while($row=$result->fetchRow()) {
- $names[]=substr($row['path'], $rootLen);
- }
- return $names;
- }
-
- /**
- * clean old pre-path_hash entries
- */
- public static function clean() {
- $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE LENGTH(`path_hash`)<30');
- $query->execute();
- }
-
- /**
- * clear filecache entries
- * @param string user (optonal)
- */
- public static function clear($user='') {
- if($user) {
- $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `user`=?');
- $query->execute(array($user));
- }else{
- $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache`');
- $query->execute();
- }
- }
-
- /**
- * trigger an update for the cache by setting the mtimes to 0
- * @param string $user (optional)
- */
- public static function triggerUpdate($user=''){
- if($user) {
- $query=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 WHERE `user`=? AND `mimetype`="httpd/unix-directory"');
- $query->execute(array($user));
- }else{
- $query=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 AND `mimetype`="httpd/unix-directory"');
- $query->execute();
- }
- }
-}
-
-//watch for changes and try to keep the cache up to date
-OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_FileCache_Update', 'fileSystemWatcherWrite');
-OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC_FileCache_Update', 'fileSystemWatcherDelete');
-OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_FileCache_Update', 'fileSystemWatcherRename');
-OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_FileCache_Update', 'deleteFromUser');
diff --git a/lib/filecache/cached.php b/lib/filecache/cached.php
deleted file mode 100644
index 9b1eb4f7803..00000000000
--- a/lib/filecache/cached.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-
-/**
- * get data from the filecache without checking for updates
- */
-class OC_FileCache_Cached{
- public static $savedData=array();
-
- public static function get($path,$root=false) {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- $path=$root.$path;
- $stmt=OC_DB::prepare('SELECT `path`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `path_hash`=?');
- if ( ! OC_DB::isError($stmt) ) {
- $result=$stmt->execute(array(md5($path)));
- if ( ! OC_DB::isError($result) ) {
- $result = $result->fetchRow();
- } else {
- OC:Log::write('OC_FileCache_Cached', 'could not execute get: '. OC_DB::getErrorMessage($result), OC_Log::ERROR);
- $result = false;
- }
- } else {
- OC_Log::write('OC_FileCache_Cached', 'could not prepare get: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR);
- $result = false;
- }
- if(is_array($result)) {
- if(isset(self::$savedData[$path])) {
- $result=array_merge($result, self::$savedData[$path]);
- }
- return $result;
- }else{
- if(isset(self::$savedData[$path])) {
- return self::$savedData[$path];
- }else{
- return array();
- }
- }
- }
-
- /**
- * get all files and folders in a folder
- * @param string path
- * @param string root (optional)
- * @return array
- *
- * returns an array of assiciative arrays with the following keys:
- * - path
- * - name
- * - size
- * - mtime
- * - ctime
- * - mimetype
- * - encrypted
- * - versioned
- */
- public static function getFolderContent($path,$root=false,$mimetype_filter='') {
- if($root===false) {
- $root=OC_Filesystem::getRoot();
- }
- $parent=OC_FileCache::getId($path, $root);
- if($parent==-1) {
- return array();
- }
- $query=OC_DB::prepare('SELECT `id`,`path`,`name`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `parent`=? AND (`mimetype` LIKE ? OR `mimetype` = ?)');
- $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll();
- if(is_array($result)) {
- return $result;
- }else{
- OC_Log::write('files', 'getFolderContent(): file not found in cache ('.$path.')', OC_Log::DEBUG);
- return false;
- }
- }
-} \ No newline at end of file
diff --git a/lib/filecache/update.php b/lib/filecache/update.php
deleted file mode 100644
index f9d64d0ae99..00000000000
--- a/lib/filecache/update.php
+++ /dev/null
@@ -1,227 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-
-/**
- * handles updating the filecache according to outside changes
- */
-class OC_FileCache_Update{
- /**
- * check if a file or folder is updated outside owncloud
- * @param string path
- * @param string root (optional)
- * @param boolean folder
- * @return bool
- */
- public static function hasUpdated($path,$root=false,$folder=false) {
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
- if(!$view->file_exists($path)) {
- return false;
- }
- $cachedData=OC_FileCache_Cached::get($path, $root);
- if(isset($cachedData['mtime'])) {
- $cachedMTime=$cachedData['mtime'];
- if($folder) {
- return $view->hasUpdated($path.'/', $cachedMTime);
- }else{
- return $view->hasUpdated($path, $cachedMTime);
- }
- }else{//file not in cache, so it has to be updated
- if(($path=='/' or $path=='') and $root===false) {//dont auto update the home folder, it will be scanned
- return false;
- }
- return true;
- }
- }
-
- /**
- * delete non existing files from the cache
- */
- public static function cleanFolder($path,$root=false) {
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
-
- $cachedContent=OC_FileCache_Cached::getFolderContent($path,$root);
- foreach($cachedContent as $fileData) {
- $path=$fileData['path'];
- $file=$view->getRelativePath($path);
- if(!$view->file_exists($file)) {
- if($root===false) {//filesystem hooks are only valid for the default root
- OC_Hook::emit('OC_Filesystem', 'post_delete', array('path'=>$file));
- }else{
- self::delete($file, $root);
- }
- }
- }
- }
-
- /**
- * update the cache according to changes in the folder
- * @param string path
- * @param string root (optional)
- */
- public static function updateFolder($path,$root=false) {
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
- $dh=$view->opendir($path.'/');
- if($dh) {//check for changed/new files
- while (($filename = readdir($dh)) !== false) {
- if($filename != '.' and $filename != '..' and $filename != '') {
- $file=$path.'/'.$filename;
- $isDir=$view->is_dir($file);
- if(self::hasUpdated($file, $root, $isDir)) {
- if($isDir){
- self::updateFolder($file, $root);
- }elseif($root===false) {//filesystem hooks are only valid for the default root
- OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$file));
- }else{
- self::update($file, $root);
- }
- }
- }
- }
- }
-
- self::cleanFolder($path, $root);
-
- //update the folder last, so we can calculate the size correctly
- if($root===false) {//filesystem hooks are only valid for the default root
- OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$path));
- }else{
- self::update($path, $root);
- }
- }
-
- /**
- * called when changes are made to files
- * @param array $params
- * @param string root (optional)
- */
- public static function fileSystemWatcherWrite($params) {
- $path=$params['path'];
- self::update($path);
- }
-
- /**
- * called when files are deleted
- * @param array $params
- * @param string root (optional)
- */
- public static function fileSystemWatcherDelete($params) {
- $path=$params['path'];
- self::delete($path);
- }
-
- /**
- * called when files are deleted
- * @param array $params
- * @param string root (optional)
- */
- public static function fileSystemWatcherRename($params) {
- $oldPath=$params['oldpath'];
- $newPath=$params['newpath'];
- self::rename($oldPath, $newPath);
- }
-
- /**
- * update the filecache according to changes to the filesystem
- * @param string path
- * @param string root (optional)
- */
- public static function update($path,$root=false) {
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
-
- $mimetype=$view->getMimeType($path);
-
- $size=0;
- $cached=OC_FileCache_Cached::get($path,$root);
- $cachedSize=isset($cached['size'])?$cached['size']:0;
-
- if($view->is_dir($path.'/')) {
- if(OC_FileCache::inCache($path, $root)) {
- $cachedContent=OC_FileCache_Cached::getFolderContent($path, $root);
- foreach($cachedContent as $file) {
- $size+=$file['size'];
- }
- $mtime=$view->filemtime($path.'/');
- $ctime=$view->filectime($path.'/');
- $writable=$view->is_writable($path.'/');
- OC_FileCache::put($path, array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype,'writable'=>$writable));
- }else{
- $count=0;
- OC_FileCache::scan($path, null, $count, $root);
- return; //increaseSize is already called inside scan
- }
- }else{
- $size=OC_FileCache::scanFile($path, $root);
- }
- if($path !== '' and $path !== '/'){
- OC_FileCache::increaseSize(dirname($path), $size-$cachedSize, $root);
- }
- }
-
- /**
- * update the filesystem after a delete has been detected
- * @param string path
- * @param string root (optional)
- */
- public static function delete($path,$root=false) {
- $cached=OC_FileCache_Cached::get($path, $root);
- if(!isset($cached['size'])) {
- return;
- }
- $size=$cached['size'];
- OC_FileCache::increaseSize(dirname($path), -$size, $root);
- OC_FileCache::delete($path, $root);
- }
-
- /**
- * update the filesystem after a rename has been detected
- * @param string oldPath
- * @param string newPath
- * @param string root (optional)
- */
- public static function rename($oldPath,$newPath,$root=false) {
- if(!OC_FileCache::inCache($oldPath, $root)) {
- return;
- }
- if($root===false) {
- $view=OC_Filesystem::getView();
- }else{
- $view=new OC_FilesystemView($root);
- }
-
- $cached=OC_FileCache_Cached::get($oldPath, $root);
- $oldSize=$cached['size'];
- OC_FileCache::increaseSize(dirname($oldPath), -$oldSize, $root);
- OC_FileCache::increaseSize(dirname($newPath), $oldSize, $root);
- OC_FileCache::move($oldPath, $newPath);
- }
-
- /**
- * delete files owned by user from the cache
- * @param string $parameters$parameters["uid"])
- */
- public static function deleteFromUser($parameters) {
- OC_FileCache::clear($parameters["uid"]);
- }
-}
diff --git a/lib/filechunking.php b/lib/filechunking.php
index 55a4d730430..d63a0d72c83 100644
--- a/lib/filechunking.php
+++ b/lib/filechunking.php
@@ -94,49 +94,49 @@ class OC_FileChunking {
}
public function file_assemble($path) {
- $absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path));
+ $absolutePath = \OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getView()->getAbsolutePath($path));
$data = '';
// use file_put_contents as method because that best matches what this function does
- if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) {
- $path = OC_Filesystem::getView()->getRelativePath($absolutePath);
- $exists = OC_Filesystem::file_exists($path);
+ if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && \OC\Files\Filesystem::isValidPath($path)) {
+ $path = \OC\Files\Filesystem::getView()->getRelativePath($absolutePath);
+ $exists = \OC\Files\Filesystem::file_exists($path);
$run = true;
if(!$exists) {
OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_create,
+ \OC\Files\Filesystem::CLASSNAME,
+ \OC\Files\Filesystem::signal_create,
array(
- OC_Filesystem::signal_param_path => $path,
- OC_Filesystem::signal_param_run => &$run
+ \OC\Files\Filesystem::signal_param_path => $path,
+ \OC\Files\Filesystem::signal_param_run => &$run
)
);
}
OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_write,
+ \OC\Files\Filesystem::CLASSNAME,
+ \OC\Files\Filesystem::signal_write,
array(
- OC_Filesystem::signal_param_path => $path,
- OC_Filesystem::signal_param_run => &$run
+ \OC\Files\Filesystem::signal_param_path => $path,
+ \OC\Files\Filesystem::signal_param_run => &$run
)
);
if(!$run) {
return false;
}
- $target = OC_Filesystem::fopen($path, 'w');
+ $target = \OC\Files\Filesystem::fopen($path, 'w');
if($target) {
$count = $this->assemble($target);
fclose($target);
if(!$exists) {
OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_create,
- array( OC_Filesystem::signal_param_path => $path)
+ \OC\Files\Filesystem::CLASSNAME,
+ \OC\Files\Filesystem::signal_post_create,
+ array( \OC\Files\Filesystem::signal_param_path => $path)
);
}
OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_write,
- array( OC_Filesystem::signal_param_path => $path)
+ \OC\Files\Filesystem::CLASSNAME,
+ \OC\Files\Filesystem::signal_post_write,
+ array( \OC\Files\Filesystem::signal_param_path => $path)
);
OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $count > 0;
diff --git a/lib/fileproxy/fileoperations.php b/lib/fileproxy/fileoperations.php
index 23fb63fcfb1..47ccd8f8c26 100644
--- a/lib/fileproxy/fileoperations.php
+++ b/lib/fileproxy/fileoperations.php
@@ -29,9 +29,9 @@ class OC_FileProxy_FileOperations extends OC_FileProxy{
public function premkdir($path) {
if(!self::$rootView){
- self::$rootView = new OC_FilesystemView('');
+ self::$rootView = new \OC\Files\View('');
}
return !self::$rootView->file_exists($path);
}
-} \ No newline at end of file
+}
diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php
index 012be582a51..cd9a2f4a192 100644
--- a/lib/fileproxy/quota.php
+++ b/lib/fileproxy/quota.php
@@ -57,7 +57,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{
* @return int
*/
private function getFreeSpace($path) {
- $storage=OC_Filesystem::getStorage($path);
+ list($storage,)=\OC\Files\Filesystem::resolvePath($path);
$owner=$storage->getOwner($path);
$totalSpace=$this->getQuota($owner);
@@ -65,13 +65,9 @@ class OC_FileProxy_Quota extends OC_FileProxy{
return 0;
}
- $rootInfo=OC_FileCache::get('', "/".$owner."/files");
- // TODO Remove after merge of share_api
- if (OC_FileCache::inCache('/Shared', "/".$owner."/files")) {
- $sharedInfo=OC_FileCache::get('/Shared', "/".$owner."/files");
- } else {
- $sharedInfo = null;
- }
+ $view = new \OC\Files\View("/".$owner."/files");
+
+ $rootInfo=$view->getFileInfo('/');
$usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0;
$usedSpace=isset($sharedInfo['size'])?$usedSpace-$sharedInfo['size']:$usedSpace;
return $totalSpace-$usedSpace;
@@ -94,7 +90,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{
public function preCopy($path1,$path2) {
if(!self::$rootView){
- self::$rootView = new OC_FilesystemView('');
+ self::$rootView = new \OC\Files\View('');
}
return (self::$rootView->filesize($path1)<$this->getFreeSpace($path2) or $this->getFreeSpace($path2)==0);
}
diff --git a/lib/files.php b/lib/files.php
index b4d4de1c995..6a063f216d5 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -1,113 +1,32 @@
<?php
/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
-*
-*/
+ * ownCloud
+ *
+ * @author Frank Karlitschek
+ * @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
+ *
+ */
/**
* Class for fileserver access
*
*/
class OC_Files {
- static $tmpFiles=array();
-
- /**
- * get the filesystem info
- * @param string path
- * @return array
- *
- * returns an associative array with the following keys:
- * - size
- * - mtime
- * - ctime
- * - mimetype
- * - encrypted
- * - versioned
- */
- public static function getFileInfo($path) {
- if (($path == '/Shared' || substr($path, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) {
- if ($path == '/Shared') {
- list($info) = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT);
- }else{
- $info['size'] = OC_Filesystem::filesize($path);
- $info['mtime'] = OC_Filesystem::filemtime($path);
- $info['ctime'] = OC_Filesystem::filectime($path);
- $info['mimetype'] = OC_Filesystem::getMimeType($path);
- $info['encrypted'] = false;
- $info['versioned'] = false;
- }
- } else {
- $info = OC_FileCache::get($path);
- }
- return $info;
- }
-
- /**
- * get the content of a directory
- * @param dir $directory path under datadirectory
- */
- public static function getDirectoryContent($directory, $mimetype_filter = '') {
- $directory=OC_Filesystem::normalizePath($directory);
- if($directory=='/') {
- $directory='';
- }
- $files = array();
- if (($directory == '/Shared' || substr($directory, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) {
- if ($directory == '/Shared') {
- $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter));
- } else {
- $pos = strpos($directory, '/', 8);
- // Get shared folder name
- if ($pos !== false) {
- $itemTarget = substr($directory, 7, $pos - 7);
- } else {
- $itemTarget = substr($directory, 7);
- }
- $files = OCP\Share::getItemSharedWith('folder', $itemTarget, OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter));
- }
- } else {
- $files = OC_FileCache::getFolderContent($directory, false, $mimetype_filter);
- foreach ($files as &$file) {
- $file['directory'] = $directory;
- $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
- $permissions = OCP\Share::PERMISSION_READ;
- // NOTE: Remove check when new encryption is merged
- if (!$file['encrypted']) {
- $permissions |= OCP\Share::PERMISSION_SHARE;
- }
- if ($file['type'] == 'dir' && $file['writable']) {
- $permissions |= OCP\Share::PERMISSION_CREATE;
- }
- if ($file['writable']) {
- $permissions |= OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE;
- }
- $file['permissions'] = $permissions;
- }
- if ($directory == '' && OC_App::isEnabled('files_sharing')) {
- // Add 'Shared' folder
- $files = array_merge($files, OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT));
- }
- }
- usort($files, "fileCmp");//TODO: remove this once ajax is merged
- return $files;
- }
+ static $tmpFiles = array();
public static function searchByMime($mimetype_filter) {
$files = array();
@@ -116,12 +35,11 @@ class OC_Files {
// get next subdir to check
$dir = array_pop($dirs_to_check);
$dir_content = self::getDirectoryContent($dir, $mimetype_filter);
- foreach($dir_content as $file) {
+ foreach ($dir_content as $file) {
if ($file['type'] == 'file') {
- $files[] = $dir.'/'.$file['name'];
- }
- else {
- $dirs_to_check[] = $dir.'/'.$file['name'];
+ $files[] = $dir . '/' . $file['name'];
+ } else {
+ $dirs_to_check[] = $dir . '/' . $file['name'];
}
}
}
@@ -129,200 +47,130 @@ class OC_Files {
}
/**
- * return the content of a file or return a zip file containning multiply files
- *
- * @param dir $dir
- * @param file $file ; seperated list of files to download
- * @param boolean $only_header ; boolean to only send header of the request
- */
- public static function get($dir,$files, $only_header = false) {
- if(strpos($files, ';')) {
- $files=explode(';', $files);
+ * return the content of a file or return a zip file containning multiply files
+ *
+ * @param string $dir
+ * @param string $file ; seperated list of files to download
+ * @param boolean $only_header ; boolean to only send header of the request
+ */
+ public static function get($dir, $files, $only_header = false) {
+ if (strpos($files, ';')) {
+ $files = explode(';', $files);
}
- if(is_array($files)) {
+ if (is_array($files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
- if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
+ if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
exit("cannot open <$filename>\n");
}
- foreach($files as $file) {
- $file=$dir.'/'.$file;
- if(OC_Filesystem::is_file($file)) {
- $tmpFile=OC_Filesystem::toTmpFile($file);
- self::$tmpFiles[]=$tmpFile;
+ foreach ($files as $file) {
+ $file = $dir . '/' . $file;
+ if (\OC\Files\Filesystem::is_file($file)) {
+ $tmpFile = \OC\Files\Filesystem::toTmpFile($file);
+ self::$tmpFiles[] = $tmpFile;
$zip->addFile($tmpFile, basename($file));
- }elseif(OC_Filesystem::is_dir($file)) {
+ } elseif (\OC\Files\Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
$zip->close();
set_time_limit($executionTime);
- }elseif(OC_Filesystem::is_dir($dir.'/'.$files)) {
+ } elseif (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
- if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
+ if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
exit("cannot open <$filename>\n");
}
- $file=$dir.'/'.$files;
+ $file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
$zip->close();
set_time_limit($executionTime);
- }else{
- $zip=false;
- $filename=$dir.'/'.$files;
+ } else {
+ $zip = false;
+ $filename = $dir . '/' . $files;
}
@ob_end_clean();
- if($zip or OC_Filesystem::is_readable($filename)) {
- header('Content-Disposition: attachment; filename="'.basename($filename).'"');
+ if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
+ header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
- if($zip) {
+ if ($zip) {
ini_set('zlib.output_compression', 'off');
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
- }else{
- header('Content-Type: '.OC_Filesystem::getMimeType($filename));
+ } else {
+ header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
}
- }elseif($zip or !OC_Filesystem::file_exists($filename)) {
+ } elseif ($zip or !\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
- $tmpl = new OC_Template( '', '404', 'guest' );
+ $tmpl = new OC_Template('', '404', 'guest');
$tmpl->assign('file', $filename);
$tmpl->printPage();
- }else{
+ } else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
- if($only_header) {
- if(!$zip)
- header("Content-Length: ".OC_Filesystem::filesize($filename));
- return ;
+ if ($only_header) {
+ if (!$zip)
+ header("Content-Length: " . \OC\Files\Filesystem::filesize($filename));
+ return;
}
- if($zip) {
- $handle=fopen($filename, 'r');
+ if ($zip) {
+ $handle = fopen($filename, 'r');
if ($handle) {
- $chunkSize = 8*1024;// 1 MB chunks
+ $chunkSize = 8 * 1024; // 1 MB chunks
while (!feof($handle)) {
echo fread($handle, $chunkSize);
flush();
}
}
unlink($filename);
- }else{
- OC_Filesystem::readfile($filename);
+ } else {
+ \OC\Files\Filesystem::readfile($filename);
}
- foreach(self::$tmpFiles as $tmpFile) {
- if(file_exists($tmpFile) and is_file($tmpFile)) {
+ foreach (self::$tmpFiles as $tmpFile) {
+ if (file_exists($tmpFile) and is_file($tmpFile)) {
unlink($tmpFile);
}
}
}
- public static function zipAddDir($dir,$zip,$internalDir='') {
- $dirname=basename($dir);
- $zip->addEmptyDir($internalDir.$dirname);
- $internalDir.=$dirname.='/';
- $files=OC_Files::getdirectorycontent($dir);
- foreach($files as $file) {
- $filename=$file['name'];
- $file=$dir.'/'.$filename;
- if(OC_Filesystem::is_file($file)) {
- $tmpFile=OC_Filesystem::toTmpFile($file);
- OC_Files::$tmpFiles[]=$tmpFile;
- $zip->addFile($tmpFile, $internalDir.$filename);
- }elseif(OC_Filesystem::is_dir($file)) {
+ public static function zipAddDir($dir, $zip, $internalDir = '') {
+ $dirname = basename($dir);
+ $zip->addEmptyDir($internalDir . $dirname);
+ $internalDir .= $dirname .= '/';
+ $files = \OC\Files\Filesystem::getDirectoryContent($dir);
+ foreach ($files as $file) {
+ $filename = $file['name'];
+ $file = $dir . '/' . $filename;
+ if (\OC\Files\Filesystem::is_file($file)) {
+ $tmpFile = \OC\Files\Filesystem::toTmpFile($file);
+ OC_Files::$tmpFiles[] = $tmpFile;
+ $zip->addFile($tmpFile, $internalDir . $filename);
+ } elseif (\OC\Files\Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip, $internalDir);
}
}
}
- /**
- * move a file or folder
- *
- * @param dir $sourceDir
- * @param file $source
- * @param dir $targetDir
- * @param file $target
- */
- public static function move($sourceDir,$source,$targetDir,$target) {
- if(OC_User::isLoggedIn() && ($sourceDir != '' || $source != 'Shared')) {
- $targetFile=self::normalizePath($targetDir.'/'.$target);
- $sourceFile=self::normalizePath($sourceDir.'/'.$source);
- return OC_Filesystem::rename($sourceFile, $targetFile);
- } else {
- return false;
- }
- }
-
- /**
- * copy a file or folder
- *
- * @param dir $sourceDir
- * @param file $source
- * @param dir $targetDir
- * @param file $target
- */
- public static function copy($sourceDir,$source,$targetDir,$target) {
- if(OC_User::isLoggedIn()) {
- $targetFile=$targetDir.'/'.$target;
- $sourceFile=$sourceDir.'/'.$source;
- return OC_Filesystem::copy($sourceFile, $targetFile);
- }
- }
-
- /**
- * create a new file or folder
- *
- * @param dir $dir
- * @param file $name
- * @param type $type
- */
- public static function newFile($dir,$name,$type) {
- if(OC_User::isLoggedIn()) {
- $file=$dir.'/'.$name;
- if($type=='dir') {
- return OC_Filesystem::mkdir($file);
- }elseif($type=='file') {
- $fileHandle=OC_Filesystem::fopen($file, 'w');
- if($fileHandle) {
- fclose($fileHandle);
- return true;
- }else{
- return false;
- }
- }
- }
- }
-
- /**
- * deletes a file or folder
- *
- * @param dir $dir
- * @param file $name
- */
- public static function delete($dir,$file) {
- if(OC_User::isLoggedIn() && ($dir!= '' || $file != 'Shared')) {
- $file=$dir.'/'.$file;
- return OC_Filesystem::unlink($file);
- }
- }
/**
- * checks if the selected files are within the size constraint. If not, outputs an error page.
- *
- * @param dir $dir
- * @param files $files
- */
+ * checks if the selected files are within the size constraint. If not, outputs an error page.
+ *
+ * @param dir $dir
+ * @param files $files
+ */
static function validateZipDownload($dir, $files) {
- if(!OC_Config::getValue('allowZipDownload', true)) {
+ if (!OC_Config::getValue('allowZipDownload', true)) {
$l = OC_L10N::get('lib');
header("HTTP/1.0 409 Conflict");
- $tmpl = new OC_Template( '', 'error', 'user' );
+ $tmpl = new OC_Template('', 'error', 'user');
$errors = array(
array(
'error' => $l->t('ZIP download is turned off.'),
@@ -335,19 +183,19 @@ class OC_Files {
}
$zipLimit = OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
- if($zipLimit > 0) {
+ if ($zipLimit > 0) {
$totalsize = 0;
- if(is_array($files)) {
- foreach($files as $file) {
- $totalsize += OC_Filesystem::filesize($dir.'/'.$file);
+ if (is_array($files)) {
+ foreach ($files as $file) {
+ $totalsize += \OC\Files\Filesystem::filesize($dir . '/' . $file);
}
- }else{
- $totalsize += OC_Filesystem::filesize($dir.'/'.$files);
+ } else {
+ $totalsize += \OC\Files\Filesystem::filesize($dir . '/' . $files);
}
- if($totalsize > $zipLimit) {
+ if ($totalsize > $zipLimit) {
$l = OC_L10N::get('lib');
header("HTTP/1.0 409 Conflict");
- $tmpl = new OC_Template( '', 'error', 'user' );
+ $tmpl = new OC_Template('', 'error', 'user');
$errors = array(
array(
'error' => $l->t('Selected files too large to generate zip file.'),
@@ -362,78 +210,31 @@ class OC_Files {
}
/**
- * try to detect the mime type of a file
- *
- * @param string path
- * @return string guessed mime type
- */
- static function getMimeType($path) {
- return OC_Filesystem::getMimeType($path);
- }
-
- /**
- * get a file tree
- *
- * @param string path
- * @return array
- */
- static function getTree($path) {
- return OC_Filesystem::getTree($path);
- }
-
- /**
- * pull a file from a remote server
- * @param string source
- * @param string token
- * @param string dir
- * @param string file
- * @return string guessed mime type
- */
- static function pull($source,$token,$dir,$file) {
- $tmpfile=tempnam(get_temp_dir(), 'remoteCloudFile');
- $fp=fopen($tmpfile,'w+');
- $url=$source.="/files/pull.php?token=$token";
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_FILE, $fp);
- curl_exec($ch);
- fclose($fp);
- $info=curl_getinfo($ch);
- $httpCode=$info['http_code'];
- curl_close($ch);
- if($httpCode==200 or $httpCode==0) {
- OC_Filesystem::fromTmpFile($tmpfile, $dir.'/'.$file);
- return true;
- }else{
- return false;
- }
- }
-
- /**
* set the maximum upload size limit for apache hosts using .htaccess
+ *
* @param int size filesisze in bytes
* @return false on failure, size on success
*/
static function setUploadLimit($size) {
//don't allow user to break his config -- upper boundary
- if($size > PHP_INT_MAX) {
+ if ($size > PHP_INT_MAX) {
//max size is always 1 byte lower than computerFileSize returns
- if($size > PHP_INT_MAX+1)
+ if ($size > PHP_INT_MAX + 1)
return false;
- $size -=1;
+ $size -= 1;
} else {
- $size=OC_Helper::humanFileSize($size);
- $size=substr($size, 0, -1);//strip the B
- $size=str_replace(' ', '', $size); //remove the space between the size and the postfix
+ $size = OC_Helper::humanFileSize($size);
+ $size = substr($size, 0, -1); //strip the B
+ $size = str_replace(' ', '', $size); //remove the space between the size and the postfix
}
//don't allow user to break his config -- broken or malicious size input
- if(intval($size) == 0) {
+ if (intval($size) == 0) {
return false;
}
- $htaccess = @file_get_contents(OC::$SERVERROOT.'/.htaccess'); //supress errors in case we don't have permissions for
- if(!$htaccess) {
+ $htaccess = @file_get_contents(OC::$SERVERROOT . '/.htaccess'); //supress errors in case we don't have permissions for
+ if (!$htaccess) {
return false;
}
@@ -442,50 +243,37 @@ class OC_Files {
'post_max_size'
);
- foreach($phpValueKeys as $key) {
- $pattern = '/php_value '.$key.' (\S)*/';
- $setting = 'php_value '.$key.' '.$size;
- $hasReplaced = 0;
- $content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced);
- if($content !== null) {
+ foreach ($phpValueKeys as $key) {
+ $pattern = '/php_value ' . $key . ' (\S)*/';
+ $setting = 'php_value ' . $key . ' ' . $size;
+ $hasReplaced = 0;
+ $content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced);
+ if ($content !== null) {
$htaccess = $content;
}
- if($hasReplaced == 0) {
+ if ($hasReplaced == 0) {
$htaccess .= "\n" . $setting;
}
}
//check for write permissions
- if(is_writable(OC::$SERVERROOT.'/.htaccess')) {
- file_put_contents(OC::$SERVERROOT.'/.htaccess', $htaccess);
+ if (is_writable(OC::$SERVERROOT . '/.htaccess')) {
+ file_put_contents(OC::$SERVERROOT . '/.htaccess', $htaccess);
return OC_Helper::computerFileSize($size);
- } else { OC_Log::write('files', 'Can\'t write upload limit to '.OC::$SERVERROOT.'/.htaccess. Please check the file permissions', OC_Log::WARN); }
+ } else {
+ OC_Log::write('files', 'Can\'t write upload limit to ' . OC::$SERVERROOT . '/.htaccess. Please check the file permissions', OC_Log::WARN);
+ }
return false;
}
-
- /**
- * normalize a path, removing any double, add leading /, etc
- * @param string $path
- * @return string
- */
- static public function normalizePath($path) {
- $path='/'.$path;
- $old='';
- while($old!=$path) {//replace any multiplicity of slashes with a single one
- $old=$path;
- $path=str_replace('//', '/', $path);
- }
- return $path;
- }
}
-function fileCmp($a,$b) {
- if($a['type']=='dir' and $b['type']!='dir') {
+function fileCmp($a, $b) {
+ if ($a['type'] == 'dir' and $b['type'] != 'dir') {
return -1;
- }elseif($a['type']!='dir' and $b['type']=='dir') {
+ } elseif ($a['type'] != 'dir' and $b['type'] == 'dir') {
return 1;
- }else{
+ } else {
return strnatcasecmp($a['name'], $b['name']);
}
}
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
new file mode 100644
index 00000000000..5efc7d67c4a
--- /dev/null
+++ b/lib/files/cache/cache.php
@@ -0,0 +1,304 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Cache;
+
+/**
+ * Metadata cache for the filesystem
+ *
+ * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
+ */
+class Cache {
+ const NOT_FOUND = 0;
+ const PARTIAL = 1; //only partial data available, file not cached in the database
+ const SHALLOW = 2; //folder in cache, but not all child files are completely scanned
+ const COMPLETE = 3;
+
+ /**
+ * @var \OC\Files\Storage\Storage
+ */
+ private $storage;
+
+ /**
+ * @var array partial data for the cache
+ */
+ private $partial = array();
+
+ private $storageId;
+
+ /**
+ * @param \OC\Files\Storage\Storage $storage
+ */
+ public function __construct(\OC\Files\Storage\Storage $storage) {
+ $this->storage = $storage;
+ $this->storageId = $storage->getId();
+ }
+
+ /**
+ * get the stored metadata of a file or folder
+ *
+ * @param string/int $file
+ * @return array
+ */
+ public function get($file) {
+ if (is_string($file)) {
+ $where = 'WHERE `storage` = ? AND `path_hash` = ?';
+ $params = array($this->storageId, md5($file));
+ } else { //file id
+ $where = 'WHERE `fileid` = ?';
+ $params = array($file);
+ }
+ $query = \OC_DB::prepare(
+ 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` ' . $where);
+ $result = $query->execute($params);
+ $data = $result->fetchRow();
+
+ //merge partial data
+ if (!$data and is_string($file)) {
+ if (isset($this->partial[$file])) {
+ $data = $this->partial[$file];
+ }
+ } else {
+ //fix types
+ $data['fileid'] = (int)$data['fileid'];
+ $data['size'] = (int)$data['size'];
+ $data['mtime'] = (int)$data['mtime'];
+ $data['encrypted'] = (bool)$data['encrypted'];
+ }
+
+ return $data;
+ }
+
+ /**
+ * get the metadata of all files stored in $folder
+ *
+ * @param string $folder
+ * @return array
+ */
+ public function getFolderContents($folder) {
+ $fileId = $this->getId($folder);
+ if ($fileId > -1) {
+ $query = \OC_DB::prepare(
+ 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` WHERE parent = ?');
+ $result = $query->execute(array($fileId));
+ return $result->fetchAll();
+ } else {
+ return array();
+ }
+ }
+
+ /**
+ * store meta data for a file or folder
+ *
+ * @param string $file
+ * @param array $data
+ *
+ * @return int file id
+ */
+ public function put($file, array $data) {
+ if (($id = $this->getId($file)) > -1) {
+ $this->update($id, $data);
+ return $id;
+ } else {
+ if (isset($this->partial[$file])) { //add any saved partial data
+ $data = array_merge($this->partial[$file], $data);
+ unset($this->partial[$file]);
+ }
+
+ $requiredFields = array('size', 'mtime', 'mimetype');
+ foreach ($requiredFields as $field) {
+ if (!isset($data[$field])) { //data not complete save as partial and return
+ $this->partial[$file] = $data;
+ return -1;
+ }
+ }
+
+ $data['path'] = $file;
+ $data['parent'] = $this->getParentId($file);
+ $data['name'] = basename($file);
+ $data['encrypted'] = isset($data['encrypted']) ? ((int)$data['encrypted']) : 0;
+
+ list($queryParts, $params) = $this->buildParts($data);
+ $queryParts[] = '`storage`';
+ $params[] = $this->storageId;
+ $valuesPlaceholder = array_fill(0, count($queryParts), '?');
+
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ') VALUES(' . implode(', ', $valuesPlaceholder) . ')');
+ $query->execute($params);
+
+ return (int)\OC_DB::insertid('*PREFIX*filecache');
+ }
+ }
+
+ /**
+ * update the metadata in the cache
+ *
+ * @param int $id
+ * @param array $data
+ */
+ public function update($id, array $data) {
+ list($queryParts, $params) = $this->buildParts($data);
+ $params[] = $id;
+
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? WHERE fileid = ?');
+ $query->execute($params);
+ }
+
+ /**
+ * extract query parts and params array from data array
+ *
+ * @param array $data
+ * @return array
+ */
+ static function buildParts(array $data) {
+ $fields = array('path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'encrypted');
+
+ $params = array();
+ $queryParts = array();
+ foreach ($data as $name => $value) {
+ if (array_search($name, $fields) !== false) {
+ $params[] = $value;
+ $queryParts[] = '`' . $name . '`';
+ if ($name === 'path') {
+ $params[] = md5($value);
+ $queryParts[] = '`path_hash`';
+ } elseif ($name === 'mimetype') {
+ $params[] = substr($value, 0, strpos($value, '/'));
+ $queryParts[] = '`mimepart`';
+ }
+ }
+ }
+ return array($queryParts, $params);
+ }
+
+ /**
+ * get the file id for a file
+ *
+ * @param string $file
+ * @return int
+ */
+ public function getId($file) {
+ $pathHash = md5($file);
+
+ $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
+ $result = $query->execute(array($this->storageId, $pathHash));
+
+ if ($row = $result->fetchRow()) {
+ return $row['fileid'];
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * get the id of the parent folder of a file
+ *
+ * @param string $file
+ * @return int
+ */
+ public function getParentId($file) {
+ if ($file === '') {
+ return -1;
+ } else {
+ $parent = dirname($file);
+ if ($parent === '.') {
+ $parent = '';
+ }
+ return $this->getId($parent);
+ }
+ }
+
+ /**
+ * check if a file is available in the cache
+ *
+ * @param string $file
+ * @return bool
+ */
+ public function inCache($file) {
+ return $this->getId($file) != -1;
+ }
+
+ /**
+ * remove a file or folder from the cache
+ *
+ * @param string $file
+ */
+ public function remove($file) {
+ $pathHash = md5($file);
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
+ $query->execute(array($this->storageId, $pathHash));
+ }
+
+ /**
+ * remove all entries for files that are stored on the storage from the cache
+ */
+ public function clear() {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage=?');
+ $query->execute(array($this->storageId));
+ }
+
+ /**
+ * @param string $file
+ *
+ * @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
+ */
+ public function getStatus($file) {
+ $pathHash = md5($file);
+ $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
+ $result = $query->execute(array($this->storageId, $pathHash));
+ if ($row = $result->fetchRow()) {
+ if ((int)$row['size'] === -1) {
+ return self::SHALLOW;
+ } else {
+ return self::COMPLETE;
+ }
+ } else {
+ if (isset($this->partial[$file])) {
+ return self::PARTIAL;
+ } else {
+ return self::NOT_FOUND;
+ }
+ }
+ }
+
+ /**
+ * search for files matching $pattern
+ *
+ * @param string $pattern
+ * @return array of file data
+ */
+ public function search($pattern) {
+ $query = \OC_DB::prepare('
+ SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?'
+ );
+ $result = $query->execute(array($pattern, $this->storageId));
+ $files = array();
+ while ($row = $result->fetchRow()) {
+ $files[] = $row;
+ }
+ return $files;
+ }
+
+ /**
+ * get all file ids on the files on the storage
+ *
+ * @return int[]
+ */
+ public function getAll() {
+ $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?');
+ $result = $query->execute(array($this->storageId));
+ $ids = array();
+ while ($row = $result->fetchRow()) {
+ $ids[] = $row['fileid'];
+ }
+ return $ids;
+ }
+}
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
new file mode 100644
index 00000000000..e3fa63c464a
--- /dev/null
+++ b/lib/files/cache/permissions.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Cache;
+
+class Permissions {
+ /**
+ * get the permissions for a single file
+ *
+ * @param int $fileId
+ * @param string $user
+ * @return int (-1 if file no permissions set)
+ */
+ static public function get($fileId, $user) {
+ $query = \OC_DB::prepare('SELECT `permissions` FROM `*PREFIX*permissions` WHERE `user` = ? AND `fileid` = ?');
+ $result = $query->execute(array($user, $fileId));
+ if ($row = $result->fetchRow()) {
+ return $row['permissions'];
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * set the permissions of a file
+ *
+ * @param int $fileId
+ * @param string $user
+ * @param int $permissions
+ */
+ static public function set($fileId, $user, $permissions) {
+ if (self::get($fileId, $user) !== -1) {
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ? WHERE `user` = ? AND `fileid` = ?');
+ } else {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`) VALUES(?, ?,? )');
+ }
+ $query->execute(array($permissions, $user, $fileId));
+ }
+
+ /**
+ * get the permissions of multiply files
+ *
+ * @param int[] $fileIds
+ * @param string $user
+ * @return int[]
+ */
+ static public function getMultiple($fileIds, $user) {
+ $params = $fileIds;
+ $params[] = $user;
+ $inPart = implode(', ', array_fill(0, count($fileIds), '?'));
+
+ $query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions` WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
+ $result = $query->execute($params);
+ $filePermissions = array();
+ while ($row = $result->fetchRow()) {
+ $filePermissions[$row['fileid']] = $row['permissions'];
+ }
+ return $filePermissions;
+ }
+
+ /**
+ * remove the permissions for a file
+ *
+ * @param int $fileId
+ * @param string $user
+ */
+ static public function remove($fileId, $user) {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
+ $query->execute(array($fileId, $user));
+ }
+
+ static public function removeMultiple($fileIds, $user) {
+ $params = $fileIds;
+ $params[] = $user;
+ $inPart = implode(', ', array_fill(0, count($fileIds), '?'));
+
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
+ $query->execute($params);
+ }
+}
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
new file mode 100644
index 00000000000..0adde1d354d
--- /dev/null
+++ b/lib/files/cache/scanner.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Cache;
+
+class Scanner {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ const SCAN_RECURSIVE = true;
+ const SCAN_SHALLOW = false;
+
+ public function __construct(\OC\Files\Storage\Storage $storage) {
+ $this->storage = $storage;
+ $this->cache = new Cache($storage);
+ }
+
+ /**
+ * get all the metadata of a file or folder
+ * *
+ *
+ * @param string $path
+ * @return array with metadata of the file
+ */
+ public function getData($path) {
+ $data = array();
+ if (!$this->storage->isReadable($path)) return null; //cant read, nothing we can do
+ $data['mimetype'] = $this->storage->getMimeType($path);
+ $data['mtime'] = $this->storage->filemtime($path);
+ if ($data['mimetype'] == 'httpd/unix-directory') {
+ $data['size'] = -1; //unknown
+ $data['permissions'] = $this->storage->getPermissions($path . '/');
+ } else {
+ $data['size'] = $this->storage->filesize($path);
+ $data['permissions'] = $this->storage->getPermissions($path);
+ }
+ return $data;
+ }
+
+ /**
+ * scan a single file and store it in the cache
+ *
+ * @param string $file
+ * @return array with metadata of the scanned file
+ */
+ public function scanFile($file) {
+ $data = $this->getData($file);
+ if ($file !== '') {
+ $parent = dirname($file);
+ if ($parent === '.') {
+ $parent = '';
+ }
+ if (!$this->cache->inCache($parent)) {
+ $this->scanFile($parent);
+ }
+ }
+ $id = $this->cache->put($file, $data);
+ Permissions::set($id, \OC_User::getUser(), $data['permissions']);
+ return $data;
+ }
+
+ /**
+ * scan all the files in a folder and store them in the cache
+ *
+ * @param string $path
+ * @param SCAN_RECURSIVE/SCAN_SHALLOW $recursive
+ * @return int the size of the scanned folder or -1 if the size is unknown at this stage
+ */
+ public function scan($path, $recursive = self::SCAN_RECURSIVE) {
+ $this->scanFile($path);
+
+ $size = 0;
+ if ($dh = $this->storage->opendir($path)) {
+ while ($file = readdir($dh)) {
+ if ($file !== '.' and $file !== '..') {
+ $child = ($path !== '') ? $path . '/' . $file : $file;
+ $data = $this->scanFile($child);
+ if ($data['mimetype'] === 'httpd/unix-directory') {
+ if ($recursive === self::SCAN_RECURSIVE) {
+ $data['size'] = $this->scan($child, self::SCAN_RECURSIVE);
+ } else {
+ $data['size'] = -1;
+ }
+ }
+ if ($data['size'] === -1) {
+ $size = -1;
+ } elseif ($size !== -1) {
+ $size += $data['size'];
+ }
+ }
+ }
+ }
+ if ($size !== -1) {
+ $this->cache->put($path, array('size' => $size));
+ }
+ return $size;
+ }
+}
diff --git a/lib/files/file.php b/lib/files/file.php
new file mode 100644
index 00000000000..0d33cea7ee7
--- /dev/null
+++ b/lib/files/file.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files;
+
+/**
+ * representation of the location a file or folder is stored
+ */
+
+class File{
+ /**
+ * @var Storage\Storage $storage
+ */
+ private $storage;
+ /**
+ * @var string internalPath
+ */
+ private $internalPath;
+
+ public function __construct(Storage\Storage $storage, $internalPath){
+ $this->storage = $storage;
+ $this->internalPath = $internalPath;
+ }
+
+ public static function resolve($fullPath){
+ $storage = null;
+ $internalPath = '';
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
+ return new File($storage, $internalPath);
+ }
+
+ /**
+ * get the internal path of the file inside the filestorage
+ * @return string
+ */
+ public function getInternalPath(){
+ return $this->internalPath;
+ }
+
+ /**
+ * get the storage the file is stored in
+ * @return \OC\Files\Storage\Storage
+ */
+ public function getStorage(){
+ return $this->storage;
+ }
+
+ /**
+ * get the id of the storage the file is stored in
+ * @return string
+ */
+ public function getStorageId(){
+ return $this->storage->getId();
+ }
+
+}
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
new file mode 100644
index 00000000000..b3c92f38558
--- /dev/null
+++ b/lib/files/filesystem.php
@@ -0,0 +1,658 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Class for abstraction of filesystem functions
+ * This class won't call any filesystem functions for itself but but will pass them to the correct OC_Filestorage object
+ * this class should also handle all the file permission related stuff
+ *
+ * Hooks provided:
+ * read(path)
+ * write(path, &run)
+ * post_write(path)
+ * create(path, &run) (when a file is created, both create and write will be emitted in that order)
+ * post_create(path)
+ * delete(path, &run)
+ * post_delete(path)
+ * rename(oldpath,newpath, &run)
+ * post_rename(oldpath,newpath)
+ * copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emitted in that order)
+ * post_rename(oldpath,newpath)
+ *
+ * the &run parameter can be set to false to prevent the operation from occurring
+ */
+
+namespace OC\Files;
+
+class Filesystem {
+ static private $storages = array();
+ static private $mounts = array();
+ public static $loaded = false;
+ /**
+ * @var \OC\Files\View $defaultInstance
+ */
+ static private $defaultInstance;
+
+
+ /**
+ * classname which used for hooks handling
+ * used as signalclass in OC_Hooks::emit()
+ */
+ const CLASSNAME = 'OC_Filesystem';
+
+ /**
+ * signalname emitted before file renaming
+ *
+ * @param string $oldpath
+ * @param string $newpath
+ */
+ const signal_rename = 'rename';
+
+ /**
+ * signal emitted after file renaming
+ *
+ * @param string $oldpath
+ * @param string $newpath
+ */
+ const signal_post_rename = 'post_rename';
+
+ /**
+ * signal emitted before file/dir creation
+ *
+ * @param string $path
+ * @param bool $run changing this flag to false in hook handler will cancel event
+ */
+ const signal_create = 'create';
+
+ /**
+ * signal emitted after file/dir creation
+ *
+ * @param string $path
+ * @param bool $run changing this flag to false in hook handler will cancel event
+ */
+ const signal_post_create = 'post_create';
+
+ /**
+ * signal emits before file/dir copy
+ *
+ * @param string $oldpath
+ * @param string $newpath
+ * @param bool $run changing this flag to false in hook handler will cancel event
+ */
+ const signal_copy = 'copy';
+
+ /**
+ * signal emits after file/dir copy
+ *
+ * @param string $oldpath
+ * @param string $newpath
+ */
+ const signal_post_copy = 'post_copy';
+
+ /**
+ * signal emits before file/dir save
+ *
+ * @param string $path
+ * @param bool $run changing this flag to false in hook handler will cancel event
+ */
+ const signal_write = 'write';
+
+ /**
+ * signal emits after file/dir save
+ *
+ * @param string $path
+ */
+ const signal_post_write = 'post_write';
+
+ /**
+ * signal emits when reading file/dir
+ *
+ * @param string $path
+ */
+ const signal_read = 'read';
+
+ /**
+ * signal emits when removing file/dir
+ *
+ * @param string $path
+ */
+ const signal_delete = 'delete';
+
+ /**
+ * parameters definitions for signals
+ */
+ const signal_param_path = 'path';
+ const signal_param_oldpath = 'oldpath';
+ const signal_param_newpath = 'newpath';
+
+ /**
+ * run - changing this flag to false in hook handler will cancel event
+ */
+ const signal_param_run = 'run';
+
+ /**
+ * get the mountpoint of the storage object for a path
+ ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account
+ *
+ * @param string $path
+ * @return string
+ */
+ static public function getMountPoint($path) {
+ \OC_Hook::emit(self::CLASSNAME, 'get_mountpoint', array('path' => $path));
+ if (!$path) {
+ $path = '/';
+ }
+ if ($path[0] !== '/') {
+ $path = '/' . $path;
+ }
+ $path = str_replace('//', '/', $path);
+ $foundMountPoint = '';
+ $mountPoints = array_keys(self::$mounts);
+ foreach ($mountPoints as $mountpoint) {
+ if ($mountpoint == $path) {
+ return $mountpoint;
+ }
+ if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) {
+ $foundMountPoint = $mountpoint;
+ }
+ }
+ return $foundMountPoint;
+ }
+
+ /**
+ * get a list of all mount points in a directory
+ *
+ * @param string $path
+ * @return string[]
+ */
+ static public function getMountPoints($path) {
+ $path = self::normalizePath($path);
+ if (strlen($path) > 1) {
+ $path .= '/';
+ }
+ $pathLength = strlen($path);
+
+ $mountPoints = array_keys(self::$mounts);
+ $result = array();
+ foreach ($mountPoints as $mountPoint) {
+ if (substr($mountPoint, 0, $pathLength) === $path and strlen($mountPoint) > $pathLength) {
+ $result[] = $mountPoint;
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * get the storage mounted at $mountPoint
+ *
+ * @param string $mountPoint
+ * @return \OC\Files\Storage\Storage
+ */
+ public static function getStorage($mountPoint) {
+ if (!isset(self::$storages[$mountPoint])) {
+ $mount = self::$mounts[$mountPoint];
+ self::$storages[$mountPoint] = self::createStorage($mount['class'], $mount['arguments']);
+ }
+ return self::$storages[$mountPoint];
+ }
+
+ /**
+ * resolve a path to a storage and internal path
+ *
+ * @param string $path
+ * @return array consisting of the storage and the internal path
+ */
+ static public function resolvePath($path) {
+ $mountpoint = self::getMountPoint($path);
+ if ($mountpoint) {
+ $storage = self::getStorage($mountpoint);
+ if ($mountpoint === $path) {
+ $internalPath = '';
+ } else {
+ $internalPath = substr($path, strlen($mountpoint));
+ }
+ return array($storage, $internalPath);
+ } else {
+ return array(null, null);
+ }
+ }
+
+ static public function init($root) {
+ if (self::$defaultInstance) {
+ return false;
+ }
+ self::$defaultInstance = new View($root);
+
+ //load custom mount config
+ if (is_file(\OC::$SERVERROOT . '/config/mount.php')) {
+ $mountConfig = include 'config/mount.php';
+ if (isset($mountConfig['global'])) {
+ foreach ($mountConfig['global'] as $mountPoint => $options) {
+ self::mount($options['class'], $options['options'], $mountPoint);
+ }
+ }
+
+ if (isset($mountConfig['group'])) {
+ foreach ($mountConfig['group'] as $group => $mounts) {
+ if (\OC_Group::inGroup(\OC_User::getUser(), $group)) {
+ foreach ($mounts as $mountPoint => $options) {
+ $mountPoint = self::setUserVars($mountPoint);
+ foreach ($options as &$option) {
+ $option = self::setUserVars($option);
+ }
+ self::mount($options['class'], $options['options'], $mountPoint);
+ }
+ }
+ }
+ }
+
+ if (isset($mountConfig['user'])) {
+ foreach ($mountConfig['user'] as $user => $mounts) {
+ if ($user === 'all' or strtolower($user) === strtolower(\OC_User::getUser())) {
+ foreach ($mounts as $mountPoint => $options) {
+ $mountPoint = self::setUserVars($mountPoint);
+ foreach ($options as &$option) {
+ $option = self::setUserVars($option);
+ }
+ self::mount($options['class'], $options['options'], $mountPoint);
+ }
+ }
+ }
+ }
+ }
+
+ self::$loaded = true;
+
+ return true;
+ }
+
+ /**
+ * fill in the correct values for $user, and $password placeholders
+ *
+ * @param string $input
+ * @return string
+ */
+ private static function setUserVars($input) {
+ return str_replace('$user', \OC_User::getUser(), $input);
+ }
+
+ /**
+ * get the default filesystem view
+ *
+ * @return View
+ */
+ static public function getView() {
+ return self::$defaultInstance;
+ }
+
+ /**
+ * tear down the filesystem, removing all storage providers
+ */
+ static public function tearDown() {
+ self::$storages = array();
+ }
+
+ /**
+ * create a new storage of a specific type
+ *
+ * @param string $type
+ * @param array $arguments
+ * @return \OC\Files\Storage\Storage
+ */
+ static private function createStorage($class, $arguments) {
+ if (class_exists($class)) {
+ try {
+ return new $class($arguments);
+ } catch (\Exception $exception) {
+ \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR);
+ return false;
+ }
+ } else {
+ \OC_Log::write('core', 'storage backend ' . $class . ' not found', \OC_Log::ERROR);
+ return false;
+ }
+ }
+
+ /**
+ * @brief get the relative path of the root data directory for the current user
+ * @return string
+ *
+ * Returns path like /admin/files
+ */
+ static public function getRoot() {
+ return self::$defaultInstance->getRoot();
+ }
+
+ /**
+ * clear all mounts and storage backends
+ */
+ public static function clearMounts() {
+ self::$mounts = array();
+ self::$storages = array();
+ }
+
+ /**
+ * mount an \OC\Files\Storage\Storage in our virtual filesystem
+ *
+ * @param \OC\Files\Storage\Storage|string $class
+ * @param array $arguments
+ * @param string $mountpoint
+ */
+ static public function mount($class, $arguments, $mountpoint) {
+ $mountpoint = self::normalizePath($mountpoint);
+ if (strlen($mountpoint) > 1) {
+ $mountpoint .= '/';
+ }
+
+ if ($class instanceof \OC\Files\Storage\Storage) {
+ self::$mounts[$mountpoint] = array('class' => get_class($class), 'arguments' => $arguments);
+ self::$storages[$mountpoint] = $class;
+ } else {
+ self::$mounts[$mountpoint] = array('class' => $class, 'arguments' => $arguments);
+ }
+ }
+
+ /**
+ * return the path to a local version of the file
+ * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed
+ *
+ * @param string $path
+ * @return string
+ */
+ static public function getLocalFile($path) {
+ return self::$defaultInstance->getLocalFile($path);
+ }
+
+ /**
+ * @param string $path
+ * @return string
+ */
+ static public function getLocalFolder($path) {
+ return self::$defaultInstance->getLocalFolder($path);
+ }
+
+ /**
+ * return path to file which reflects one visible in browser
+ *
+ * @param string $path
+ * @return string
+ */
+ static public function getLocalPath($path) {
+ $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files';
+ $newpath = $path;
+ if (strncmp($newpath, $datadir, strlen($datadir)) == 0) {
+ $newpath = substr($path, strlen($datadir));
+ }
+ return $newpath;
+ }
+
+ /**
+ * check if the requested path is valid
+ *
+ * @param string $path
+ * @return bool
+ */
+ static public function isValidPath($path) {
+ if (!$path || $path[0] !== '/') {
+ $path = '/' . $path;
+ }
+ if (strstr($path, '/../') || strrchr($path, '/') === '/..') {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * checks if a file is blacklisted for storage in the filesystem
+ * Listens to write and rename hooks
+ *
+ * @param array $data from hook
+ */
+ static public function isBlacklisted($data) {
+ $blacklist = array('.htaccess');
+ if (isset($data['path'])) {
+ $path = $data['path'];
+ } else if (isset($data['newpath'])) {
+ $path = $data['newpath'];
+ }
+ if (isset($path)) {
+ $filename = strtolower(basename($path));
+ if (in_array($filename, $blacklist)) {
+ $data['run'] = false;
+ }
+ }
+ }
+
+ /**
+ * following functions are equivalent to their php builtin equivalents for arguments/return values.
+ */
+ static public function mkdir($path) {
+ return self::$defaultInstance->mkdir($path);
+ }
+
+ static public function rmdir($path) {
+ return self::$defaultInstance->rmdir($path);
+ }
+
+ static public function opendir($path) {
+ return self::$defaultInstance->opendir($path);
+ }
+
+ static public function readdir($path) {
+ return self::$defaultInstance->readdir($path);
+ }
+
+ static public function is_dir($path) {
+ return self::$defaultInstance->is_dir($path);
+ }
+
+ static public function is_file($path) {
+ return self::$defaultInstance->is_file($path);
+ }
+
+ static public function stat($path) {
+ return self::$defaultInstance->stat($path);
+ }
+
+ static public function filetype($path) {
+ return self::$defaultInstance->filetype($path);
+ }
+
+ static public function filesize($path) {
+ return self::$defaultInstance->filesize($path);
+ }
+
+ static public function readfile($path) {
+ return self::$defaultInstance->readfile($path);
+ }
+
+ static public function isCreatable($path) {
+ return self::$defaultInstance->isCreatable($path);
+ }
+
+ static public function isReadable($path) {
+ return self::$defaultInstance->isReadable($path);
+ }
+
+ static public function isUpdatable($path) {
+ return self::$defaultInstance->isUpdatable($path);
+ }
+
+ static public function isDeletable($path) {
+ return self::$defaultInstance->isDeletable($path);
+ }
+
+ static public function isSharable($path) {
+ return self::$defaultInstance->isSharable($path);
+ }
+
+ static public function file_exists($path) {
+ return self::$defaultInstance->file_exists($path);
+ }
+
+ static public function filemtime($path) {
+ return self::$defaultInstance->filemtime($path);
+ }
+
+ static public function touch($path, $mtime = null) {
+ return self::$defaultInstance->touch($path, $mtime);
+ }
+
+ static public function file_get_contents($path) {
+ return self::$defaultInstance->file_get_contents($path);
+ }
+
+ static public function file_put_contents($path, $data) {
+ return self::$defaultInstance->file_put_contents($path, $data);
+ }
+
+ static public function unlink($path) {
+ return self::$defaultInstance->unlink($path);
+ }
+
+ static public function rename($path1, $path2) {
+ return self::$defaultInstance->rename($path1, $path2);
+ }
+
+ static public function copy($path1, $path2) {
+ return self::$defaultInstance->copy($path1, $path2);
+ }
+
+ static public function fopen($path, $mode) {
+ return self::$defaultInstance->fopen($path, $mode);
+ }
+
+ static public function toTmpFile($path) {
+ return self::$defaultInstance->toTmpFile($path);
+ }
+
+ static public function fromTmpFile($tmpFile, $path) {
+ return self::$defaultInstance->fromTmpFile($tmpFile, $path);
+ }
+
+ static public function getMimeType($path) {
+ return self::$defaultInstance->getMimeType($path);
+ }
+
+ static public function hash($type, $path, $raw = false) {
+ return self::$defaultInstance->hash($type, $path, $raw);
+ }
+
+ static public function free_space($path = '/') {
+ return self::$defaultInstance->free_space($path);
+ }
+
+ static public function search($query) {
+ return self::$defaultInstance->search($query);
+ }
+
+ /**
+ * check if a file or folder has been updated since $time
+ *
+ * @param int $time
+ * @return bool
+ */
+ static public function hasUpdated($path, $time) {
+ return self::$defaultInstance->hasUpdated($path, $time);
+ }
+
+ static public function removeETagHook($params, $root = false) {
+ if (isset($params['path'])) {
+ $path = $params['path'];
+ } else {
+ $path = $params['oldpath'];
+ }
+
+ if ($root) { // reduce path to the required part of it (no 'username/files')
+ $fakeRootView = new View($root);
+ $count = 1;
+ $path = str_replace(\OC_App::getStorage("files")->getAbsolutePath(''), "", $fakeRootView->getAbsolutePath($path), $count);
+ }
+
+ $path = self::normalizePath($path);
+ \OC_Connector_Sabre_Node::removeETagPropertyForPath($path);
+ }
+
+ /**
+ * normalize a path
+ *
+ * @param string $path
+ * @param bool $stripTrailingSlash
+ * @return string
+ */
+ public static function normalizePath($path, $stripTrailingSlash = true) {
+ if ($path == '') {
+ return '/';
+ }
+//no windows style slashes
+ $path = str_replace('\\', '/', $path);
+//add leading slash
+ if ($path[0] !== '/') {
+ $path = '/' . $path;
+ }
+//remove duplicate slashes
+ while (strpos($path, '//') !== false) {
+ $path = str_replace('//', '/', $path);
+ }
+//remove trailing slash
+ if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') {
+ $path = substr($path, 0, -1);
+ }
+//normalize unicode if possible
+ if (class_exists('Normalizer')) {
+ $path = \Normalizer::normalize($path);
+ }
+ return $path;
+ }
+
+ /**
+ * get the filesystem info
+ *
+ * @param string $path
+ * @return array
+ *
+ * returns an associative array with the following keys:
+ * - size
+ * - mtime
+ * - mimetype
+ * - encrypted
+ * - versioned
+ */
+ public static function getFileInfo($path) {
+ return self::$defaultInstance->getFileInfo($path);
+ }
+
+ /**
+ * change file metadata
+ *
+ * @param string $path
+ * @param array $data
+ * @return int
+ *
+ * returns the fileid of the updated file
+ */
+ public static function putFileInfo($path, $data) {
+ return self::$defaultInstance->putFileInfo($path, $data);
+ }
+
+ /**
+ * get the content of a directory
+ *
+ * @param string $directory path under datadirectory
+ * @return array
+ */
+ public static function getDirectoryContent($directory, $mimetype_filter = '') {
+ return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
+ }
+}
+
+\OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Filesystem', 'removeETagHook');
+\OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC_Filesystem', 'removeETagHook');
+\OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_Filesystem', 'removeETagHook');
+
+\OC_Util::setupFS();
diff --git a/lib/filestorage/common.php b/lib/files/storage/common.php
index f24a5704913..e22264d0da9 100644
--- a/lib/filestorage/common.php
+++ b/lib/files/storage/common.php
@@ -1,51 +1,40 @@
<?php
-
/**
-* ownCloud
-*
-* @author Michael Gapczynski
-* @copyright 2012 Michael Gapczynski GapczynskiM@gmail.com
-*
-* 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/>.
-*/
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Storage;
/**
* Storage backend class for providing common filesystem operation methods
* which are not storage-backend specific.
*
- * OC_Filestorage_Common is never used directly; it is extended by all other
+ * \OC\Files\Storage\Common is never used directly; it is extended by all other
* storage backends, where its methods may be overridden, and additional
* (backend-specific) methods are defined.
*
- * Some OC_Filestorage_Common methods call functions which are first defined
+ * Some \OC\Files\Storage\Common methods call functions which are first defined
* in classes which extend it, e.g. $this->stat() .
*/
-abstract class OC_Filestorage_Common extends OC_Filestorage {
+abstract class Common implements \OC\Files\Storage\Storage {
public function __construct($parameters) {}
-// abstract public function mkdir($path);
-// abstract public function rmdir($path);
-// abstract public function opendir($path);
+ abstract public function getId();
+ abstract public function mkdir($path);
+ abstract public function rmdir($path);
+ abstract public function opendir($path);
public function is_dir($path) {
return $this->filetype($path)=='dir';
}
public function is_file($path) {
return $this->filetype($path)=='file';
}
-// abstract public function stat($path);
-// abstract public function filetype($path);
+ abstract public function stat($path);
+ abstract public function filetype($path);
public function filesize($path) {
if($this->is_dir($path)) {
return 0;//by definition
@@ -57,19 +46,34 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
public function isCreatable($path) {
return $this->isUpdatable($path);
}
-// abstract public function isReadable($path);
-// abstract public function isUpdatable($path);
+ abstract public function isReadable($path);
+ abstract public function isUpdatable($path);
public function isDeletable($path) {
return $this->isUpdatable($path);
}
public function isSharable($path) {
return $this->isReadable($path);
}
-// abstract public function file_exists($path);
- public function filectime($path) {
- $stat = $this->stat($path);
- return $stat['ctime'];
+ public function getPermissions($path){
+ $permissions = 0;
+ if($this->isCreatable($path)){
+ $permissions |= \OCP\Share::PERMISSION_CREATE;
+ }
+ if($this->isReadable($path)){
+ $permissions |= \OCP\Share::PERMISSION_READ;
+ }
+ if($this->isUpdatable($path)){
+ $permissions |= \OCP\Share::PERMISSION_UPDATE;
+ }
+ if($this->isDeletable($path)){
+ $permissions |= \OCP\Share::PERMISSION_DELETE;
+ }
+ if($this->isSharable($path)){
+ $permissions |= \OCP\Share::PERMISSION_SHARE;
+ }
+ return $permissions;
}
+ abstract public function file_exists($path);
public function filemtime($path) {
$stat = $this->stat($path);
return $stat['mtime'];
@@ -93,7 +97,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
$handle = $this->fopen($path, "w");
return fwrite($handle, $data);
}
-// abstract public function unlink($path);
+ abstract public function unlink($path);
public function rename($path1,$path2) {
if($this->copy($path1,$path2)) {
return $this->unlink($path1);
@@ -104,79 +108,45 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
public function copy($path1,$path2) {
$source=$this->fopen($path1,'r');
$target=$this->fopen($path2,'w');
- $count=OC_Helper::streamCopy($source,$target);
+ $count=\OC_Helper::streamCopy($source,$target);
return $count>0;
}
-// abstract public function fopen($path,$mode);
+ abstract public function fopen($path,$mode);
/**
* @brief Deletes all files and folders recursively within a directory
- * @param $directory The directory whose contents will be deleted
- * @param $empty Flag indicating whether directory will be emptied
- * @returns true/false
+ * @param string $directory The directory whose contents will be deleted
+ * @param bool $empty Flag indicating whether directory will be emptied
+ * @returns bool
*
* @note By default the directory specified by $directory will be
* deleted together with its contents. To avoid this set $empty to true
*/
public function deleteAll( $directory, $empty = false ) {
-
- // strip leading slash
- if( substr( $directory, 0, 1 ) == "/" ) {
-
- $directory = substr( $directory, 1 );
-
- }
-
- // strip trailing slash
- if( substr( $directory, -1) == "/" ) {
-
- $directory = substr( $directory, 0, -1 );
-
- }
+ $directory = trim($directory,'/');
if ( !$this->file_exists( \OCP\USER::getUser() . '/' . $directory ) || !$this->is_dir( \OCP\USER::getUser() . '/' . $directory ) ) {
-
return false;
-
- } elseif( !$this->is_readable( \OCP\USER::getUser() . '/' . $directory ) ) {
-
+ } elseif( !$this->isReadable( \OCP\USER::getUser() . '/' . $directory ) ) {
return false;
-
} else {
-
$directoryHandle = $this->opendir( \OCP\USER::getUser() . '/' . $directory );
-
while ( $contents = readdir( $directoryHandle ) ) {
-
if ( $contents != '.' && $contents != '..') {
-
$path = $directory . "/" . $contents;
-
if ( $this->is_dir( $path ) ) {
-
- deleteAll( $path );
-
+ $this->deleteAll( $path );
} else {
-
$this->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir
-
}
}
-
}
-
//$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV
-
if ( $empty == false ) {
-
if ( !$this->rmdir( $directory ) ) {
-
- return false;
-
+ return false;
}
-
}
-
return true;
}
@@ -198,26 +168,26 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
}else{
$extension='';
}
- $tmpFile=OC_Helper::tmpFile($extension);
+ $tmpFile=\OC_Helper::tmpFile($extension);
file_put_contents($tmpFile,$head);
- $mime=OC_Helper::getMimeType($tmpFile);
+ $mime=\OC_Helper::getMimeType($tmpFile);
unlink($tmpFile);
return $mime;
}
public function hash($type,$path,$raw = false) {
- $tmpFile=$this->getLocalFile();
+ $tmpFile=$this->getLocalFile($path);
$hash=hash($type,$tmpFile,$raw);
unlink($tmpFile);
return $hash;
}
-// abstract public function free_space($path);
+ abstract public function free_space($path);
public function search($query) {
return $this->searchInDir($query);
}
public function getLocalFile($path) {
return $this->toTmpFile($path);
}
- private function toTmpFile($path) {//no longer in the storage api, still usefull here
+ private function toTmpFile($path) {//no longer in the storage api, still useful here
$source=$this->fopen($path,'r');
if(!$source) {
return false;
@@ -227,13 +197,13 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
}else{
$extension='';
}
- $tmpFile=OC_Helper::tmpFile($extension);
+ $tmpFile=\OC_Helper::tmpFile($extension);
$target=fopen($tmpFile,'w');
- OC_Helper::streamCopy($source,$target);
+ \OC_Helper::streamCopy($source,$target);
return $tmpFile;
}
public function getLocalFolder($path) {
- $baseDir=OC_Helper::tmpFolder();
+ $baseDir=\OC_Helper::tmpFolder();
$this->addLocalFolder($path,$baseDir);
return $baseDir;
}
@@ -252,7 +222,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
}
}
}
-// abstract public function touch($path, $mtime=null);
+ abstract public function touch($path, $mtime=null);
protected function searchInDir($query,$dir='') {
$files=array();
@@ -273,6 +243,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
/**
* check if a file or folder has been updated since $time
+ * @param string $path
* @param int $time
* @return bool
*/
@@ -280,12 +251,20 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
return $this->filemtime($path)>$time;
}
+ public function getCache(){
+ return new \OC\Files\Cache\Cache($this);
+ }
+
+ public function getScanner(){
+ return new \OC\Files\Cache\Scanner($this);
+ }
+
/**
* get the owner of a path
- * @param $path The path to get the owner
+ * @param string $path The path to get the owner
* @return string uid or false
*/
public function getOwner($path) {
- return OC_User::getUser();
+ return \OC_User::getUser();
}
}
diff --git a/lib/filestorage/commontest.php b/lib/files/storage/commontest.php
index b88bb232c36..2b42cfe1156 100644
--- a/lib/filestorage/commontest.php
+++ b/lib/files/storage/commontest.php
@@ -22,20 +22,25 @@
*/
/**
- * test implementation for OC_FileStorage_Common with OC_FileStorage_Local
+ * test implementation for \OC\Files\Storage\Common with \OC\Files\Storage\Local
*/
-class OC_Filestorage_CommonTest extends OC_Filestorage_Common{
+namespace OC\Files\Storage;
+
+class CommonTest extends \OC\Files\Storage\Common{
/**
* underlying local storage used for missing functions
- * @var OC_FileStorage_Local
+ * @var \OC\Files\Storage\Local
*/
private $storage;
public function __construct($params) {
- $this->storage=new OC_Filestorage_Local($params);
+ $this->storage=new \OC\Files\Storage\Local($params);
}
+ public function getId(){
+ return 'test::'.$this->storage->getId();
+ }
public function mkdir($path) {
return $this->storage->mkdir($path);
}
diff --git a/lib/filestorage/local.php b/lib/files/storage/local.php
index 731ac4a3c72..71f3bedad39 100644
--- a/lib/filestorage/local.php
+++ b/lib/files/storage/local.php
@@ -1,8 +1,17 @@
<?php
/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Storage;
+
+/**
* for local filestore, we only have to map the paths
*/
-class OC_Filestorage_Local extends OC_Filestorage_Common{
+class Local extends \OC\Files\Storage\Common{
protected $datadir;
public function __construct($arguments) {
$this->datadir=$arguments['datadir'];
@@ -10,6 +19,9 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
$this->datadir.='/';
}
}
+ public function getId(){
+ return 'local::'.$this->datadir;
+ }
public function mkdir($path) {
return @mkdir($this->datadir.$path);
}
@@ -54,9 +66,6 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
public function file_exists($path) {
return file_exists($this->datadir.$path);
}
- public function filectime($path) {
- return filectime($this->datadir.$path);
- }
public function filemtime($path) {
return filemtime($this->datadir.$path);
}
@@ -86,11 +95,11 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
}
public function rename($path1,$path2) {
if (!$this->isUpdatable($path1)) {
- OC_Log::write('core','unable to rename, file is not writable : '.$path1,OC_Log::ERROR);
+ \OC_Log::write('core','unable to rename, file is not writable : '.$path1,\OC_Log::ERROR);
return false;
}
if(! $this->file_exists($path1)) {
- OC_Log::write('core','unable to rename, file does not exists : '.$path1,OC_Log::ERROR);
+ \OC_Log::write('core','unable to rename, file does not exists : '.$path1,\OC_Log::ERROR);
return false;
}
@@ -129,7 +138,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
public function getMimeType($path) {
if($this->isReadable($path)) {
- return OC_Helper::getMimeType($this->datadir.$path);
+ return \OC_Helper::getMimeType($this->datadir.$path);
}else{
return false;
}
diff --git a/lib/files/storage/storage.php b/lib/files/storage/storage.php
new file mode 100644
index 00000000000..1f5c9356294
--- /dev/null
+++ b/lib/files/storage/storage.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Storage;
+
+/**
+ * Provide a common interface to all different storage options
+ */
+interface Storage{
+ public function __construct($parameters);
+ public function getId();
+ public function mkdir($path);
+ public function rmdir($path);
+ public function opendir($path);
+ public function is_dir($path);
+ public function is_file($path);
+ public function stat($path);
+ public function filetype($path);
+ public function filesize($path);
+ public function isCreatable($path);
+ public function isReadable($path);
+ public function isUpdatable($path);
+ public function isDeletable($path);
+ public function isSharable($path);
+ public function getPermissions($path);
+ public function file_exists($path);
+ public function filemtime($path);
+ public function file_get_contents($path);
+ public function file_put_contents($path,$data);
+ public function unlink($path);
+ public function rename($path1,$path2);
+ public function copy($path1,$path2);
+ public function fopen($path,$mode);
+ public function getMimeType($path);
+ public function hash($type,$path,$raw = false);
+ public function free_space($path);
+ public function search($query);
+ public function touch($path, $mtime=null);
+ public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote
+ public function getLocalFolder($path);// get a path to a local version of the folder, whether the original file is local or remote
+ /**
+ * check if a file or folder has been updated since $time
+ * @param int $time
+ * @return bool
+ *
+ * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
+ * returning true for other changes in the folder is optional
+ */
+ public function hasUpdated($path,$time);
+
+ /**
+ * @return \OC\Files\Cache\Cache
+ */
+ public function getCache();
+ /**
+ * @return \OC\Files\Cache\Scanner
+ */
+ public function getScanner();
+
+ public function getOwner($path);
+}
diff --git a/lib/files/storage/temporary.php b/lib/files/storage/temporary.php
new file mode 100644
index 00000000000..ffc55e27507
--- /dev/null
+++ b/lib/files/storage/temporary.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Storage;
+
+/**
+ * local storage backnd in temporary folder for testing purpores
+ */
+class Temporary extends Local{
+ public function __construct($arguments) {
+ $this->datadir=\OC_Helper::tmpFolder();
+ }
+
+ public function cleanUp() {
+ \OC_Helper::rmdirr($this->datadir);
+ }
+
+ public function __destruct() {
+ $this->cleanUp();
+ }
+}
diff --git a/lib/files/view.php b/lib/files/view.php
new file mode 100644
index 00000000000..82455d582eb
--- /dev/null
+++ b/lib/files/view.php
@@ -0,0 +1,817 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Class to provide access to ownCloud filesystem via a "view", and methods for
+ * working with files within that view (e.g. read, write, delete, etc.). Each
+ * view is restricted to a set of directories via a virtual root. The default view
+ * uses the currently logged in user's data directory as root (parts of
+ * OC_Filesystem are merely a wrapper for OC_FilesystemView).
+ *
+ * Apps that need to access files outside of the user data folders (to modify files
+ * belonging to a user other than the one currently logged in, for example) should
+ * use this class directly rather than using OC_Filesystem, or making use of PHP's
+ * built-in file manipulation functions. This will ensure all hooks and proxies
+ * are triggered correctly.
+ *
+ * Filesystem functions are not called directly; they are passed to the correct
+ * \OC\Files\Storage\Storage object
+ */
+
+namespace OC\Files;
+
+class View {
+ private $fakeRoot = '';
+ private $internal_path_cache = array();
+ private $storage_cache = array();
+
+ public function __construct($root) {
+ $this->fakeRoot = $root;
+ }
+
+ public function getAbsolutePath($path) {
+ if (!$path) {
+ $path = '/';
+ }
+ if ($path[0] !== '/') {
+ $path = '/' . $path;
+ }
+ return $this->fakeRoot . $path;
+ }
+
+ /**
+ * change the root to a fake root
+ *
+ * @param string $fakeRoot
+ * @return bool
+ */
+ public function chroot($fakeRoot) {
+ if (!$fakeRoot == '') {
+ if ($fakeRoot[0] !== '/') {
+ $fakeRoot = '/' . $fakeRoot;
+ }
+ }
+ $this->fakeRoot = $fakeRoot;
+ }
+
+ /**
+ * get the fake root
+ *
+ * @return string
+ */
+ public function getRoot() {
+ return $this->fakeRoot;
+ }
+
+ /**
+ * get path relative to the root of the view
+ *
+ * @param string $path
+ * @return string
+ */
+ public function getRelativePath($path) {
+ if ($this->fakeRoot == '') {
+ return $path;
+ }
+ if (strpos($path, $this->fakeRoot) !== 0) {
+ return null;
+ } else {
+ $path = substr($path, strlen($this->fakeRoot));
+ if (strlen($path) === 0) {
+ return '/';
+ } else {
+ return $path;
+ }
+ }
+ }
+
+ /**
+ * get the mountpoint of the storage object for a path
+ ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account
+ *
+ * @param string $path
+ * @return string
+ */
+ public function getMountPoint($path) {
+ return Filesystem::getMountPoint($this->getAbsolutePath($path));
+ }
+
+ /**
+ * return the path to a local version of the file
+ * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed
+ *
+ * @param string $path
+ * @return string
+ */
+ public function getLocalFile($path) {
+ $parent = substr($path, 0, strrpos($path, '/'));
+ list($storage, $internalPath) = Filesystem::resolvePath($path);
+ if (Filesystem::isValidPath($parent) and $storage) {
+ return $storage->getLocalFile($internalPath);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @param string $path
+ * @return string
+ */
+ public function getLocalFolder($path) {
+ $parent = substr($path, 0, strrpos($path, '/'));
+ list($storage, $internalPath) = Filesystem::resolvePath($path);
+ if (Filesystem::isValidPath($parent) and $storage) {
+ return $storage->getLocalFolder($internalPath);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * the following functions operate with arguments and return values identical
+ * to those of their PHP built-in equivalents. Mostly they are merely wrappers
+ * for \OC\Files\Storage\Storage via basicOperation().
+ */
+ public function mkdir($path) {
+ return $this->basicOperation('mkdir', $path, array('create', 'write'));
+ }
+
+ public function rmdir($path) {
+ return $this->basicOperation('rmdir', $path, array('delete'));
+ }
+
+ public function opendir($path) {
+ return $this->basicOperation('opendir', $path, array('read'));
+ }
+
+ public function readdir($handle) {
+ $fsLocal = new Storage\Local(array('datadir' => '/'));
+ return $fsLocal->readdir($handle);
+ }
+
+ public function is_dir($path) {
+ if ($path == '/') {
+ return true;
+ }
+ return $this->basicOperation('is_dir', $path);
+ }
+
+ public function is_file($path) {
+ if ($path == '/') {
+ return false;
+ }
+ return $this->basicOperation('is_file', $path);
+ }
+
+ public function stat($path) {
+ return $this->basicOperation('stat', $path);
+ }
+
+ public function filetype($path) {
+ return $this->basicOperation('filetype', $path);
+ }
+
+ public function filesize($path) {
+ return $this->basicOperation('filesize', $path);
+ }
+
+ public function readfile($path) {
+ @ob_end_clean();
+ $handle = $this->fopen($path, 'rb');
+ if ($handle) {
+ $chunkSize = 8192; // 8 MB chunks
+ while (!feof($handle)) {
+ echo fread($handle, $chunkSize);
+ flush();
+ }
+ $size = $this->filesize($path);
+ return $size;
+ }
+ return false;
+ }
+
+ public function isCreatable($path) {
+ return $this->basicOperation('isCreatable', $path);
+ }
+
+ public function isReadable($path) {
+ return $this->basicOperation('isReadable', $path);
+ }
+
+ public function isUpdatable($path) {
+ return $this->basicOperation('isUpdatable', $path);
+ }
+
+ public function isDeletable($path) {
+ return $this->basicOperation('isDeletable', $path);
+ }
+
+ public function isSharable($path) {
+ return $this->basicOperation('isSharable', $path);
+ }
+
+ public function file_exists($path) {
+ if ($path == '/') {
+ return true;
+ }
+ return $this->basicOperation('file_exists', $path);
+ }
+
+ public function filemtime($path) {
+ return $this->basicOperation('filemtime', $path);
+ }
+
+ public function touch($path, $mtime = null) {
+ if (!is_null($mtime) and !is_numeric($mtime)) {
+ $mtime = strtotime($mtime);
+ }
+ return $this->basicOperation('touch', $path, array('write'), $mtime);
+ }
+
+ public function file_get_contents($path) {
+ return $this->basicOperation('file_get_contents', $path, array('read'));
+ }
+
+ public function file_put_contents($path, $data) {
+ if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
+ $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
+ if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && Filesystem::isValidPath($path)) {
+ $path = $this->getRelativePath($absolutePath);
+ $exists = $this->file_exists($path);
+ $run = true;
+ if ($this->fakeRoot == Filesystem::getRoot()) {
+ if (!$exists) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_create,
+ array(
+ Filesystem::signal_param_path => $path,
+ Filesystem::signal_param_run => &$run
+ )
+ );
+ }
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_write,
+ array(
+ Filesystem::signal_param_path => $path,
+ Filesystem::signal_param_run => &$run
+ )
+ );
+ }
+ if (!$run) {
+ return false;
+ }
+ $target = $this->fopen($path, 'w');
+ if ($target) {
+ $count = \OC_Helper::streamCopy($data, $target);
+ fclose($target);
+ fclose($data);
+ if ($this->fakeRoot == Filesystem::getRoot()) {
+ if (!$exists) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_create,
+ array(Filesystem::signal_param_path => $path)
+ );
+ }
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_write,
+ array(Filesystem::signal_param_path => $path)
+ );
+ }
+ \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
+ return $count > 0;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } else {
+ return $this->basicOperation('file_put_contents', $path, array('create', 'write'), $data);
+ }
+ }
+
+ public function unlink($path) {
+ return $this->basicOperation('unlink', $path, array('delete'));
+ }
+
+ public function deleteAll($directory, $empty = false) {
+ return $this->basicOperation('deleteAll', $directory, array('delete'), $empty);
+ }
+
+ public function rename($path1, $path2) {
+ $postFix1 = (substr($path1, -1, 1) === '/') ? '/' : '';
+ $postFix2 = (substr($path2, -1, 1) === '/') ? '/' : '';
+ $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
+ $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
+ if (\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2)) {
+ $path1 = $this->getRelativePath($absolutePath1);
+ $path2 = $this->getRelativePath($absolutePath2);
+
+ if ($path1 == null or $path2 == null) {
+ return false;
+ }
+ $run = true;
+ if ($this->fakeRoot == Filesystem::getRoot()) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME, Filesystem::signal_rename,
+ array(
+ Filesystem::signal_param_oldpath => $path1,
+ Filesystem::signal_param_newpath => $path2,
+ Filesystem::signal_param_run => &$run
+ )
+ );
+ }
+ if ($run) {
+ $mp1 = $this->getMountPoint($path1 . $postFix1);
+ $mp2 = $this->getMountPoint($path2 . $postFix2);
+ if ($mp1 == $mp2) {
+ list($storage, $internalPath1) = Filesystem::resolvePath($path1 . $postFix1);
+ list(, $internalPath2) = Filesystem::resolvePath($path2 . $postFix2);
+ if ($storage) {
+ $result = $storage->rename($internalPath1, $internalPath2);
+ } else {
+ $result = false;
+ }
+ } else {
+ $source = $this->fopen($path1 . $postFix1, 'r');
+ $target = $this->fopen($path2 . $postFix2, 'w');
+ $count = \OC_Helper::streamCopy($source, $target);
+ list($storage1, $internalPath1) = Filesystem::resolvePath($path1 . $postFix1);
+ $storage1->unlink($internalPath1);
+ $result = $count > 0;
+ }
+ if ($this->fakeRoot == Filesystem::getRoot()) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_rename,
+ array(
+ Filesystem::signal_param_oldpath => $path1,
+ Filesystem::signal_param_newpath => $path2
+ )
+ );
+ }
+ return $result;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function copy($path1, $path2) {
+ $postFix1 = (substr($path1, -1, 1) === '/') ? '/' : '';
+ $postFix2 = (substr($path2, -1, 1) === '/') ? '/' : '';
+ $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
+ $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
+ if (\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2)) {
+ $path1 = $this->getRelativePath($absolutePath1);
+ $path2 = $this->getRelativePath($absolutePath2);
+
+ if ($path1 == null or $path2 == null) {
+ return false;
+ }
+ $run = true;
+ $exists = $this->file_exists($path2);
+ if ($this->fakeRoot == Filesystem::getRoot()) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_copy,
+ array(
+ Filesystem::signal_param_oldpath => $path1,
+ Filesystem::signal_param_newpath => $path2,
+ Filesystem::signal_param_run => &$run
+ )
+ );
+ if ($run and !$exists) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_create,
+ array(
+ Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_run => &$run
+ )
+ );
+ }
+ if ($run) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_write,
+ array(
+ Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_run => &$run
+ )
+ );
+ }
+ }
+ if ($run) {
+ $mp1 = $this->getMountPoint($path1 . $postFix1);
+ $mp2 = $this->getMountPoint($path2 . $postFix2);
+ if ($mp1 == $mp2) {
+ list($storage, $internalPath1) = Filesystem::resolvePath($path1 . $postFix1);
+ list(, $internalPath2) = Filesystem::resolvePath($path2 . $postFix2);
+ if ($storage) {
+ $result = $storage->copy($internalPath1, $internalPath2);
+ } else {
+ $result = false;
+ }
+ } else {
+ $source = $this->fopen($path1 . $postFix1, 'r');
+ $target = $this->fopen($path2 . $postFix2, 'w');
+ $result = \OC_Helper::streamCopy($source, $target);
+ }
+ if ($this->fakeRoot == Filesystem::getRoot()) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_copy,
+ array(
+ Filesystem::signal_param_oldpath => $path1,
+ Filesystem::signal_param_newpath => $path2
+ )
+ );
+ if (!$exists) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_create,
+ array(Filesystem::signal_param_path => $path2)
+ );
+ }
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_write,
+ array(Filesystem::signal_param_path => $path2)
+ );
+ } else { // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions
+ Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot);
+ }
+ return $result;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function fopen($path, $mode) {
+ $hooks = array();
+ switch ($mode) {
+ case 'r':
+ case 'rb':
+ $hooks[] = 'read';
+ break;
+ case 'r+':
+ case 'rb+':
+ case 'w+':
+ case 'wb+':
+ case 'x+':
+ case 'xb+':
+ case 'a+':
+ case 'ab+':
+ $hooks[] = 'read';
+ $hooks[] = 'write';
+ break;
+ case 'w':
+ case 'wb':
+ case 'x':
+ case 'xb':
+ case 'a':
+ case 'ab':
+ $hooks[] = 'write';
+ break;
+ default:
+ \OC_Log::write('core', 'invalid mode (' . $mode . ') for ' . $path, \OC_Log::ERROR);
+ }
+
+ return $this->basicOperation('fopen', $path, $hooks, $mode);
+ }
+
+ public function toTmpFile($path) {
+ if (Filesystem::isValidPath($path)) {
+ $source = $this->fopen($path, 'r');
+ if ($source) {
+ $extension = '';
+ $extOffset = strpos($path, '.');
+ if ($extOffset !== false) {
+ $extension = substr($path, strrpos($path, '.'));
+ }
+ $tmpFile = \OC_Helper::tmpFile($extension);
+ file_put_contents($tmpFile, $source);
+ return $tmpFile;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function fromTmpFile($tmpFile, $path) {
+ if (Filesystem::isValidPath($path)) {
+ if (!$tmpFile) {
+ debug_print_backtrace();
+ }
+ $source = fopen($tmpFile, 'r');
+ if ($source) {
+ $this->file_put_contents($path, $source);
+ unlink($tmpFile);
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function getMimeType($path) {
+ return $this->basicOperation('getMimeType', $path);
+ }
+
+ public function hash($type, $path, $raw = false) {
+ $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+ $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
+ if (\OC_FileProxy::runPreProxies('hash', $absolutePath) && Filesystem::isValidPath($path)) {
+ $path = $this->getRelativePath($absolutePath);
+ if ($path == null) {
+ return false;
+ }
+ if (Filesystem::$loaded && $this->fakeRoot == Filesystem::getRoot()) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_read,
+ array(Filesystem::signal_param_path => $path)
+ );
+ }
+ list($storage, $internalPath) = Filesystem::resolvePath($path . $postFix);
+ if ($storage) {
+ $result = $storage->hash($type, $internalPath, $raw);
+ $result = \OC_FileProxy::runPostProxies('hash', $absolutePath, $result);
+ return $result;
+ }
+ }
+ return null;
+ }
+
+ public function free_space($path = '/') {
+ return $this->basicOperation('free_space', $path);
+ }
+
+ /**
+ * @brief abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage
+ * @param string $operation
+ * @param string $path
+ * @param array $hooks (optional)
+ * @param mixed $extraParam (optional)
+ * @return mixed
+ *
+ * This method takes requests for basic filesystem functions (e.g. reading & writing
+ * files), processes hooks and proxies, sanitises paths, and finally passes them on to
+ * \OC\Files\Storage\Storage for delegation to a storage backend for execution
+ */
+ private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) {
+ $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+ $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
+ if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and Filesystem::isValidPath($path)) {
+ $path = $this->getRelativePath($absolutePath);
+ if ($path == null) {
+ return false;
+ }
+ $run = $this->runHooks($hooks, $path);
+ list($storage, $internalPath) = Filesystem::resolvePath($path . $postFix);
+ if ($run and $storage) {
+ if (!is_null($extraParam)) {
+ $result = $storage->$operation($internalPath, $extraParam);
+ } else {
+ $result = $storage->$operation($internalPath);
+ }
+ $result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
+ if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot()) {
+ if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
+ $this->runHooks($hooks, $path, true);
+ }
+ }
+ return $result;
+ }
+ }
+ return null;
+ }
+
+ private function runHooks($hooks, $path, $post = false) {
+ $prefix = ($post) ? 'post_' : '';
+ $run = true;
+ if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot()) {
+ foreach ($hooks as $hook) {
+ if ($hook != 'read') {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ $prefix . $hook,
+ array(
+ Filesystem::signal_param_run => &$run,
+ Filesystem::signal_param_path => $path
+ )
+ );
+ } elseif (!$post) {
+ \OC_Hook::emit(
+ Filesystem::CLASSNAME,
+ $prefix . $hook,
+ array(
+ Filesystem::signal_param_path => $path
+ )
+ );
+ }
+ }
+ }
+ return $run;
+ }
+
+ /**
+ * check if a file or folder has been updated since $time
+ *
+ * @param string $path
+ * @param int $time
+ * @return bool
+ */
+ public function hasUpdated($path, $time) {
+ return $this->basicOperation('hasUpdated', $path, array(), $time);
+ }
+
+ /**
+ * get the filesystem info
+ *
+ * @param string $path
+ * @return array
+ *
+ * returns an associative array with the following keys:
+ * - size
+ * - mtime
+ * - mimetype
+ * - encrypted
+ * - versioned
+ */
+ public function getFileInfo($path) {
+ $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ * @var string $internalPath
+ */
+ list($storage, $internalPath) = Filesystem::resolvePath($path);
+ $cache = $storage->getCache();
+
+ if (!$cache->inCache($internalPath)) {
+ $scanner = $storage->getScanner();
+ $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
+ }
+
+ $data = $cache->get($internalPath);
+
+ if ($data['mimetype'] === 'httpd/unix-directory') {
+ //add the sizes of other mountpoints to the folder
+ $mountPoints = Filesystem::getMountPoints($path);
+ foreach ($mountPoints as $mountPoint) {
+ $subStorage = Filesystem::getStorage($mountPoint);
+ $subCache = $subStorage->getCache();
+ $rootEntry = $subCache->get('');
+
+ $data['size'] += $rootEntry['size'];
+ }
+ }
+
+ $data['permissions'] = Cache\Permissions::get($data['fileid'], \OC_User::getUser());
+
+ return $data;
+ }
+
+ /**
+ * get the content of a directory
+ *
+ * @param string $directory path under datadirectory
+ * @return array
+ */
+ public function getDirectoryContent($directory, $mimetype_filter = '') {
+ $path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ * @var string $internalPath
+ */
+ list($storage, $internalPath) = Filesystem::resolvePath($path);
+ $cache = $storage->getCache();
+
+ if (!$cache->inCache($internalPath)) {
+ $scanner = $storage->getScanner();
+ $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
+ }
+
+ $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+
+ //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
+ $mountPoints = Filesystem::getMountPoints($path);
+ $dirLength = strlen($path);
+ foreach ($mountPoints as $mountPoint) {
+ $subStorage = Filesystem::getStorage($mountPoint);
+ $subCache = $subStorage->getCache();
+ $rootEntry = $subCache->get('');
+
+ $relativePath = trim(substr($mountPoint, $dirLength), '/');
+ if ($pos = strpos($relativePath, '/')) { //mountpoint inside subfolder add size to the correct folder
+ $entryName = substr($relativePath, 0, $pos);
+ foreach ($files as &$entry) {
+ if ($entry['name'] === $entryName) {
+ $entry['size'] += $rootEntry['size'];
+ }
+ }
+ } else { //mountpoint in this folder, add an entry for it
+ $rootEntry['name'] = $relativePath;
+ $files[] = $rootEntry;
+ }
+ }
+
+ $ids = array();
+
+ foreach ($files as $i => $file) {
+ $files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
+ $ids[] = $file['fileid'];
+ }
+
+ $permissions = Cache\Permissions::getMultiple($ids, \OC_User::getUser());
+ foreach ($files as $i => $file) {
+ $files[$i]['permissions'] = $permissions[$file['fileid']];
+ }
+
+ usort($files, "fileCmp"); //TODO: remove this once ajax is merged
+ return $files;
+ }
+
+ /**
+ * change file metadata
+ *
+ * @param string $path
+ * @param array $data
+ * @return int
+ *
+ * returns the fileid of the updated file
+ */
+ public function putFileInfo($path, $data) {
+ $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ * @var string $internalPath
+ */
+ list($storage, $internalPath) = Filesystem::resolvePath($path);
+ $cache = $storage->getCache();
+
+ if (!$cache->inCache($internalPath)) {
+ $scanner = $storage->getScanner();
+ $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
+ }
+
+ return $cache->put($internalPath, $data);
+ }
+
+ /**
+ * search for files with the name matching $query
+ *
+ * @param string $query
+ * @return array
+ */
+ public function search($query) {
+ $files = array();
+ $rootLength = strlen($this->fakeRoot);
+
+ $mountPoint = Filesystem::getMountPoint($this->fakeRoot);
+ $storage = Filesystem::getStorage($mountPoint);
+ $cache = $storage->getCache();
+
+ $results = $cache->search('%' . $query . '%');
+ foreach ($results as $result) {
+ if (substr($mountPoint . $result['path'], 0, $rootLength) === $this->fakeRoot) {
+ $result['path'] = substr($mountPoint . $result['path'], $rootLength);
+ $files[] = $result;
+ }
+ }
+
+ $mountPoints = Filesystem::getMountPoints($this->fakeRoot);
+ foreach ($mountPoints as $mountPoint) {
+ $storage = Filesystem::getStorage($mountPoint);
+ $cache = $storage->getCache();
+
+ $relativeMountPoint = substr($mountPoint, $rootLength);
+ $results = $cache->search('%' . $query . '%');
+ foreach ($results as $result) {
+ $result['path'] = $relativeMountPoint . $result['path'];
+ $files[] = $result;
+ }
+ }
+
+ return $files;
+ }
+}
diff --git a/lib/filestorage.php b/lib/filestorage.php
deleted file mode 100644
index 146cecf4efa..00000000000
--- a/lib/filestorage.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
-*/
-
-/**
- * Provde a common interface to all different storage options
- */
-abstract class OC_Filestorage{
- abstract public function __construct($parameters);
- abstract public function mkdir($path);
- abstract public function rmdir($path);
- abstract public function opendir($path);
- abstract public function is_dir($path);
- abstract public function is_file($path);
- abstract public function stat($path);
- abstract public function filetype($path);
- abstract public function filesize($path);
- abstract public function isCreatable($path);
- abstract public function isReadable($path);
- abstract public function isUpdatable($path);
- abstract public function isDeletable($path);
- abstract public function isSharable($path);
- abstract public function file_exists($path);
- abstract public function filectime($path);
- abstract public function filemtime($path);
- abstract public function file_get_contents($path);
- abstract public function file_put_contents($path,$data);
- abstract public function unlink($path);
- abstract public function rename($path1,$path2);
- abstract public function copy($path1,$path2);
- abstract public function fopen($path,$mode);
- abstract public function getMimeType($path);
- abstract public function hash($type,$path,$raw = false);
- abstract public function free_space($path);
- abstract public function search($query);
- abstract public function touch($path, $mtime=null);
- abstract public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote
- abstract public function getLocalFolder($path);// get a path to a local version of the folder, whether the original file is local or remote
- /**
- * check if a file or folder has been updated since $time
- * @param int $time
- * @return bool
- *
- * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
- * returning true for other changes in the folder is optional
- */
- abstract public function hasUpdated($path,$time);
- abstract public function getOwner($path);
-}
diff --git a/lib/filestorage/temporary.php b/lib/filestorage/temporary.php
deleted file mode 100644
index 876ba045a63..00000000000
--- a/lib/filestorage/temporary.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-/**
- * local storage backnd in temporary folder for testing purpores
- */
-class OC_Filestorage_Temporary extends OC_Filestorage_Local{
- public function __construct($arguments) {
- $this->datadir=OC_Helper::tmpFolder();
- }
-
- public function cleanUp() {
- OC_Helper::rmdirr($this->datadir);
- }
-
- public function __destruct() {
- $this->cleanUp();
- }
-}
diff --git a/lib/filesystem.php b/lib/filesystem.php
index bc30dac7fa1..20b5ab27909 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -1,26 +1,11 @@
<?php
/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
-*
-*/
-
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
/**
* Class for abstraction of filesystem functions
@@ -31,572 +16,404 @@
* read(path)
* write(path, &run)
* post_write(path)
- * create(path, &run) (when a file is created, both create and write will be emited in that order)
+ * create(path, &run) (when a file is created, both create and write will be emitted in that order)
* post_create(path)
* delete(path, &run)
* post_delete(path)
* rename(oldpath,newpath, &run)
* post_rename(oldpath,newpath)
- * copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emited in that order)
+ * copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emitted in that order)
* post_rename(oldpath,newpath)
*
- * the &run parameter can be set to false to prevent the operation from occuring
+ * the &run parameter can be set to false to prevent the operation from occurring
*/
-class OC_Filesystem{
- static private $storages=array();
- static private $mounts=array();
- static private $loadedUsers=array();
- public static $loaded=false;
- /**
- * @var OC_Filestorage $defaultInstance
- */
- static private $defaultInstance;
-
-
- /**
- * classname which used for hooks handling
- * used as signalclass in OC_Hooks::emit()
- */
- const CLASSNAME = 'OC_Filesystem';
-
- /**
- * signalname emited before file renaming
- * @param oldpath
- * @param newpath
- */
- const signal_rename = 'rename';
-
- /**
- * signal emited after file renaming
- * @param oldpath
- * @param newpath
- */
- const signal_post_rename = 'post_rename';
-
- /**
- * signal emited before file/dir creation
- * @param path
- * @param run changing this flag to false in hook handler will cancel event
- */
- const signal_create = 'create';
-
- /**
- * signal emited after file/dir creation
- * @param path
- * @param run changing this flag to false in hook handler will cancel event
- */
- const signal_post_create = 'post_create';
-
- /**
- * signal emits before file/dir copy
- * @param oldpath
- * @param newpath
- * @param run changing this flag to false in hook handler will cancel event
- */
- const signal_copy = 'copy';
-
- /**
- * signal emits after file/dir copy
- * @param oldpath
- * @param newpath
- */
- const signal_post_copy = 'post_copy';
-
- /**
- * signal emits before file/dir save
- * @param path
- * @param run changing this flag to false in hook handler will cancel event
- */
- const signal_write = 'write';
-
- /**
- * signal emits after file/dir save
- * @param path
- */
- const signal_post_write = 'post_write';
-
- /**
- * signal emits when reading file/dir
- * @param path
- */
- const signal_read = 'read';
-
- /**
- * signal emits when removing file/dir
- * @param path
- */
- const signal_delete = 'delete';
-
+/**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+class OC_Filesystem {
/**
- * parameters definitions for signals
+ * get the mountpoint of the storage object for a path
+ ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
+ * @return string
*/
- const signal_param_path = 'path';
- const signal_param_oldpath = 'oldpath';
- const signal_param_newpath = 'newpath';
+ static public function getMountPoint($path) {
+ return \OC\Files\Filesystem::getMountPoint($path);
+ }
/**
- * run - changing this flag to false in hook handler will cancel event
+ * resolve a path to a storage and internal path
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
+ * @return array consisting of the storage and the internal path
*/
- const signal_param_run = 'run';
+ static public function resolvePath($path) {
+ return \OC\Files\Filesystem::resolvePath($path);
+ }
/**
- * get the mountpoint of the storage object for a path
- ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account
- *
- * @param string path
- * @return string
- */
- static public function getMountPoint($path) {
- OC_Hook::emit(self::CLASSNAME,'get_mountpoint', array('path'=>$path));
- if(!$path) {
- $path='/';
- }
- if($path[0]!=='/') {
- $path='/'.$path;
- }
- $path=str_replace('//', '/',$path);
- $foundMountPoint='';
- $mountPoints=array_keys(OC_Filesystem::$mounts);
- foreach($mountPoints as $mountpoint) {
- if($mountpoint==$path) {
- return $mountpoint;
- }
- if(strpos($path,$mountpoint)===0 and strlen($mountpoint)>strlen($foundMountPoint)) {
- $foundMountPoint=$mountpoint;
- }
- }
- return $foundMountPoint;
- }
-
- /**
- * get the part of the path relative to the mountpoint of the storage it's stored in
- * @param string path
- * @return bool
- */
- static public function getInternalPath($path) {
- $mountPoint=self::getMountPoint($path);
- $internalPath=substr($path, strlen($mountPoint));
- return $internalPath;
- }
-
- static private function mountPointsLoaded($user) {
- return in_array($user, self::$loadedUsers);
- }
-
- /**
- * get the storage object for a path
- * @param string path
- * @return OC_Filestorage
- */
- static public function getStorage($path) {
- $user = ltrim(substr($path, 0, strpos($path, '/', 1)), '/');
- // check mount points if file was shared from a different user
- if ($user != OC_User::getUser() && !self::mountPointsLoaded($user)) {
- OC_Util::loadUserMountPoints($user);
- self::loadSystemMountPoints($user);
- self::$loadedUsers[] = $user;
- }
-
- $mountpoint=self::getMountPoint($path);
- if($mountpoint) {
- if(!isset(OC_Filesystem::$storages[$mountpoint])) {
- $mount=OC_Filesystem::$mounts[$mountpoint];
- OC_Filesystem::$storages[$mountpoint]=OC_Filesystem::createStorage($mount['class'],$mount['arguments']);
- }
- return OC_Filesystem::$storages[$mountpoint];
- }
- }
-
- static private function loadSystemMountPoints($user) {
- if(is_file(OC::$SERVERROOT.'/config/mount.php')) {
- $mountConfig=include OC::$SERVERROOT.'/config/mount.php';
- if(isset($mountConfig['global'])) {
- foreach($mountConfig['global'] as $mountPoint=>$options) {
- self::mount($options['class'],$options['options'],$mountPoint);
- }
- }
-
- if(isset($mountConfig['group'])) {
- foreach($mountConfig['group'] as $group=>$mounts) {
- if(OC_Group::inGroup($user,$group)) {
- foreach($mounts as $mountPoint=>$options) {
- $mountPoint=self::setUserVars($mountPoint, $user);
- foreach($options as &$option) {
- $option=self::setUserVars($option, $user);
- }
- self::mount($options['class'],$options['options'],$mountPoint);
- }
- }
- }
- }
-
- if(isset($mountConfig['user'])) {
- foreach($mountConfig['user'] as $user=>$mounts) {
- if($user==='all' or strtolower($user)===strtolower($user)) {
- foreach($mounts as $mountPoint=>$options) {
- $mountPoint=self::setUserVars($mountPoint, $user);
- foreach($options as &$option) {
- $option=self::setUserVars($option, $user);
- }
- self::mount($options['class'],$options['options'],$mountPoint);
- }
- }
- }
- }
-
- $mtime=filemtime(OC::$SERVERROOT.'/config/mount.php');
- $previousMTime=OC_Appconfig::getValue('files','mountconfigmtime',0);
- if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated
- OC_FileCache::triggerUpdate();
- OC_Appconfig::setValue('files','mountconfigmtime',$mtime);
- }
- }
- }
-
- static public function init($root, $user = '') {
- if(self::$defaultInstance) {
- return false;
- }
- self::$defaultInstance=new OC_FilesystemView($root);
-
- //load custom mount config
- if (!isset($user)) {
- $user = OC_User::getUser();
- }
- self::loadSystemMountPoints($user);
-
- self::$loaded=true;
- }
-
- /**
- * fill in the correct values for $user, and $password placeholders
- * @param string intput
- * @return string
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
*/
- private static function setUserVars($input, $user) {
- if (isset($user)) {
- return str_replace('$user', $user,$input);
- } else {
- return str_replace('$user',OC_User::getUser(),$input);
- }
+ static public function init($root) {
+ return \OC\Files\Filesystem::init($root);
}
/**
* get the default filesystem view
- * @return OC_FilesystemView
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @return \OC\Files\View
*/
static public function getView() {
- return self::$defaultInstance;
+ return \OC\Files\Filesystem::getView();
}
/**
* tear down the filesystem, removing all storage providers
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
*/
static public function tearDown() {
- self::$storages=array();
- }
-
- /**
- * create a new storage of a specific type
- * @param string type
- * @param array arguments
- * @return OC_Filestorage
- */
- static private function createStorage($class,$arguments) {
- if(class_exists($class)) {
- try {
- return new $class($arguments);
- } catch (Exception $exception) {
- OC_Log::write('core', $exception->getMessage(), OC_Log::ERROR);
- return false;
- }
- }else{
- OC_Log::write('core','storage backend '.$class.' not found',OC_Log::ERROR);
- return false;
- }
- }
-
- /**
- * change the root to a fake root
- * @param string fakeRoot
- * @return bool
- */
- static public function chroot($fakeRoot) {
- return self::$defaultInstance->chroot($fakeRoot);
+ \OC\Files\Filesystem::tearDown();
}
/**
* @brief get the relative path of the root data directory for the current user
* @return string
*
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
* Returns path like /admin/files
*/
static public function getRoot() {
- return self::$defaultInstance->getRoot();
+ return \OC\Files\Filesystem::getRoot();
}
/**
* clear all mounts and storage backends
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
*/
public static function clearMounts() {
- self::$mounts=array();
- self::$storages=array();
+ \OC\Files\Filesystem::clearMounts();
}
/**
- * mount an OC_Filestorage in our virtual filesystem
- * @param OC_Filestorage storage
- * @param string mountpoint
- */
- static public function mount($class,$arguments,$mountpoint) {
- if($mountpoint[0]!='/') {
- $mountpoint='/'.$mountpoint;
- }
- if(substr($mountpoint,-1)!=='/') {
- $mountpoint=$mountpoint.'/';
- }
- self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments);
+ * mount an \OC\Files\Storage\Storage in our virtual filesystem
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param \OC\Files\Storage\Storage $class
+ * @param array $arguments
+ * @param string $mountpoint
+ */
+ static public function mount($class, $arguments, $mountpoint) {
+ \OC\Files\Filesystem::mount($class, $arguments, $mountpoint);
}
/**
- * return the path to a local version of the file
- * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed
- * @param string path
- * @return string
- */
+ * return the path to a local version of the file
+ * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
+ * @return string
+ */
static public function getLocalFile($path) {
- return self::$defaultInstance->getLocalFile($path);
+ return \OC\Files\Filesystem::getLocalFile($path);
}
+
/**
- * @param string path
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
* @return string
*/
static public function getLocalFolder($path) {
- return self::$defaultInstance->getLocalFolder($path);
+ return \OC\Files\Filesystem::getLocalFolder($path);
}
/**
- * return path to file which reflects one visible in browser
- * @param string path
- * @return string
- */
+ * return path to file which reflects one visible in browser
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
+ * @return string
+ */
static public function getLocalPath($path) {
- $datadir = OC_User::getHome(OC_User::getUser()).'/files';
- $newpath = $path;
- if (strncmp($newpath, $datadir, strlen($datadir)) == 0) {
- $newpath = substr($path, strlen($datadir));
- }
- return $newpath;
+ return \OC\Files\Filesystem::getLocalPath($path);
}
/**
* check if the requested path is valid
- * @param string path
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
* @return bool
*/
static public function isValidPath($path) {
- if(!$path || $path[0]!=='/') {
- $path='/'.$path;
- }
- if(strstr($path,'/../') || strrchr($path, '/') === '/..' ) {
- return false;
- }
- return true;
+ return \OC\Files\Filesystem::isValidPath($path);
}
/**
- * checks if a file is blacklsited for storage in the filesystem
+ * checks if a file is blacklisted for storage in the filesystem
* Listens to write and rename hooks
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
* @param array $data from hook
*/
static public function isBlacklisted($data) {
- $blacklist = array('.htaccess');
- if (isset($data['path'])) {
- $path = $data['path'];
- } else if (isset($data['newpath'])) {
- $path = $data['newpath'];
- }
- if (isset($path)) {
- $filename = strtolower(basename($path));
- if (in_array($filename, $blacklist)) {
- $data['run'] = false;
- }
- }
+ \OC\Files\Filesystem::isBlacklisted($data);
}
/**
- * following functions are equivilent to their php buildin equivilents for arguments/return values.
+ * following functions are equivalent to their php builtin equivalents for arguments/return values.
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
*/
static public function mkdir($path) {
- return self::$defaultInstance->mkdir($path);
+ return \OC\Files\Filesystem::mkdir($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function rmdir($path) {
- return self::$defaultInstance->rmdir($path);
+ return \OC\Files\Filesystem::rmdir($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function opendir($path) {
- return self::$defaultInstance->opendir($path);
+ return \OC\Files\Filesystem::opendir($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function readdir($path) {
- return self::$defaultInstance->readdir($path);
+ return \OC\Files\Filesystem::readdir($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function is_dir($path) {
- return self::$defaultInstance->is_dir($path);
+ return \OC\Files\Filesystem::is_dir($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function is_file($path) {
- return self::$defaultInstance->is_file($path);
+ return \OC\Files\Filesystem::is_file($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function stat($path) {
- return self::$defaultInstance->stat($path);
+ return \OC\Files\Filesystem::stat($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function filetype($path) {
- return self::$defaultInstance->filetype($path);
+ return \OC\Files\Filesystem::filetype($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function filesize($path) {
- return self::$defaultInstance->filesize($path);
+ return \OC\Files\Filesystem::filesize($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function readfile($path) {
- return self::$defaultInstance->readfile($path);
+ return \OC\Files\Filesystem::readfile($path);
}
+
/**
- * @deprecated Replaced by isReadable() as part of CRUDS
- */
+ * @deprecated Replaced by isReadable() as part of CRUDS
+ */
static public function is_readable($path) {
- return self::$defaultInstance->is_readable($path);
+ return \OC\Files\Filesystem::isReadable($path);
}
+
/**
- * @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS
- */
- static public function is_writable($path) {
- return self::$defaultInstance->is_writable($path);
- }
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function isCreatable($path) {
- return self::$defaultInstance->isCreatable($path);
+ return \OC\Files\Filesystem::isCreatable($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function isReadable($path) {
- return self::$defaultInstance->isReadable($path);
+ return \OC\Files\Filesystem::isReadable($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function isUpdatable($path) {
- return self::$defaultInstance->isUpdatable($path);
+ return \OC\Files\Filesystem::isUpdatable($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function isDeletable($path) {
- return self::$defaultInstance->isDeletable($path);
+ return \OC\Files\Filesystem::isDeletable($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function isSharable($path) {
- return self::$defaultInstance->isSharable($path);
+ return \OC\Files\Filesystem::isSharable($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function file_exists($path) {
- return self::$defaultInstance->file_exists($path);
- }
- static public function filectime($path) {
- return self::$defaultInstance->filectime($path);
+ return \OC\Files\Filesystem::file_exists($path);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function filemtime($path) {
- return self::$defaultInstance->filemtime($path);
+ return \OC\Files\Filesystem::filemtime($path);
}
- static public function touch($path, $mtime=null) {
- return self::$defaultInstance->touch($path, $mtime);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function touch($path, $mtime = null) {
+ return \OC\Files\Filesystem::touch($path, $mtime);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function file_get_contents($path) {
- return self::$defaultInstance->file_get_contents($path);
+ return \OC\Files\Filesystem::file_get_contents($path);
}
- static public function file_put_contents($path,$data) {
- return self::$defaultInstance->file_put_contents($path,$data);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function file_put_contents($path, $data) {
+ return \OC\Files\Filesystem::file_put_contents($path, $data);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function unlink($path) {
- return self::$defaultInstance->unlink($path);
+ return \OC\Files\Filesystem::unlink($path);
}
- static public function rename($path1,$path2) {
- return self::$defaultInstance->rename($path1,$path2);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function rename($path1, $path2) {
+ return \OC\Files\Filesystem::rename($path1, $path2);
}
- static public function copy($path1,$path2) {
- return self::$defaultInstance->copy($path1,$path2);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function copy($path1, $path2) {
+ return \OC\Files\Filesystem::copy($path1, $path2);
}
- static public function fopen($path,$mode) {
- return self::$defaultInstance->fopen($path,$mode);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function fopen($path, $mode) {
+ return \OC\Files\Filesystem::fopen($path, $mode);
}
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function toTmpFile($path) {
- return self::$defaultInstance->toTmpFile($path);
+ return \OC\Files\Filesystem::toTmpFile($path);
}
- static public function fromTmpFile($tmpFile,$path) {
- return self::$defaultInstance->fromTmpFile($tmpFile,$path);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function fromTmpFile($tmpFile, $path) {
+ return \OC\Files\Filesystem::fromTmpFile($tmpFile, $path);
}
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function getMimeType($path) {
- return self::$defaultInstance->getMimeType($path);
+ return \OC\Files\Filesystem::getMimeType($path);
}
- static public function hash($type,$path, $raw = false) {
- return self::$defaultInstance->hash($type,$path, $raw);
+
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function hash($type, $path, $raw = false) {
+ return \OC\Files\Filesystem::hash($type, $path, $raw);
}
- static public function free_space($path='/') {
- return self::$defaultInstance->free_space($path);
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
+ static public function free_space($path = '/') {
+ return \OC\Files\Filesystem::free_space($path);
}
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function search($query) {
- return OC_FileCache::search($query);
+ return \OC\Files\Filesystem::search($query);
}
/**
* check if a file or folder has been updated since $time
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
* @param int $time
* @return bool
*/
- static public function hasUpdated($path,$time) {
- return self::$defaultInstance->hasUpdated($path,$time);
+ static public function hasUpdated($path, $time) {
+ return \OC\Files\Filesystem::hasUpdated($path, $time);
}
+ /**
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ */
static public function removeETagHook($params, $root = false) {
- if (isset($params['path'])) {
- $path=$params['path'];
- } else {
- $path=$params['oldpath'];
- }
-
- if ($root) { // reduce path to the required part of it (no 'username/files')
- $fakeRootView = new OC_FilesystemView($root);
- $count = 1;
- $path=str_replace(OC_App::getStorage("files")->getAbsolutePath(), "", $fakeRootView->getAbsolutePath($path), $count);
- }
-
- $path = self::normalizePath($path);
- OC_Connector_Sabre_Node::removeETagPropertyForPath($path);
+ \OC\Files\Filesystem::removeETagHook($params, $root);
}
/**
* normalize a path
- * @param string path
+ *
+ * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
+ * @param string $path
* @param bool $stripTrailingSlash
* @return string
*/
- public static function normalizePath($path,$stripTrailingSlash=true) {
- if($path=='') {
- return '/';
- }
- //no windows style slashes
- $path=str_replace('\\','/',$path);
- //add leading slash
- if($path[0]!=='/') {
- $path='/'.$path;
- }
- //remove trainling slash
- if($stripTrailingSlash and strlen($path)>1 and substr($path,-1,1)==='/') {
- $path=substr($path,0,-1);
- }
- //remove duplicate slashes
- while(strpos($path,'//')!==false) {
- $path=str_replace('//','/',$path);
- }
- //normalize unicode if possible
- if(class_exists('Normalizer')) {
- $path=Normalizer::normalize($path);
- }
- return $path;
+ public static function normalizePath($path, $stripTrailingSlash = true) {
+ return \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash);
}
}
-OC_Hook::connect('OC_Filesystem','post_write', 'OC_Filesystem','removeETagHook');
-OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook');
-OC_Hook::connect('OC_Filesystem','post_rename','OC_Filesystem','removeETagHook');
-
-OC_Util::setupFS();
-require_once 'filecache.php';
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
deleted file mode 100644
index 872da992fab..00000000000
--- a/lib/filesystemview.php
+++ /dev/null
@@ -1,636 +0,0 @@
-<?php
-
-/**
- * ownCloud
- *
- * @author Frank Karlitschek
- * @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
- */
-
-
-/**
- * Class to provide access to ownCloud filesystem via a "view", and methods for
- * working with files within that view (e.g. read, write, delete, etc.). Each
- * view is restricted to a set of directories via a virtual root. The default view
- * uses the currently logged in user's data directory as root (parts of
- * OC_Filesystem are merely a wrapper for OC_FilesystemView).
- *
- * Apps that need to access files outside of the user data folders (to modify files
- * belonging to a user other than the one currently logged in, for example) should
- * use this class directly rather than using OC_Filesystem, or making use of PHP's
- * built-in file manipulation functions. This will ensure all hooks and proxies
- * are triggered correctly.
- *
- * Filesystem functions are not called directly; they are passed to the correct
- * OC_Filestorage object
- */
-
-class OC_FilesystemView {
- private $fakeRoot='';
- private $internal_path_cache=array();
- private $storage_cache=array();
-
- public function __construct($root) {
- $this->fakeRoot=$root;
- }
-
- public function getAbsolutePath($path) {
- if(!$path) {
- $path='/';
- }
- if($path[0]!=='/') {
- $path='/'.$path;
- }
- return $this->fakeRoot.$path;
- }
-
- /**
- * change the root to a fake toor
- * @param string fakeRoot
- * @return bool
- */
- public function chroot($fakeRoot) {
- if(!$fakeRoot=='') {
- if($fakeRoot[0]!=='/') {
- $fakeRoot='/'.$fakeRoot;
- }
- }
- $this->fakeRoot=$fakeRoot;
- }
-
- /**
- * get the fake root
- * @return string
- */
- public function getRoot() {
- return $this->fakeRoot;
- }
-
- /**
- * get the part of the path relative to the mountpoint of the storage it's stored in
- * @param string path
- * @return bool
- */
- public function getInternalPath($path) {
- if (!isset($this->internal_path_cache[$path])) {
- $this->internal_path_cache[$path] = OC_Filesystem::getInternalPath($this->getAbsolutePath($path));
- }
- return $this->internal_path_cache[$path];
- }
-
- /**
- * get path relative to the root of the view
- * @param string path
- * @return string
- */
- public function getRelativePath($path) {
- if($this->fakeRoot=='') {
- return $path;
- }
- if(strpos($path, $this->fakeRoot)!==0) {
- return null;
- }else{
- $path=substr($path, strlen($this->fakeRoot));
- if(strlen($path)===0) {
- return '/';
- }else{
- return $path;
- }
- }
- }
-
- /**
- * get the storage object for a path
- * @param string path
- * @return OC_Filestorage
- */
- public function getStorage($path) {
- if (!isset($this->storage_cache[$path])) {
- $this->storage_cache[$path] = OC_Filesystem::getStorage($this->getAbsolutePath($path));
- }
- return $this->storage_cache[$path];
- }
-
- /**
- * get the mountpoint of the storage object for a path
- ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account
- *
- * @param string path
- * @return string
- */
- public function getMountPoint($path) {
- return OC_Filesystem::getMountPoint($this->getAbsolutePath($path));
- }
-
- /**
- * return the path to a local version of the file
- * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed
- * @param string path
- * @return string
- */
- public function getLocalFile($path) {
- $parent=substr($path, 0, strrpos($path,'/'));
- if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) {
- return $storage->getLocalFile($this->getInternalPath($path));
- }
- }
- /**
- * @param string path
- * @return string
- */
- public function getLocalFolder($path) {
- $parent=substr($path, 0, strrpos($path,'/'));
- if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) {
- return $storage->getLocalFolder($this->getInternalPath($path));
- }
- }
-
- /**
- * the following functions operate with arguments and return values identical
- * to those of their PHP built-in equivalents. Mostly they are merely wrappers
- * for OC_Filestorage via basicOperation().
- */
- public function mkdir($path) {
- return $this->basicOperation('mkdir', $path, array('create', 'write'));
- }
- public function rmdir($path) {
- return $this->basicOperation('rmdir', $path, array('delete'));
- }
- public function opendir($path) {
- return $this->basicOperation('opendir', $path, array('read'));
- }
- public function readdir($handle) {
- $fsLocal= new OC_Filestorage_Local( array( 'datadir' => '/' ) );
- return $fsLocal->readdir( $handle );
- }
- public function is_dir($path) {
- if($path=='/') {
- return true;
- }
- return $this->basicOperation('is_dir', $path);
- }
- public function is_file($path) {
- if($path=='/') {
- return false;
- }
- return $this->basicOperation('is_file', $path);
- }
- public function stat($path) {
- return $this->basicOperation('stat', $path);
- }
- public function filetype($path) {
- return $this->basicOperation('filetype', $path);
- }
- public function filesize($path) {
- return $this->basicOperation('filesize', $path);
- }
- public function readfile($path) {
- @ob_end_clean();
- $handle=$this->fopen($path, 'rb');
- if ($handle) {
- $chunkSize = 8192;// 8 MB chunks
- while (!feof($handle)) {
- echo fread($handle, $chunkSize);
- flush();
- }
- $size=$this->filesize($path);
- return $size;
- }
- return false;
- }
- /**
- * @deprecated Replaced by isReadable() as part of CRUDS
- */
- public function is_readable($path) {
- return $this->basicOperation('isReadable',$path);
- }
- /**
- * @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS
- */
- public function is_writable($path) {
- return $this->basicOperation('isUpdatable',$path);
- }
- public function isCreatable($path) {
- return $this->basicOperation('isCreatable', $path);
- }
- public function isReadable($path) {
- return $this->basicOperation('isReadable', $path);
- }
- public function isUpdatable($path) {
- return $this->basicOperation('isUpdatable', $path);
- }
- public function isDeletable($path) {
- return $this->basicOperation('isDeletable', $path);
- }
- public function isSharable($path) {
- return $this->basicOperation('isSharable', $path);
- }
- public function file_exists($path) {
- if($path=='/') {
- return true;
- }
- return $this->basicOperation('file_exists', $path);
- }
- public function filectime($path) {
- return $this->basicOperation('filectime', $path);
- }
- public function filemtime($path) {
- return $this->basicOperation('filemtime', $path);
- }
- public function touch($path, $mtime=null) {
- if(!is_null($mtime) and !is_numeric($mtime)){
- $mtime = strtotime($mtime);
- }
- return $this->basicOperation('touch', $path, array('write'), $mtime);
- }
- public function file_get_contents($path) {
- return $this->basicOperation('file_get_contents', $path, array('read'));
- }
- public function file_put_contents($path, $data) {
- if(is_resource($data)) {//not having to deal with streams in file_put_contents makes life easier
- $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
- if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) {
- $path = $this->getRelativePath($absolutePath);
- $exists = $this->file_exists($path);
- $run = true;
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
- if(!$exists) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_create,
- array(
- OC_Filesystem::signal_param_path => $path,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- }
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_write,
- array(
- OC_Filesystem::signal_param_path => $path,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- }
- if(!$run) {
- return false;
- }
- $target=$this->fopen($path, 'w');
- if($target) {
- $count=OC_Helper::streamCopy($data, $target);
- fclose($target);
- fclose($data);
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
- if(!$exists) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_create,
- array( OC_Filesystem::signal_param_path => $path)
- );
- }
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_write,
- array( OC_Filesystem::signal_param_path => $path)
- );
- }
- OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
- return $count > 0;
- }else{
- return false;
- }
- }
- }else{
- return $this->basicOperation('file_put_contents', $path, array('create', 'write'), $data);
- }
- }
- public function unlink($path) {
- return $this->basicOperation('unlink', $path, array('delete'));
- }
- public function deleteAll( $directory, $empty = false ) {
- return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty );
- }
- public function rename($path1, $path2) {
- $postFix1=(substr($path1,-1,1)==='/')?'/':'';
- $postFix2=(substr($path2,-1,1)==='/')?'/':'';
- $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1));
- $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2));
- if(OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) {
- $path1 = $this->getRelativePath($absolutePath1);
- $path2 = $this->getRelativePath($absolutePath2);
-
- if($path1 == null or $path2 == null) {
- return false;
- }
- $run=true;
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename,
- array(
- OC_Filesystem::signal_param_oldpath => $path1,
- OC_Filesystem::signal_param_newpath => $path2,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- }
- if($run) {
- $mp1 = $this->getMountPoint($path1.$postFix1);
- $mp2 = $this->getMountPoint($path2.$postFix2);
- if($mp1 == $mp2) {
- if($storage = $this->getStorage($path1)) {
- $result = $storage->rename($this->getInternalPath($path1.$postFix1), $this->getInternalPath($path2.$postFix2));
- }
- } else {
- $source = $this->fopen($path1.$postFix1, 'r');
- $target = $this->fopen($path2.$postFix2, 'w');
- $count = OC_Helper::streamCopy($source, $target);
- $storage1 = $this->getStorage($path1);
- $storage1->unlink($this->getInternalPath($path1.$postFix1));
- $result = $count>0;
- }
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_rename,
- array(
- OC_Filesystem::signal_param_oldpath => $path1,
- OC_Filesystem::signal_param_newpath => $path2
- )
- );
- }
- return $result;
- }
- }
- }
- public function copy($path1, $path2) {
- $postFix1=(substr($path1,-1,1)==='/')?'/':'';
- $postFix2=(substr($path2,-1,1)==='/')?'/':'';
- $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1));
- $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2));
- if(OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) {
- $path1 = $this->getRelativePath($absolutePath1);
- $path2 = $this->getRelativePath($absolutePath2);
-
- if($path1 == null or $path2 == null) {
- return false;
- }
- $run=true;
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_copy,
- array(
- OC_Filesystem::signal_param_oldpath => $path1,
- OC_Filesystem::signal_param_newpath=>$path2,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- $exists=$this->file_exists($path2);
- if($run and !$exists) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_create,
- array(
- OC_Filesystem::signal_param_path => $path2,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- }
- if($run) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_write,
- array(
- OC_Filesystem::signal_param_path => $path2,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- }
- }
- if($run) {
- $mp1=$this->getMountPoint($path1.$postFix1);
- $mp2=$this->getMountPoint($path2.$postFix2);
- if($mp1 == $mp2) {
- if($storage = $this->getStorage($path1.$postFix1)) {
- $result=$storage->copy($this->getInternalPath($path1.$postFix1), $this->getInternalPath($path2.$postFix2));
- }
- } else {
- $source = $this->fopen($path1.$postFix1, 'r');
- $target = $this->fopen($path2.$postFix2, 'w');
- $result = OC_Helper::streamCopy($source, $target);
- }
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_copy,
- array(
- OC_Filesystem::signal_param_oldpath => $path1,
- OC_Filesystem::signal_param_newpath=>$path2
- )
- );
- if(!$exists) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_create,
- array(OC_Filesystem::signal_param_path => $path2)
- );
- }
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_write,
- array( OC_Filesystem::signal_param_path => $path2)
- );
- } else { // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions
- OC_FileCache_Update::update($path2, $this->fakeRoot);
- OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot);
- }
- return $result;
- }
- }
- }
- public function fopen($path, $mode) {
- $hooks=array();
- switch($mode) {
- case 'r':
- case 'rb':
- $hooks[]='read';
- break;
- case 'r+':
- case 'rb+':
- case 'w+':
- case 'wb+':
- case 'x+':
- case 'xb+':
- case 'a+':
- case 'ab+':
- $hooks[]='read';
- $hooks[]='write';
- break;
- case 'w':
- case 'wb':
- case 'x':
- case 'xb':
- case 'a':
- case 'ab':
- $hooks[]='write';
- break;
- default:
- OC_Log::write('core','invalid mode ('.$mode.') for '.$path,OC_Log::ERROR);
- }
-
- return $this->basicOperation('fopen', $path, $hooks, $mode);
- }
- public function toTmpFile($path) {
- if(OC_Filesystem::isValidPath($path)) {
- $source = $this->fopen($path, 'r');
- if($source) {
- $extension='';
- $extOffset=strpos($path, '.');
- if($extOffset !== false) {
- $extension=substr($path, strrpos($path,'.'));
- }
- $tmpFile = OC_Helper::tmpFile($extension);
- file_put_contents($tmpFile, $source);
- return $tmpFile;
- }
- }
- }
- public function fromTmpFile($tmpFile, $path) {
- if(OC_Filesystem::isValidPath($path)) {
- if(!$tmpFile) {
- debug_print_backtrace();
- }
- $source=fopen($tmpFile, 'r');
- if($source) {
- $this->file_put_contents($path, $source);
- unlink($tmpFile);
- return true;
- } else {
- }
- } else {
- return false;
- }
- }
-
- public function getMimeType($path) {
- return $this->basicOperation('getMimeType', $path);
- }
- public function hash($type, $path, $raw = false) {
- $postFix=(substr($path,-1,1)==='/')?'/':'';
- $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
- if (OC_FileProxy::runPreProxies('hash', $absolutePath) && OC_Filesystem::isValidPath($path)) {
- $path = $this->getRelativePath($absolutePath);
- if ($path == null) {
- return false;
- }
- if (OC_Filesystem::$loaded && $this->fakeRoot == OC_Filesystem::getRoot()) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_read,
- array( OC_Filesystem::signal_param_path => $path)
- );
- }
- if ($storage = $this->getStorage($path.$postFix)) {
- $result = $storage->hash($type, $this->getInternalPath($path.$postFix), $raw);
- $result = OC_FileProxy::runPostProxies('hash', $absolutePath, $result);
- return $result;
- }
- }
- return null;
- }
-
- public function free_space($path='/') {
- return $this->basicOperation('free_space', $path);
- }
-
- /**
- * @brief abstraction layer for basic filesystem functions: wrapper for OC_Filestorage
- * @param string $operation
- * @param string #path
- * @param array (optional) hooks
- * @param mixed (optional) $extraParam
- * @return mixed
- *
- * This method takes requests for basic filesystem functions (e.g. reading & writing
- * files), processes hooks and proxies, sanitises paths, and finally passes them on to
- * OC_Filestorage for delegation to a storage backend for execution
- */
- private function basicOperation($operation, $path, $hooks=array(), $extraParam=null) {
- $postFix=(substr($path,-1,1)==='/')?'/':'';
- $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
- if(OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) {
- $path = $this->getRelativePath($absolutePath);
- if($path == null) {
- return false;
- }
- $internalPath = $this->getInternalPath($path.$postFix);
- $run=$this->runHooks($hooks,$path);
- if($run and $storage = $this->getStorage($path.$postFix)) {
- if(!is_null($extraParam)) {
- $result = $storage->$operation($internalPath, $extraParam);
- } else {
- $result = $storage->$operation($internalPath);
- }
- $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
- if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) {
- if($operation!='fopen') {//no post hooks for fopen, the file stream is still open
- $this->runHooks($hooks,$path, true);
- }
- }
- return $result;
- }
- }
- return null;
- }
-
- private function runHooks($hooks,$path,$post=false) {
- $prefix=($post)?'post_':'';
- $run=true;
- if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) {
- foreach($hooks as $hook) {
- if($hook!='read') {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- $prefix.$hook,
- array(
- OC_Filesystem::signal_param_run => &$run,
- OC_Filesystem::signal_param_path => $path
- )
- );
- } elseif(!$post) {
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- $prefix.$hook,
- array(
- OC_Filesystem::signal_param_path => $path
- )
- );
- }
- }
- }
- return $run;
- }
-
- /**
- * check if a file or folder has been updated since $time
- * @param int $time
- * @return bool
- */
- public function hasUpdated($path, $time) {
- return $this->basicOperation('hasUpdated', $path, array(), $time);
- }
-}
diff --git a/lib/helper.php b/lib/helper.php
index 2da06c4cc45..aa453ad7504 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -566,7 +566,7 @@ class OC_Helper {
$newpath = $path . '/' . $filename;
$counter = 2;
- while (OC_Filesystem::file_exists($newpath)) {
+ while (\OC\Files\Filesystem::file_exists($newpath)) {
$newname = $name . ' (' . $counter . ')' . $ext;
$newpath = $path . '/' . $newname;
$counter++;
diff --git a/lib/image.php b/lib/image.php
index 016d20599b2..7c1a097cfd6 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -470,7 +470,7 @@ class OC_Image {
default:
// this is mostly file created from encrypted file
- $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($imagepath)));
+ $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagepath)));
$itype = IMAGETYPE_PNG;
OC_Log::write('core','OC_Image->loadFromFile, Default', OC_Log::DEBUG);
break;
diff --git a/lib/ocs.php b/lib/ocs.php
index 7350c3c8821..c6bcd2c06e1 100644
--- a/lib/ocs.php
+++ b/lib/ocs.php
@@ -589,11 +589,11 @@ class OC_OCS {
if(OC_User::userExists($user)) {
// calculate the disc space
$user_dir = '/'.$user.'/files';
- OC_Filesystem::init($user_dir);
- $rootInfo=OC_FileCache::get('');
- $sharedInfo=OC_FileCache::get('/Shared');
+ \OC\Files\Filesystem::init($user_dir);
+ $rootInfo=\OC\Files\Filesystem::getFileInfo('');
+ $sharedInfo=\OC\Files\Filesystem::getFileInfo('/Shared');
$used=$rootInfo['size']-$sharedInfo['size'];
- $free=OC_Filesystem::free_space();
+ $free=\OC\Files\Filesystem::free_space();
$total=$free+$used;
if($total==0) $total=1; // prevent division by zero
$relative=round(($used/$total)*10000)/100;
diff --git a/lib/public/files.php b/lib/public/files.php
index 90889c59ad8..2d6775e01f1 100644
--- a/lib/public/files.php
+++ b/lib/public/files.php
@@ -98,7 +98,7 @@ class Files {
/**
* @param string appid
* @param $app app
- * @return OC_FilesystemView
+ * @return \OC\Files\View
*/
public static function getStorage( $app ) {
return \OC_App::getStorage( $app );
diff --git a/lib/public/share.php b/lib/public/share.php
index da1c0616390..060f67c9e91 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -285,10 +285,10 @@ class Share {
// If the item is a folder, scan through the folder looking for equivalent item types
if ($itemType == 'folder') {
$parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true);
- if ($parentFolder && $files = \OC_Files::getDirectoryContent($itemSource)) {
+ if ($parentFolder && $files = \OC\Files\Filesystem::getDirectoryContent($itemSource)) {
for ($i = 0; $i < count($files); $i++) {
$name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource));
- if ($files[$i]['mimetype'] == 'httpd/unix-directory' && $children = \OC_Files::getDirectoryContent($name, '/')) {
+ if ($files[$i]['mimetype'] == 'httpd/unix-directory' && $children = \OC\Files\Filesystem::getDirectoryContent($name, '/')) {
// Continue scanning into child folders
array_push($files, $children);
} else {
@@ -768,9 +768,10 @@ class Share {
if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
$childItem['file_source'] = $child['source'];
} else {
- $childItem['file_source'] = \OC_FileCache::getId($child['file_path']);
+ $meta = \OC\Files\Filesystem::getFileInfo($child['file_path']);
+ $childItem['file_source'] = $meta['fileid'];
}
- $childItem['file_target'] = \OC_Filesystem::normalizePath($child['file_path']);
+ $childItem['file_target'] = \OC\Files\Filesystem::normalizePath($child['file_path']);
}
if (isset($item)) {
if ($childItem[$column] == $item) {
@@ -881,7 +882,8 @@ class Share {
if ($itemType == 'file' || $itemType == 'folder') {
$fileSource = $itemSource;
} else {
- $fileSource = \OC_FileCache::getId($filePath);
+ $meta = \OC\Files\Filesystem::getFileInfo($filePath);
+ $fileSource = $meta['fileid'];
}
if ($fileSource == -1) {
$message = 'Sharing '.$itemSource.' failed, because the file could not be found in the file cache';
@@ -1063,7 +1065,8 @@ class Share {
}
if ($item['uid_owner'] == $uidOwner) {
if ($itemType == 'file' || $itemType == 'folder') {
- if ($item['file_source'] == \OC_FileCache::getId($itemSource)) {
+ $meta = \OC\Files\Filesystem::getFileInfo($itemSource);
+ if ($item['file_source'] == $meta['fileid']) {
return $target;
}
} else if ($item['item_source'] == $itemSource) {
diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php
index 0d4b332b792..456e12b5ec2 100644
--- a/lib/search/provider/file.php
+++ b/lib/search/provider/file.php
@@ -2,7 +2,7 @@
class OC_Search_Provider_File extends OC_Search_Provider{
function search($query) {
- $files=OC_FileCache::search($query, true);
+ $files=\OC\Files\Filesystem::search($query, true);
$results=array();
$l=OC_L10N::get('lib');
foreach($files as $fileData) {
diff --git a/lib/util.php b/lib/util.php
index 4ca84ba75af..a2e0422c97f 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -34,7 +34,7 @@ class OC_Util {
$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
//first set up the local "root" storage
if(!self::$rootMounted) {
- OC_Filesystem::mount('OC_Filestorage_Local', array('datadir'=>$CONFIG_DATADIRECTORY),'/');
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$CONFIG_DATADIRECTORY), '/');
self::$rootMounted=true;
}
@@ -46,20 +46,23 @@ class OC_Util {
mkdir( $userdirectory, 0755, true );
}
//jail the user into his "home" directory
- OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user);
- OC_Filesystem::init($user_dir, $user);
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $user_root), $user);
+ \OC\Files\Filesystem::init($user_dir, $user);
+
$quotaProxy=new OC_FileProxy_Quota();
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($quotaProxy);
OC_FileProxy::register($fileOperationProxy);
// Load personal mount config
self::loadUserMountPoints($user);
+
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
}
+ return true;
}
public static function tearDownFS() {
- OC_Filesystem::tearDown();
+ \OC\Files\Filesystem::tearDown();
self::$fsSetup=false;
}
@@ -71,16 +74,9 @@ class OC_Util {
$mountConfig = include $user_root.'/mount.php';
if (isset($mountConfig['user'][$user])) {
foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
- OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
+ \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
}
}
-
- $mtime=filemtime($user_root.'/mount.php');
- $previousMTime=OC_Preferences::getValue($user,'files','mountconfigmtime',0);
- if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated
- OC_FileCache::triggerUpdate($user);
- OC_Preferences::setValue($user,'files','mountconfigmtime',$mtime);
- }
}
}
@@ -90,7 +86,7 @@ class OC_Util {
*/
public static function getVersion() {
// hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4.90.0. This is not visible to the user
- return array(4,91,00);
+ return array(4,91,01);
}
/**
diff --git a/settings/personal.php b/settings/personal.php
index 2031edd8df8..5a267ec2844 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -16,11 +16,11 @@ OC_Util::addStyle( '3rdparty', 'chosen' );
OC_App::setActiveNavigationEntry( 'personal' );
// calculate the disc space
-$rootInfo=OC_FileCache::get('');
-$sharedInfo=OC_FileCache::get('/Shared');
+$rootInfo=\OC\Files\Filesystem::getFileInfo('');
+$sharedInfo=\OC\Files\Filesystem::getFileInfo('/Shared');
$used=$rootInfo['size'];
if($used<0) $used=0;
-$free=OC_Filesystem::free_space();
+$free=\OC\Files\Filesystem::free_space();
$total=$free+$used;
if($total==0) $total=1; // prevent division by zero
$relative=round(($used/$total)*10000)/100;
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index 00be005d08d..5dcd3268804 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -38,8 +38,8 @@ class Test_Cache_File extends Test_Cache {
}
//set up temporary storage
- OC_Filesystem::clearMounts();
- OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/');
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Temporary',array(),'/');
OC_User::clearBackends();
OC_User::useBackend(new OC_User_Dummy());
@@ -51,7 +51,7 @@ class Test_Cache_File extends Test_Cache {
OC_User::setUserId('test');
//set up the users dir
- $rootView=new OC_FilesystemView('');
+ $rootView=new \OC\Files\View('');
$rootView->mkdir('/test');
$this->instance=new OC_Cache_File();
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
new file mode 100644
index 00000000000..839e06e93fc
--- /dev/null
+++ b/tests/lib/files/cache/cache.php
@@ -0,0 +1,142 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Cache extends \UnitTestCase {
+ /**
+ * @var \OC\Files\Storage\Temporary $storage;
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ public function testSimple() {
+ $file1 = 'foo';
+ $file2 = 'foo/bar';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+ $data2 = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+
+ $this->assertFalse($this->cache->inCache($file1));
+ $this->assertEqual($this->cache->get($file1), null);
+
+ $id1 = $this->cache->put($file1, $data1);
+ $this->assertTrue($this->cache->inCache($file1));
+ $cacheData1 = $this->cache->get($file1);
+ foreach ($data1 as $key => $value) {
+ $this->assertEqual($value, $cacheData1[$key]);
+ }
+ $this->assertEqual($cacheData1['mimepart'], 'foo');
+ $this->assertEqual($cacheData1['fileid'], $id1);
+ $this->assertEqual($id1, $this->cache->getId($file1));
+
+ $this->assertFalse($this->cache->inCache($file2));
+ $id2 = $this->cache->put($file2, $data2);
+ $this->assertTrue($this->cache->inCache($file2));
+ $cacheData2 = $this->cache->get($file2);
+ foreach ($data2 as $key => $value) {
+ $this->assertEqual($value, $cacheData2[$key]);
+ }
+ $this->assertEqual($cacheData1['fileid'], $cacheData2['parent']);
+ $this->assertEqual($cacheData2['fileid'], $id2);
+ $this->assertEqual($id2, $this->cache->getId($file2));
+ $this->assertEqual($id1, $this->cache->getParentId($file2));
+
+ $newSize = 1050;
+ $newId2 = $this->cache->put($file2, array('size' => $newSize));
+ $cacheData2 = $this->cache->get($file2);
+ $this->assertEqual($newId2, $id2);
+ $this->assertEqual($cacheData2['size'], $newSize);
+ $this->assertEqual($cacheData1, $this->cache->get($file1));
+
+ $this->cache->remove($file2);
+ $this->assertFalse($this->cache->inCache($file2));
+ $this->assertEqual($this->cache->get($file2), null);
+ $this->assertTrue($this->cache->inCache($file1));
+
+ $this->assertEqual($cacheData1, $this->cache->get($id1));
+ }
+
+ public function testPartial() {
+ $file1 = 'foo';
+
+ $this->cache->put($file1, array('size' => 10));
+ $this->assertEqual(array('size' => 10), $this->cache->get($file1));
+
+ $this->cache->put($file1, array('mtime' => 15));
+ $this->assertEqual(array('size' => 10, 'mtime' => 15), $this->cache->get($file1));
+
+ $this->cache->put($file1, array('size' => 12));
+ $this->assertEqual(array('size' => 12, 'mtime' => 15), $this->cache->get($file1));
+ }
+
+ public function testFolder() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+ $fileData = array();
+ $fileData['bar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['bar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $content = $this->cache->getFolderContents($file1);
+ $this->assertEqual(count($content), 2);
+ foreach ($content as $cachedData) {
+ $data = $fileData[$cachedData['name']];
+ foreach ($data as $name => $value) {
+ $this->assertEqual($value, $cachedData[$name]);
+ }
+ }
+ }
+
+ function testStatus() {
+ $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo'));
+ $this->cache->put('foo', array('size' => -1));
+ $this->assertEquals(\OC\Files\Cache\Cache::PARTIAL, $this->cache->getStatus('foo'));
+ $this->cache->put('foo', array('size' => -1, 'mtime' => 20, 'mimetype' => 'foo/file'));
+ $this->assertEquals(\OC\Files\Cache\Cache::SHALLOW, $this->cache->getStatus('foo'));
+ $this->cache->put('foo', array('size' => 10));
+ $this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo'));
+ }
+
+ function testSearch() {
+ $file1 = 'folder';
+ $file2 = 'folder/foobar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+ $fileData = array();
+ $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['foobar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $this->assertEquals(2, count($this->cache->search('%foo%')));
+ $this->assertEquals(1, count($this->cache->search('foo')));
+ $this->assertEquals(1, count($this->cache->search('%folder%')));
+ $this->assertEquals(1, count($this->cache->search('folder%')));
+ $this->assertEquals(3, count($this->cache->search('%')));
+ }
+
+ public function tearDown() {
+ $this->cache->clear();
+ }
+
+ public function setUp() {
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+ $this->cache = new \OC\Files\Cache\Cache($this->storage);
+ }
+}
diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php
new file mode 100644
index 00000000000..4d47929a3ee
--- /dev/null
+++ b/tests/lib/files/cache/permissions.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Permissions extends \PHPUnit_Framework_TestCase {
+ function testSimple() {
+ $ids = range(1, 10);
+ $user = uniqid();
+
+ $this->assertEquals(-1, \OC\Files\Cache\Permissions::get(1, $user));
+ \OC\Files\Cache\Permissions::set(1, $user, 1);
+ $this->assertEquals(1, \OC\Files\Cache\Permissions::get(1, $user));
+ $this->assertEquals(-1, \OC\Files\Cache\Permissions::get(2, $user));
+ $this->assertEquals(-1, \OC\Files\Cache\Permissions::get(1, $user . '2'));
+
+ \OC\Files\Cache\Permissions::set(1, $user, 2);
+ $this->assertEquals(2, \OC\Files\Cache\Permissions::get(1, $user));
+
+ \OC\Files\Cache\Permissions::set(2, $user, 1);
+ $this->assertEquals(1, \OC\Files\Cache\Permissions::get(2, $user));
+
+ \OC\Files\Cache\Permissions::remove(1, $user);
+ $this->assertEquals(-1, \OC\Files\Cache\Permissions::get(1, $user));
+ \OC\Files\Cache\Permissions::remove(1, $user . '2');
+ $this->assertEquals(1, \OC\Files\Cache\Permissions::get(2, $user));
+
+ $expected = array();
+ foreach ($ids as $id) {
+ \OC\Files\Cache\Permissions::set($id, $user, 10 + $id);
+ $expected[$id] = 10 + $id;
+ }
+ $this->assertEquals($expected, \OC\Files\Cache\Permissions::getMultiple($ids, $user));
+
+ \OC\Files\Cache\Permissions::removeMultiple(array(10, 9), $user);
+ unset($expected[9]);
+ unset($expected[10]);
+ $this->assertEquals($expected, \OC\Files\Cache\Permissions::getMultiple($ids, $user));
+
+ \OC\Files\Cache\Permissions::removeMultiple($ids, $user);
+ }
+}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
new file mode 100644
index 00000000000..34fefc784d4
--- /dev/null
+++ b/tests/lib/files/cache/scanner.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Scanner extends \UnitTestCase {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Scanner $scanner
+ */
+ private $scanner;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ function testFile() {
+ $data = "dummy file data\n";
+ $this->storage->file_put_contents('foo.txt', $data);
+ $this->scanner->scanFile('foo.txt');
+
+ $this->assertEqual($this->cache->inCache('foo.txt'), true);
+ $cachedData = $this->cache->get('foo.txt');
+ $this->assertEqual($cachedData['size'], strlen($data));
+ $this->assertEqual($cachedData['mimetype'], 'text/plain');
+ $this->assertNotEqual($cachedData['parent'], -1); //parent folders should be scanned automatically
+
+ $data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->file_put_contents('foo.png', $data);
+ $this->scanner->scanFile('foo.png');
+
+ $this->assertEqual($this->cache->inCache('foo.png'), true);
+ $cachedData = $this->cache->get('foo.png');
+ $this->assertEqual($cachedData['size'], strlen($data));
+ $this->assertEqual($cachedData['mimetype'], 'image/png');
+ }
+
+ private function fillTestFolders() {
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->mkdir('folder');
+ $this->storage->file_put_contents('foo.txt', $textData);
+ $this->storage->file_put_contents('foo.png', $imgData);
+ $this->storage->file_put_contents('folder/bar.txt', $textData);
+ }
+
+ function testFolder() {
+ $this->fillTestFolders();
+
+ $this->scanner->scan('');
+ $this->assertEqual($this->cache->inCache(''), true);
+ $this->assertEqual($this->cache->inCache('foo.txt'), true);
+ $this->assertEqual($this->cache->inCache('foo.png'), true);
+ $this->assertEqual($this->cache->inCache('folder'), true);
+ $this->assertEqual($this->cache->inCache('folder/bar.txt'), true);
+
+ $cachedDataText = $this->cache->get('foo.txt');
+ $cachedDataText2 = $this->cache->get('foo.txt');
+ $cachedDataImage = $this->cache->get('foo.png');
+ $cachedDataFolder = $this->cache->get('');
+ $cachedDataFolder2 = $this->cache->get('folder');
+
+ $this->assertEqual($cachedDataImage['parent'], $cachedDataText['parent']);
+ $this->assertEqual($cachedDataFolder['fileid'], $cachedDataImage['parent']);
+ $this->assertEqual($cachedDataFolder['size'], $cachedDataImage['size'] + $cachedDataText['size'] + $cachedDataText2['size']);
+ $this->assertEqual($cachedDataFolder2['size'], $cachedDataText2['size']);
+ }
+
+ function testShallow() {
+ $this->fillTestFolders();
+
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+ $this->assertEqual($this->cache->inCache(''), true);
+ $this->assertEqual($this->cache->inCache('foo.txt'), true);
+ $this->assertEqual($this->cache->inCache('foo.png'), true);
+ $this->assertEqual($this->cache->inCache('folder'), true);
+ $this->assertEqual($this->cache->inCache('folder/bar.txt'), false);
+
+ $cachedDataFolder = $this->cache->get('');
+ $cachedDataFolder2 = $this->cache->get('folder');
+
+ $this->assertEqual($cachedDataFolder['size'], -1);
+ $this->assertEqual($cachedDataFolder2['size'], -1);
+
+ $this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+
+ $cachedDataFolder2 = $this->cache->get('folder');
+
+ $this->assertNotEqual($cachedDataFolder2['size'], -1);
+ }
+
+ function setUp() {
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+ $this->scanner = new \OC\Files\Cache\Scanner($this->storage);
+ $this->cache = new \OC\Files\Cache\Cache($this->storage);
+ }
+
+ function tearDown() {
+ $ids = $this->cache->getAll();
+ \OC\Files\Cache\Permissions::removeMultiple($ids, \OC_User::getUser());
+ $this->cache->clear();
+ }
+}
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
new file mode 100644
index 00000000000..363426511bd
--- /dev/null
+++ b/tests/lib/files/filesystem.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Robin Appelman
+ * @copyright 2012 Robin Appelman icewind@owncloud.com
+ *
+ * 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/>.
+ *
+ */
+
+namespace Test\Files;
+
+class Filesystem extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var array tmpDirs
+ */
+ private $tmpDirs=array();
+
+ /**
+ * @return array
+ */
+ private function getStorageData() {
+ $dir = \OC_Helper::tmpFolder();
+ $this->tmpDirs[] = $dir;
+ return array('datadir' => $dir);
+ }
+
+ public function tearDown() {
+ foreach ($this->tmpDirs as $dir) {
+ \OC_Helper::rmdirr($dir);
+ }
+ }
+
+ public function setUp() {
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ public function testMount() {
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/');
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/');
+ $this->assertEquals('',$internalPath);
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEquals('some/folder',$internalPath);
+
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some');
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/'));
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEquals('folder',$internalPath);
+ }
+
+ public function testNormalize() {
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/'));
+ $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path'));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar'));
+ if (class_exists('Normalizer')) {
+ $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
+ }
+ }
+
+ public function testHooks() {
+ if(\OC\Files\Filesystem::getView()){
+ $user = \OC_User::getUser();
+ }else{
+ $user=uniqid();
+ \OC\Files\Filesystem::init('/'.$user.'/files');
+ }
+ \OC_Hook::clear('OC_Filesystem');
+ \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
+
+ \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
+
+ $rootView=new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
+ \OC\Files\Filesystem::mkdir('/bar');
+ \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
+
+ $tmpFile = \OC_Helper::tmpFile();
+ file_put_contents($tmpFile, 'foo');
+ $fh = fopen($tmpFile, 'r');
+ \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
+ }
+
+ public function dummyHook($arguments) {
+ $path = $arguments['path'];
+ $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
+ }
+}
diff --git a/tests/lib/filestorage/commontest.php b/tests/lib/files/storage/commontest.php
index 89e83589e5d..2e3808e2d92 100644
--- a/tests/lib/filestorage/commontest.php
+++ b/tests/lib/files/storage/commontest.php
@@ -20,7 +20,9 @@
*
*/
-class Test_Filestorage_CommonTest extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class CommonTest extends Storage {
/**
* @var string tmpDir
*/
@@ -30,12 +32,12 @@ class Test_Filestorage_CommonTest extends Test_FileStorage {
if(!file_exists($this->tmpDir)) {
mkdir($this->tmpDir);
}
- $this->instance=new OC_Filestorage_CommonTest(array('datadir'=>$this->tmpDir));
+ $this->instance=new \OC\Files\Storage\CommonTest(array('datadir'=>$this->tmpDir));
}
public function tearDown() {
- OC_Helper::rmdirr($this->tmpDir);
+ \OC_Helper::rmdirr($this->tmpDir);
}
}
-?> \ No newline at end of file
+?>
diff --git a/tests/lib/filestorage/local.php b/tests/lib/files/storage/local.php
index f68fb69b97f..6672368e676 100644
--- a/tests/lib/filestorage/local.php
+++ b/tests/lib/files/storage/local.php
@@ -20,19 +20,19 @@
*
*/
-class Test_Filestorage_Local extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class Local extends Storage {
/**
* @var string tmpDir
*/
private $tmpDir;
public function setUp() {
- $this->tmpDir=OC_Helper::tmpFolder();
- $this->instance=new OC_Filestorage_Local(array('datadir'=>$this->tmpDir));
+ $this->tmpDir=\OC_Helper::tmpFolder();
+ $this->instance=new \OC\Files\Storage\Local(array('datadir'=>$this->tmpDir));
}
public function tearDown() {
- OC_Helper::rmdirr($this->tmpDir);
+ \OC_Helper::rmdirr($this->tmpDir);
}
}
-
-?> \ No newline at end of file
diff --git a/tests/lib/filestorage.php b/tests/lib/files/storage/storage.php
index e82a6f54e3d..5d8a2241263 100644
--- a/tests/lib/filestorage.php
+++ b/tests/lib/files/storage/storage.php
@@ -20,9 +20,11 @@
*
*/
-abstract class Test_FileStorage extends UnitTestCase {
+namespace Test\Files\Storage;
+
+abstract class Storage extends \UnitTestCase {
/**
- * @var OC_Filestorage instance
+ * @var \OC\Files\Storage\Storage instance
*/
protected $instance;
@@ -36,7 +38,7 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertFalse($this->instance->is_file('/'), 'Root folder is a file');
$this->assertEqual('dir', $this->instance->filetype('/'));
- //without this, any further testing would be useless, not an acutal requirement for filestorage though
+ //without this, any further testing would be useless, not an actual requirement for filestorage though
$this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable');
}
@@ -83,7 +85,7 @@ abstract class Test_FileStorage extends UnitTestCase {
* test the various uses of file_get_contents and file_put_contents
*/
public function testGetPutContents() {
- $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$sourceText = file_get_contents($sourceFile);
//fill a file with string data
@@ -103,21 +105,21 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertEqual('httpd/unix-directory', $this->instance->getMimeType('/'));
$this->assertEqual(false, $this->instance->getMimeType('/non/existing/file'));
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r'));
$this->assertEqual('text/plain', $this->instance->getMimeType('/lorem.txt'));
- $pngFile = OC::$SERVERROOT . '/tests/data/logo-wide.png';
+ $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png';
$this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r'));
$this->assertEqual('image/png', $this->instance->getMimeType('/logo-wide.png'));
- $svgFile = OC::$SERVERROOT . '/tests/data/logo-wide.svg';
+ $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg';
$this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r'));
$this->assertEqual('image/svg+xml', $this->instance->getMimeType('/logo-wide.svg'));
}
public function testCopyAndMove() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/source.txt', file_get_contents($textFile));
$this->instance->copy('/source.txt', '/target.txt');
$this->assertTrue($this->instance->file_exists('/target.txt'));
@@ -130,7 +132,7 @@ abstract class Test_FileStorage extends UnitTestCase {
}
public function testLocal() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$localFile = $this->instance->getLocalFile('/lorem.txt');
$this->assertTrue(file_exists($localFile));
@@ -151,7 +153,7 @@ abstract class Test_FileStorage extends UnitTestCase {
}
public function testStat() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$this->assertTrue($this->instance->isReadable('/lorem.txt'));
@@ -165,7 +167,7 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertEqual(filesize($textFile), $this->instance->filesize('/lorem.txt'));
$stat = $this->instance->stat('/lorem.txt');
- //only size and mtime are requered in the result
+ //only size and mtime are required in the result
$this->assertEqual($stat['size'], $this->instance->filesize('/lorem.txt'));
$this->assertEqual($stat['mtime'], $mTime);
@@ -200,11 +202,11 @@ abstract class Test_FileStorage extends UnitTestCase {
}
public function testSearch() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r'));
- $pngFile = OC::$SERVERROOT . '/tests/data/logo-wide.png';
+ $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png';
$this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r'));
- $svgFile = OC::$SERVERROOT . '/tests/data/logo-wide.svg';
+ $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg';
$this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r'));
$result = $this->instance->search('logo');
$this->assertEqual(2, count($result));
@@ -213,7 +215,7 @@ abstract class Test_FileStorage extends UnitTestCase {
}
public function testFOpen() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$fh = @$this->instance->fopen('foo', 'r');
if ($fh) {
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
new file mode 100644
index 00000000000..980c5298fb4
--- /dev/null
+++ b/tests/lib/files/view.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file. */
+
+namespace Test\Files;
+
+class View extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Storage[] $storages;
+ */
+ private $storages = array();
+
+ public function setUp() {
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ public function tearDown() {
+ foreach ($this->storages as $storage) {
+ $cache = $storage->getCache();
+ $cache->clear();
+ }
+ }
+
+ public function testCacheAPI() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $storage3 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $storageSize = $textSize * 2 + $imageSize;
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $this->assertEquals($textSize, $cachedData['size']);
+ $this->assertEquals('text/plain', $cachedData['mimetype']);
+
+ $cachedData = $rootView->getFileInfo('/');
+ $this->assertEquals($storageSize * 3, $cachedData['size']);
+ $this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
+
+ $cachedData = $rootView->getFileInfo('/folder');
+ $this->assertEquals($storageSize + $textSize, $cachedData['size']);
+ $this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
+
+ $folderData = $rootView->getDirectoryContent('/');
+ /**
+ * expected entries:
+ * folder
+ * foo.png
+ * foo.txt
+ * substorage
+ */
+ $this->assertEquals(4, count($folderData));
+ $this->assertEquals('folder', $folderData[0]['name']);
+ $this->assertEquals('foo.png', $folderData[1]['name']);
+ $this->assertEquals('foo.txt', $folderData[2]['name']);
+ $this->assertEquals('substorage', $folderData[3]['name']);
+
+ $this->assertEquals($storageSize + $textSize, $folderData[0]['size']);
+ $this->assertEquals($imageSize, $folderData[1]['size']);
+ $this->assertEquals($textSize, $folderData[2]['size']);
+ $this->assertEquals($storageSize, $folderData[3]['size']);
+
+ $folderView = new \OC\Files\View('/folder');
+ $this->assertEquals($rootView->getFileInfo('/folder'), $folderView->getFileInfo('/'));
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $this->assertFalse($cachedData['encrypted']);
+ $id = $rootView->putFileInfo('/foo.txt', array('encrypted' => true));
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $this->assertTrue($cachedData['encrypted']);
+ $this->assertEquals($cachedData['fileid'], $id);
+ }
+
+ public function testAutoScan() {
+ $storage1 = $this->getTestStorage(false);
+ $storage2 = $this->getTestStorage(false);
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ $textSize = strlen("dummy file data\n");
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/');
+ $this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
+ $this->assertEquals(-1, $cachedData['size']);
+
+ $folderData = $rootView->getDirectoryContent('/substorage/folder');
+ $this->assertEquals('text/plain', $folderData[0]['mimetype']);
+ $this->assertEquals($textSize, $folderData[0]['size']);
+ }
+
+ function testSearch() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $storage3 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+
+ $rootView = new \OC\Files\View('');
+
+ $results = $rootView->search('foo');
+ $this->assertEquals(6, count($results));
+ $paths = array();
+ foreach ($results as $result) {
+ $this->assertEquals($result['path'], \OC\Files\Filesystem::normalizePath($result['path']));
+ $paths[] = $result['path'];
+ }
+ $this->assertContains('/foo.txt', $paths);
+ $this->assertContains('/foo.png', $paths);
+ $this->assertContains('/substorage/foo.txt', $paths);
+ $this->assertContains('/substorage/foo.png', $paths);
+ $this->assertContains('/folder/anotherstorage/foo.txt', $paths);
+ $this->assertContains('/folder/anotherstorage/foo.png', $paths);
+
+ $folderView = new \OC\Files\View('/folder');
+ $results = $folderView->search('bar');
+ $this->assertEquals(2, count($results));
+ $paths = array();
+ foreach ($results as $result) {
+ $paths[] = $result['path'];
+ }
+ $this->assertContains('/anotherstorage/folder/bar.txt', $paths);
+ $this->assertContains('/bar.txt', $paths);
+
+ $results = $folderView->search('foo');
+ $this->assertEquals(2, count($results));
+ $paths = array();
+ foreach ($results as $result) {
+ $paths[] = $result['path'];
+ }
+ $this->assertContains('/anotherstorage/foo.txt', $paths);
+ $this->assertContains('/anotherstorage/foo.png', $paths);
+ }
+
+ /**
+ * @param bool $scan
+ * @return \OC\Files\Storage\Storage
+ */
+ private function getTestStorage($scan = true) {
+ $storage = new \OC\Files\Storage\Temporary(array());
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', $textData);
+ $storage->file_put_contents('foo.png', $imgData);
+ $storage->file_put_contents('folder/bar.txt', $textData);
+
+ if ($scan) {
+ $scanner = $storage->getScanner();
+ $scanner->scan('');
+ }
+ $this->storages[] = $storage;
+ return $storage;
+ }
+}
diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
deleted file mode 100644
index e22b3f1c0d8..00000000000
--- a/tests/lib/filesystem.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Robin Appelman
- * @copyright 2012 Robin Appelman icewind@owncloud.com
- *
- * 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/>.
- *
- */
-
-class Test_Filesystem extends UnitTestCase {
- /**
- * @var array tmpDirs
- */
- private $tmpDirs=array();
-
- /**
- * @return array
- */
- private function getStorageData() {
- $dir = OC_Helper::tmpFolder();
- $this->tmpDirs[] = $dir;
- return array('datadir' => $dir);
- }
-
- public function tearDown() {
- foreach ($this->tmpDirs as $dir) {
- OC_Helper::rmdirr($dir);
- }
- }
-
- public function setUp() {
- OC_Filesystem::clearMounts();
- }
-
- public function testMount() {
- OC_Filesystem::mount('OC_Filestorage_Local', self::getStorageData(), '/');
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/'));
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/some/folder'));
- $this->assertEqual('', OC_Filesystem::getInternalPath('/'));
- $this->assertEqual('some/folder', OC_Filesystem::getInternalPath('/some/folder'));
-
- OC_Filesystem::mount('OC_Filestorage_Local', self::getStorageData(), '/some');
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/'));
- $this->assertEqual('/some/', OC_Filesystem::getMountPoint('/some/folder'));
- $this->assertEqual('/some/', OC_Filesystem::getMountPoint('/some/'));
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/some'));
- $this->assertEqual('folder', OC_Filesystem::getInternalPath('/some/folder'));
- }
-
- public function testNormalize() {
- $this->assertEqual('/path', OC_Filesystem::normalizePath('/path/'));
- $this->assertEqual('/path/', OC_Filesystem::normalizePath('/path/', false));
- $this->assertEqual('/path', OC_Filesystem::normalizePath('path'));
- $this->assertEqual('/path', OC_Filesystem::normalizePath('\path'));
- $this->assertEqual('/foo/bar', OC_Filesystem::normalizePath('/foo//bar/'));
- $this->assertEqual('/foo/bar', OC_Filesystem::normalizePath('/foo////bar'));
- if (class_exists('Normalizer')) {
- $this->assertEqual("/foo/bar\xC3\xBC", OC_Filesystem::normalizePath("/foo/baru\xCC\x88"));
- }
- }
-
- public function testHooks() {
- if(OC_Filesystem::getView()){
- $user = OC_User::getUser();
- }else{
- $user=uniqid();
- OC_Filesystem::init('/'.$user.'/files');
- }
- OC_Hook::clear('OC_Filesystem');
- OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
-
- OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
-
- $rootView=new OC_FilesystemView('');
- $rootView->mkdir('/'.$user);
- $rootView->mkdir('/'.$user.'/files');
-
- OC_Filesystem::file_put_contents('/foo', 'foo');
- OC_Filesystem::mkdir('/bar');
- OC_Filesystem::file_put_contents('/bar//foo', 'foo');
-
- $tmpFile = OC_Helper::tmpFile();
- file_put_contents($tmpFile, 'foo');
- $fh = fopen($tmpFile, 'r');
- OC_Filesystem::file_put_contents('/bar//foo', $fh);
- }
-
- public function dummyHook($arguments) {
- $path = $arguments['path'];
- $this->assertEqual($path, OC_Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
- }
-}