aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/files/ajax/autocomplete.php6
-rw-r--r--apps/files/ajax/delete.php12
-rw-r--r--apps/files/ajax/list.php2
-rw-r--r--apps/files/ajax/move.php18
-rw-r--r--apps/files/ajax/newfile.php21
-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/scan.php90
-rw-r--r--apps/files/ajax/upload.php7
-rw-r--r--apps/files/appinfo/app.php12
-rw-r--r--apps/files/appinfo/filesync.php4
-rw-r--r--apps/files/appinfo/version2
-rw-r--r--apps/files/download.php8
-rw-r--r--apps/files/index.php30
-rw-r--r--apps/files/js/files.js38
-rw-r--r--apps/files/settings.php2
-rw-r--r--apps/files/templates/part.list.php4
-rw-r--r--apps/files_encryption/lib/crypt.php10
-rw-r--r--apps/files_encryption/lib/cryptstream.php8
-rw-r--r--apps/files_encryption/lib/proxy.php29
-rw-r--r--apps/files_encryption/tests/proxy.php52
-rw-r--r--apps/files_external/ajax/addRootCertificate.php6
-rw-r--r--apps/files_external/appinfo/app.php16
-rw-r--r--apps/files_external/lib/amazons3.php33
-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.php34
-rw-r--r--apps/files_external/lib/smb.php21
-rw-r--r--apps/files_external/lib/streamwrapper.php55
-rw-r--r--apps/files_external/lib/swift.php113
-rw-r--r--apps/files_external/lib/webdav.php92
-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.php10
-rw-r--r--apps/files_sharing/lib/sharedstorage.php157
-rw-r--r--apps/files_sharing/public.php296
-rw-r--r--apps/files_versions/lib/hooks.php4
-rw-r--r--apps/files_versions/lib/versions.php16
48 files changed, 837 insertions, 553 deletions
diff --git a/apps/files/ajax/autocomplete.php b/apps/files/ajax/autocomplete.php
index b32ba7c3d5b..7613a1cb77a 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 6532b76df21..8f05eaaa1b8 100644
--- a/apps/files/ajax/delete.php
+++ b/apps/files/ajax/delete.php
@@ -12,17 +12,19 @@ $files = isset($_POST["file"]) ? stripslashes($_POST["file"]) : stripslashes($_P
$files = json_decode($files);
$filesWithError = '';
+
$success = true;
+
//Now delete
-foreach($files as $file) {
- if( !OC_Files::delete( $dir, $file )) {
+foreach ($files as $file) {
+ if (($dir === '' && $file === 'Shared') || !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
$filesWithError .= $file . "\n";
$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 cade7e872b3..878e4cb2159 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 5612716b7e4..d4eacd962a0 100644
--- a/apps/files/ajax/move.php
+++ b/apps/files/ajax/move.php
@@ -11,14 +11,14 @@ $dir = stripslashes($_GET["dir"]);
$file = stripslashes($_GET["file"]);
$target = stripslashes(rawurldecode($_GET["target"]));
-
-if(OC_Filesystem::file_exists($target . '/' . $file)) {
- OCP\JSON::error(array("data" => array( "message" => "Could not move $file - File with this name already exists" )));
- exit;
-}
-
-if(OC_Files::move($dir, $file, $target, $file)) {
- OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
-} else {
+if ($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 2bac9bb20ba..38714f34a63 100644
--- a/apps/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -63,13 +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) {
- $target = OC_Filesystem::normalizePath($target);
- $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);
}
@@ -77,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..470ee635a2a 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 (($dir != '' || $file != 'Shared')) {
+ $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
+ $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
+ 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/scan.php b/apps/files/ajax/scan.php
index 5cd9572d7f9..391b98608bd 100644
--- a/apps/files/ajax/scan.php
+++ b/apps/files/ajax/scan.php
@@ -1,43 +1,71 @@
<?php
+set_time_limit(0); //scanning can take ages
+session_write_close();
-set_time_limit(0);//scanning can take ages
+$force = (isset($_GET['force']) and ($_GET['force'] === 'true'));
+$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
-$force=isset($_GET['force']) and $_GET['force']=='true';
-$dir=isset($_GET['dir'])?$_GET['dir']:'';
-$checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true';
+$eventSource = new OC_EventSource();
+ScanListener::$eventSource = $eventSource;
+ScanListener::$view = \OC\Files\Filesystem::getView();
-if(!$checkOnly) {
- $eventSource=new OC_EventSource();
-}
+OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_folder', 'ScanListener', 'folder');
+OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_file', 'ScanListener', 'file');
-session_write_close();
+$absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);
-//create the file cache if necesary
-if($force or !OC_FileCache::inCache('')) {
- if(!$checkOnly) {
- OCP\DB::beginTransaction();
+$mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
+$mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
+$mountPoints = array_reverse($mountPoints); //start with the mount point of $dir
- if(OC_Cache::isFast()) {
- OC_Cache::clear('fileid/'); //make sure the old fileid's don't mess things up
+foreach ($mountPoints as $mountPoint) {
+ $storage = \OC\Files\Filesystem::getStorage($mountPoint);
+ if ($storage) {
+ ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
+ $scanner = $storage->getScanner();
+ if ($force) {
+ $scanner->scan('');
+ } else {
+ $scanner->backgroundScan();
}
-
- OC_FileCache::scan($dir, $eventSource);
- OC_FileCache::clean();
- OCP\DB::commit();
- $eventSource->send('success', true);
- } else {
- OCP\JSON::success(array('data'=>array('done'=>true)));
- exit;
}
-} else {
- if($checkOnly) {
- OCP\JSON::success(array('data'=>array('done'=>false)));
- exit;
+}
+
+$eventSource->send('done', ScanListener::$fileCount);
+$eventSource->close();
+
+class ScanListener {
+
+ static public $fileCount = 0;
+ static public $lastCount = 0;
+
+ /**
+ * @var \OC\Files\View $view
+ */
+ static public $view;
+
+ /**
+ * @var array $mountPoints map storage ids to mountpoints
+ */
+ static public $mountPoints = array();
+
+ /**
+ * @var \OC_EventSource event source to pass events to
+ */
+ static public $eventSource;
+
+ static function folder($params) {
+ $internalPath = $params['path'];
+ $mountPoint = self::$mountPoints[$params['storage']];
+ $path = self::$view->getRelativePath($mountPoint . $internalPath);
+ self::$eventSource->send('folder', $path);
}
- if(isset($eventSource)) {
- $eventSource->send('success', false);
- } else {
- exit;
+
+ static function file() {
+ self::$fileCount++;
+ if (self::$fileCount > self::$lastCount + 20) { //send a count update every 20 files
+ self::$lastCount = self::$fileCount;
+ self::$eventSource->send('count', self::$fileCount);
+ }
}
}
-$eventSource->close();
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index e7823bc4ffb..f40679f5756 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -40,7 +40,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();
}
@@ -53,12 +53,11 @@ if(strpos($dir, '..') === false) {
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
$target = OC_Filesystem::normalizePath($target);
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);
+ $meta = \OC\Files\Filesystem::getFileInfo($target);
$result[]=array( 'status' => 'success',
'mime'=>$meta['mimetype'],
'size'=>$meta['size'],
- 'id'=>$id,
+ 'id'=>$meta['fileid'],
'name'=>basename($target));
}
}
diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php
index 108f02930e2..643d8ed18a2 100644
--- a/apps/files/appinfo/app.php
+++ b/apps/files/appinfo/app.php
@@ -1,5 +1,5 @@
<?php
-$l=OC_L10N::get('files');
+$l = OC_L10N::get('files');
OCP\App::registerAdmin('files', 'admin');
@@ -10,3 +10,13 @@ OCP\App::addNavigationEntry( array( "id" => "files_index",
"name" => $l->t("Files") ));
OC_Search::registerProvider('OC_Search_Provider_File');
+
+if (OC_User::isLoggedIn()) {
+ // update OC4.5 filecache to OC5 filecache, can't do this in update.php since it needs to happen for each user individually
+ $cacheVersion = (int)OCP\Config::getUserValue(OC_User::getUser(), 'files', 'cache_version', 4);
+ if ($cacheVersion < 5) {
+ \OC_Log::write('files', 'updating filecache to 5.0 for user ' . OC_User::getUser(), \OC_Log::INFO);
+ \OC\Files\Cache\Upgrade::upgrade();
+ OCP\Config::setUserValue(OC_User::getUser(), 'files', 'cache_version', 5);
+ }
+}
diff --git a/apps/files/appinfo/filesync.php b/apps/files/appinfo/filesync.php
index cbed56a6de5..47884a4f15e 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/appinfo/version b/apps/files/appinfo/version
index 0664a8fd291..2bf1ca5f549 100644
--- a/apps/files/appinfo/version
+++ b/apps/files/appinfo/version
@@ -1 +1 @@
-1.1.6
+1.1.7
diff --git a/apps/files/download.php b/apps/files/download.php
index 6475afb56e0..dd356b27e9b 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));
OC_Util::obEnd();
-OC_Filesystem::readfile( $filename );
+\OC\Files\Filesystem::readfile( $filename );
diff --git a/apps/files/index.php b/apps/files/index.php
index c45fe60e4f7..173cef791d3 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -39,13 +39,23 @@ OCP\App::setActiveNavigationEntry( 'files_index' );
// Load the files
$dir = isset( $_GET['dir'] ) ? 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();
}
+function fileCmp($a, $b) {
+ if ($a['type'] == 'dir' and $b['type'] != 'dir') {
+ return -1;
+ } elseif ($a['type'] != 'dir' and $b['type'] == 'dir') {
+ return 1;
+ } else {
+ return strnatcasecmp($a['name'], $b['name']);
+ }
+}
+
$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']);
@@ -57,18 +67,18 @@ foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
$i['extension']='';
}
}
- if($i['directory']=='/') {
- $i['directory']='';
- }
+ $i['directory'] = $dir;
$files[] = $i;
}
+usort($files, "fileCmp");
+
// Make breadcrumb
$breadcrumb = array();
$pathtohere = '';
foreach( explode( '/', $dir ) as $i ) {
if( $i != '' ) {
- $pathtohere .= '/'.$i;
+ $pathtohere .= '/'.str_replace('+','%20', urlencode($i));
$breadcrumb[] = array( 'dir' => $pathtohere, 'name' => $i );
}
}
@@ -86,8 +96,8 @@ $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=max($freeSpace, 0);
+$freeSpace=\OC\Files\Filesystem::free_space($dir);
+$freeSpace=max($freeSpace,0);
$maxUploadFilesize = min($maxUploadFilesize, $freeSpace);
$permissions = OCP\PERMISSION_READ;
@@ -104,8 +114,8 @@ if (OC_Filesystem::isSharable($dir.'/')) {
$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/js/files.js b/apps/files/js/files.js
index 33c775fc8ec..a1f94ad1784 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -605,12 +605,8 @@ $(document).ready(function() {
});
});
- //check if we need to scan the filesystem
- $.get(OC.filePath('files','ajax','scan.php'),{checkonly:'true'}, function(response) {
- if(response.data.done){
- scanFiles();
- }
- }, "json");
+ //do a background scan if needed
+ scanFiles();
var lastWidth = 0;
var breadcrumbs = [];
@@ -679,27 +675,23 @@ $(document).ready(function() {
resizeBreadcrumbs(true);
});
-function scanFiles(force,dir){
+function scanFiles(force, dir){
if(!dir){
- dir='';
+ dir = '';
}
- force=!!force; //cast to bool
- scanFiles.scanning=true;
- $('#scanning-message').show();
- $('#fileList').remove();
- var scannerEventSource=new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force:force,dir:dir});
- scanFiles.cancel=scannerEventSource.close.bind(scannerEventSource);
- scannerEventSource.listen('scanning',function(data){
- $('#scan-count').text(t('files', '{count} files scanned', {count: data.count}));
- $('#scan-current').text(data.file+'/');
+ force = !!force; //cast to bool
+ scanFiles.scanning = true;
+ var scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force:force,dir:dir});
+ scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource);
+ scannerEventSource.listen('count',function(count){
+ console.log(count + 'files scanned')
+ });
+ scannerEventSource.listen('folder',function(path){
+ console.log('now scanning ' + path)
});
- scannerEventSource.listen('success',function(success){
+ scannerEventSource.listen('done',function(count){
scanFiles.scanning=false;
- if(success){
- window.location.reload();
- }else{
- alert(t('files', 'error while scanning'));
- }
+ console.log('done after ' + count + 'files');
});
}
scanFiles.scanning=false;
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/templates/part.list.php b/apps/files/templates/part.list.php
index 4c765adb7af..764fd8850ff 100644
--- a/apps/files/templates/part.list.php
+++ b/apps/files/templates/part.list.php
@@ -19,7 +19,7 @@
$name = str_replace('%2F', '/', $name);
$directory = str_replace('+', '%20', urlencode($file['directory']));
$directory = str_replace('%2F', '/', $directory); ?>
- <tr data-id="<?php echo $file['id']; ?>"
+ <tr data-id="<?php echo $file['fileid']; ?>"
data-file="<?php echo $name;?>"
data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>"
data-mime="<?php echo $file['mimetype']?>"
@@ -67,4 +67,4 @@
</span>
</td>
</tr>
- <?php endforeach; \ No newline at end of file
+ <?php endforeach;
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index 666fedb4e1b..e62c9b77273 100644
--- a/apps/files_encryption/lib/crypt.php
+++ b/apps/files_encryption/lib/crypt.php
@@ -45,8 +45,8 @@ class OC_Crypt {
}
public static function init($login, $password) {
- $view=new OC_FilesystemView('/');
- if ( ! $view->file_exists('/'.$login)) {
+ $view=new \OC\Files\View('/');
+ if(!$view->file_exists('/'.$login)) {
$view->mkdir('/'.$login);
}
@@ -81,7 +81,7 @@ class OC_Crypt {
}
}
- public static function createkey($username, $passcode) {
+ public static function createkey($username,$passcode) {
// generate a random key
$key=mt_rand(10000, 99999).mt_rand(10000, 99999).mt_rand(10000, 99999).mt_rand(10000, 99999);
@@ -91,7 +91,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;
}
@@ -99,7 +99,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 d516c0c21b2..8d5a9ff9990 100644
--- a/apps/files_encryption/lib/cryptstream.php
+++ b/apps/files_encryption/lib/cryptstream.php
@@ -38,8 +38,8 @@ class OC_CryptStream{
private static $rootView;
public function stream_open($path, $mode, $options, &$opened_path) {
- if ( ! self::$rootView) {
- self::$rootView=new OC_FilesystemView('');
+ if (!self::$rootView) {
+ self::$rootView=new \OC\Files\View('');
}
$path=str_replace('crypt://', '', $path);
if (dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) {
@@ -169,8 +169,8 @@ 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), '');
+ if($this->meta['mode']!='r' and $this->meta['mode']!='rb') {
+ \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 e8dbd95c29d..ffee394047c 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -61,7 +61,8 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @return bool
*/
private static function isEncrypted($path) {
- $metadata=OC_FileCache_Cached::get($path, '');
+ $rootView = new \OC\Files\View('');
+ $metadata=$rootView->getFileInfo($path);
return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
}
@@ -69,15 +70,17 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if (self::shouldEncrypt($path)) {
if ( ! is_resource($data)) {//stream put contents should have been converter to fopen
$size=strlen($data);
+ $rootView = new \OC\Files\View('');
$data=OC_Crypt::blockEncrypt($data);
- OC_FileCache::put($path, array('encrypted'=>true,'size'=>$size), '');
+ $rootView->putFileInfo($path, array('encrypted'=>true,'size'=>$size));
}
}
}
public function postFile_get_contents($path, $data) {
- if (self::isEncrypted($path)) {
- $cached=OC_FileCache_Cached::get($path, '');
+ if(self::isEncrypted($path)) {
+ $rootView = new \OC\Files\View('');
+ $cached=$rootView->getFileInfo($path, '');
$data=OC_Crypt::blockDecrypt($data, '', $cached['size']);
}
return $data;
@@ -91,14 +94,14 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if (self::isEncrypted($path)) {
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) {
+ }elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') {
+ 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);
+ OCP\Util::writeLog('files_encryption','Decrypting '.$path.' before writing', OCP\Util::DEBUG);
$tmp=fopen('php://temp');
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']);
@@ -114,16 +117,18 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
}
public function postStat($path, $data) {
- if (self::isEncrypted($path)) {
- $cached=OC_FileCache_Cached::get($path, '');
+ if(self::isEncrypted($path)) {
+ $rootView = new \OC\Files\View('');
+ $cached=$rootView->getFileInfo($path);
$data['size']=$cached['size'];
}
return $data;
}
public function postFileSize($path, $size) {
- if (self::isEncrypted($path)) {
- $cached=OC_FileCache_Cached::get($path, '');
+ if(self::isEncrypted($path)) {
+ $rootView = new \OC\Files\View('');
+ $cached=$rootView->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 5aa617e7472..09b2a67943c 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -13,8 +13,8 @@ class Test_CryptProxy extends UnitTestCase {
public function setUp() {
$user=OC_User::getUser();
- $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption', 'true');
- OCP\Config::setAppValue('files_encryption', 'enable_encryption', 'true');
+ $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true');
+ OCP\Config::setAppValue('files_encryption','enable_encryption','true');
$this->oldKey=isset($_SESSION['enckey'])?$_SESSION['enckey']:null;
@@ -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,16 +51,16 @@ 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');
- $this->assertNotEqual($original, $stored);
+ $fromFile=\OC\Files\Filesystem::file_get_contents('/file');
+ $this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original), strlen($fromFile));
- $this->assertEqual($original, $fromFile);
+ $this->assertEqual($original,$fromFile);
}
@@ -68,50 +68,50 @@ 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);
+ $rootView->file_put_contents($userDir.'/file',$original);
OC_FileProxy::$enabled=false;
$stored=$rootView->file_get_contents($userDir.'/file');
OC_FileProxy::$enabled=true;
- $this->assertNotEqual($original, $stored);
+ $this->assertNotEqual($original,$stored);
$fromFile=$rootView->file_get_contents($userDir.'/file');
- $this->assertEqual($original, $fromFile);
+ $this->assertEqual($original,$fromFile);
$fromFile=$view->file_get_contents('files/file');
- $this->assertEqual($original, $fromFile);
+ $this->assertEqual($original,$fromFile);
}
public function testBinary() {
$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');
- $this->assertNotEqual($original, $stored);
+ $fromFile=\OC\Files\Filesystem::file_get_contents('/file');
+ $this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original), strlen($fromFile));
- $this->assertEqual($original, $fromFile);
+ $this->assertEqual($original,$fromFile);
$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');
- $this->assertNotEqual($original, $stored);
+ $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 be60b415e1b..2f67e801b2c 100644
--- a/apps/files_external/ajax/addRootCertificate.php
+++ b/apps/files_external/ajax/addRootCertificate.php
@@ -12,8 +12,10 @@ $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');
-if ( ! $view->file_exists('')) $view->mkdir('');
+$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 235ade06db6..a209f0d0507 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,15 +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 {
- $object = $this->getObject($path);
- if ($object) {
- $stat['size'] = $object['Size'];
- $stat['atime'] = time();
- $stat['mtime'] = strtotime($object['LastModified']);
- $stat['ctime'] = $stat['mtime'];
- }
+ } else if ($object = $this->getObject($path)) {
+ $stat['size'] = $object['Size'];
+ $stat['atime'] = time();
+ $stat['mtime'] = strtotime($object['LastModified']);
}
if (isset($stat)) {
return $stat;
@@ -166,7 +169,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()) {
@@ -190,8 +193,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 c0864dc50d2..959086e43dc 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -39,19 +39,19 @@ class OC_Mount_Config {
*/
public static function getBackends() {
- $backends['OC_Filestorage_Local']=array(
+ $backends['\OC\Files\Storage\Local']=array(
'backend' => 'Local',
'configuration' => array(
'datadir' => 'Location'));
- $backends['OC_Filestorage_AmazonS3']=array(
+ $backends['\OC\Files\Storage\AmazonS3']=array(
'backend' => 'Amazon S3',
'configuration' => array(
'key' => 'Key',
'secret' => '*Secret',
'bucket' => 'Bucket'));
- $backends['OC_Filestorage_Dropbox']=array(
+ $backends['\OC\Files\Storage\Dropbox']=array(
'backend' => 'Dropbox',
'configuration' => array(
'configured' => '#configured',
@@ -61,7 +61,7 @@ class OC_Mount_Config {
'token_secret' => '#token_secret'),
'custom' => 'dropbox');
- if(OC_Mount_Config::checkphpftp()) $backends['OC_Filestorage_FTP']=array(
+ if(OC_Mount_Config::checkphpftp()) $backends['\OC\Files\Storage\FTP']=array(
'backend' => 'FTP',
'configuration' => array(
'host' => 'URL',
@@ -70,7 +70,7 @@ class OC_Mount_Config {
'root' => '&Root',
'secure' => '!Secure ftps://'));
- $backends['OC_Filestorage_Google']=array(
+ $backends['\OC\Files\Storage\Google']=array(
'backend' => 'Google Drive',
'configuration' => array(
'configured' => '#configured',
@@ -78,7 +78,7 @@ class OC_Mount_Config {
'token_secret' => '#token secret'),
'custom' => 'google');
- $backends['OC_Filestorage_SWIFT']=array(
+ $backends['\OC\Files\Storage\SWIFT']=array(
'backend' => 'OpenStack Swift',
'configuration' => array(
'host' => 'URL',
@@ -87,7 +87,7 @@ class OC_Mount_Config {
'root' => '&Root',
'secure' => '!Secure ftps://'));
- if(OC_Mount_Config::checksmbclient()) $backends['OC_Filestorage_SMB']=array(
+ if(OC_Mount_Config::checksmbclient()) $backends['\OC\Files\Storage\SMB']=array(
'backend' => 'SMB / CIFS',
'configuration' => array(
'host' => 'URL',
@@ -96,7 +96,7 @@ class OC_Mount_Config {
'share' => 'Share',
'root' => '&Root'));
- $backends['OC_Filestorage_DAV']=array(
+ $backends['\OC\Files\Storage\DAV']=array(
'backend' => 'ownCloud / WebDAV',
'configuration' => array(
'host' => 'URL',
@@ -213,14 +213,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 33ca14cab15..9223b4ca87b 100755
--- a/apps/files_external/lib/dropbox.php
+++ b/apps/files_external/lib/dropbox.php
@@ -20,12 +20,15 @@
* 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();
@@ -37,13 +40,14 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
&& 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');
}
}
@@ -55,8 +59,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'])) {
@@ -76,21 +80,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;
}
}
@@ -106,7 +114,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;
@@ -118,7 +126,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;
@@ -163,8 +170,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;
}
}
@@ -175,8 +182,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;
}
}
@@ -187,8 +194,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;
}
}
@@ -198,13 +205,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':
@@ -224,8 +231,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);
@@ -242,8 +249,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);
}
}
}
@@ -264,8 +271,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 e796ae446bf..973b33fbfd7 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;
@@ -38,9 +40,13 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
}
}
+ 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) {
@@ -51,7 +57,8 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
$url.='://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path;
return $url;
}
- public function fopen($path, $mode) {
+ public function fopen($path,$mode) {
+ $this->init();
switch($mode) {
case 'r':
case 'rb':
@@ -61,7 +68,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
case 'ab':
//these are supported by the wrapper
$context = stream_context_create(array('ftp' => array('overwrite' => true)));
- return fopen($this->constructUrl($path), $mode, false, $context);
+ return fopen($this->constructUrl($path),$mode, false,$context);
case 'r+':
case 'w+':
case 'wb+':
@@ -82,11 +89,13 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
$this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
- return fopen('close://'.$tmpFile, $mode);
+ 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 c836a5a07c0..bbb315c4910 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();
@@ -38,12 +41,13 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
) {
$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');
}
}
@@ -68,7 +72,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,
+ $request = \OAuthRequest::from_consumer_and_token($this->consumer,
$this->oauth_token,
$httpMethod,
$uri,
@@ -110,7 +114,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);
}
@@ -139,7 +143,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;
}
@@ -194,6 +198,9 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
}
+ public function getId(){
+ return $this->id;
+ }
public function mkdir($path) {
$collection = dirname($path);
@@ -266,7 +273,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);
}
@@ -287,7 +294,6 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
//$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)) {
@@ -443,8 +449,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);
@@ -482,7 +488,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"?>';
@@ -590,4 +596,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 071a9cd5f95..96778b0b2e1 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;
@@ -30,14 +32,13 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
if ( ! $this->share || $this->share[0]!='/') {
$this->share='/'.$this->share;
}
- if (substr($this->share, -1, 1)=='/') {
- $this->share=substr($this->share, 0, -1);
+ 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) {
@@ -65,11 +66,13 @@ 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) {
- if ( ! $path and $this->root=='/') {
+ 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 a386e333995..7c3ddcf8a2c 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -6,16 +6,33 @@
* 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) {
- if ($this->file_exists($path)) {
+ $this->init();
+ if($this->file_exists($path)) {
$succes = rmdir($this->constructUrl($path));
clearstatcache();
return $succes;
@@ -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,46 +60,54 @@ 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) {
- return fopen($this->constructUrl($path), $mode);
+ public function fopen($path,$mode) {
+ $this->init();
+ return fopen($this->constructUrl($path),$mode);
}
public function free_space($path) {
return 0;
}
- public function touch($path, $mtime = null) {
- if (is_null($mtime)) {
- $fh = $this->fopen($path, 'a');
- fwrite($fh, '');
+ public function touch($path,$mtime=null) {
+ $this->init();
+ if(is_null($mtime)) {
+ $fh = $this->fopen($path,'a');
+ fwrite($fh,'');
fclose($fh);
} else {
return false;//not supported
}
}
- public function getFile($path, $target) {
- return copy($this->constructUrl($path), $target);
+ public function getFile($path,$target) {
+ $this->init();
+ return copy($this->constructUrl($path),$target);
}
- public function uploadFile($path, $target) {
- return copy($path, $this->constructUrl($target));
+ public function uploadFile($path,$target) {
+ $this->init();
+ return copy($path,$this->constructUrl($target));
}
- public function rename($path1, $path2) {
- return rename($this->constructUrl($path1), $this->constructUrl($path2));
+ 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 a071dfdbb03..bd1f4c572a6 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,18 +39,18 @@ 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) {
- $path=trim(trim($this->root, '/')."/".$path, '/.');
+ $path=trim(trim($this->root, '/') . "/".$path, '/.');
return str_replace('/', '\\', $path);
}
/**
* 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);
@@ -201,16 +205,15 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
foreach ($containers as &$sub) {
$sub=trim($sub);
}
- if (array_search($name, $containers)!==false) {
+ if(array_search($name, $containers) !== false) {
unlink($tmpFile);
return false;
} else {
$fh=fopen($tmpFile, 'a');
- fwrite($fh, $name."\n");
+ fwrite($fh,$name . "\n");
}
- } catch(Exception $e) {
- $containers=array();
- file_put_contents($tmpFile, $name."\n");
+ } catch(\Exception $e) {
+ file_put_contents($tmpFile, $name . "\n");
}
$obj->load_from_filename($tmpFile);
@@ -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,8 +258,8 @@ 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 {
@@ -283,10 +286,19 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
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('/');
@@ -295,8 +307,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 {
@@ -306,7 +323,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function rmdir($path) {
- if ( ! $this->containerExists($path)) {
+ $this->init();
+ if (!$this->containerExists($path)) {
return false;
} else {
$this->emptyContainer($path);
@@ -343,6 +361,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);
@@ -352,11 +371,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 {
@@ -373,6 +393,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function file_exists($path) {
+ $this->init();
if ($this->is_dir($path)) {
return true;
} else {
@@ -381,6 +402,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;
@@ -389,6 +411,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));
@@ -402,6 +425,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function unlink($path) {
+ $this->init();
if ($this->containerExists($path)) {
return $this->rmdir($path);
}
@@ -415,6 +439,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function fopen($path, $mode) {
+ $this->init();
switch($mode) {
case 'r':
case 'rb':
@@ -458,6 +483,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;
@@ -472,6 +498,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));
@@ -484,6 +511,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));
@@ -495,6 +523,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
public function stat($path) {
+ $this->init();
$container=$this->getContainer($path);
if ( ! is_null($container)) {
return array(
@@ -523,17 +552,19 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
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);
@@ -544,7 +575,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 68aca228bc5..19b6ec2fd2c 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;
@@ -43,6 +46,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(),
@@ -50,7 +60,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);
$caview = \OCP\Files::getStorage('files_external');
if ($caview) {
@@ -63,6 +73,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) {
@@ -73,40 +87,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;
@@ -122,20 +140,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) {
+ public function fopen($path,$mode) {
+ $this->init();
$path=$this->cleanPath($path);
switch($mode) {
case 'r':
@@ -172,9 +193,9 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
} else {
$ext='';
}
- $tmpFile=OCP\Files::tmpFile($ext);
- OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this, 'writeBack');
- if ($this->file_exists($path)) {
+ $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;
@@ -190,6 +211,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'));
@@ -198,12 +220,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();
}
@@ -211,12 +234,14 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->client->proppatch($path, array('{DAV:}lastmodified' => $mtime));
}
- public function getFile($path, $target) {
- $source=$this->fopen($path, 'r');
- file_put_contents($target, $source);
+ public function getFile($path,$target) {
+ $this->init();
+ $source=$this->fopen($path,'r');
+ file_put_contents($target,$source);
}
- public function uploadFile($path, $target) {
+ public function uploadFile($path,$target) {
+ $this->init();
$source=fopen($path, 'r');
$curl = curl_init();
@@ -230,49 +255,46 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
curl_close ($curl);
}
- public function rename($path1, $path2) {
+ 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) {
+ 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'));
@@ -285,7 +307,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
} else {
return false;
}
- } catch(Exception $e) {
+ } catch(\Exception $e) {
return false;
}
}
@@ -298,12 +320,12 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
}
- private function simpleResponse($method, $path, $body, $expected) {
+ private function simpleResponse($method,$path,$body,$expected) {
$path=$this->cleanPath($path);
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 4215b28787e..268d1880232 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 39f96fe8e55..6b3a942b5ba 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'],
+ $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 304cb3ca38c..e4e598b06b0 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 d0404b5f34c..9998a479bf8 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 379bf992ff5..f344163a8b9 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 2d6268ef269..be3ea5a8308 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 8b25db50996..5c782840246 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 dd938a0c93a..1702898045e 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 e998626f4a4..1d22b32b503 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -9,10 +9,12 @@ if (version_compare($installedVersion, '0.3', '<')) {
OC_User::useBackend(new OC_User_Database());
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
+ $rootView = new \OC\Files\View('');
while ($row = $result->fetchRow()) {
- $itemSource = OC_FileCache::getId($row['source'], '');
+ $meta = $rootView->getFileInfo($$row['source']);
+ $itemSource = $meta['fileid'];
if ($itemSource != -1) {
- $file = OC_FileCache::get($row['source'], '');
+ $file = $meta;
if ($file['mimetype'] == 'httpd/unix-directory') {
$itemType = 'folder';
} else {
@@ -68,6 +70,6 @@ if (version_compare($installedVersion, '0.3.3', '<')) {
OC_App::loadApps(array('authentication'));
$users = OC_User::getUsers();
foreach ($users as $user) {
- OC_FileCache::delete('Shared', '/'.$user.'/files/');
+// 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 50db9166fe7..5abdbf29f03 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;
}
@@ -233,33 +223,12 @@ 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->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_sharing/public.php b/apps/files_sharing/public.php
index fef0ed8a8c2..eb4af58cdca 100644
--- a/apps/files_sharing/public.php
+++ b/apps/files_sharing/public.php
@@ -9,9 +9,10 @@ if (isset($_GET['token'])) {
unset($_GET['file']);
$qry = \OC_DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? LIMIT 1');
$filepath = $qry->execute(array($_GET['token']))->fetchOne();
- if(isset($filepath)) {
- $info = OC_FileCache_Cached::get($filepath, '');
- if(strtolower($info['mimetype']) == 'httpd/unix-directory') {
+ if (isset($filepath)) {
+ $rootView = new \OC\Files\View('');
+ $info = $rootView->getFileInfo($filepath, '');
+ if (strtolower($info['mimetype']) == 'httpd/unix-directory') {
$_GET['dir'] = $filepath;
} else {
$_GET['file'] = $filepath;
@@ -23,25 +24,28 @@ if (isset($_GET['token'])) {
function getID($path) {
// use the share table from the db to find the item source if the file was reshared because shared files
//are not stored in the file cache.
- if (substr(OC_Filesystem::getMountPoint($path), -7, 6) == "Shared") {
+ if (substr(\OC\Files\Filesystem::getMountPoint($path), -7, 6) == "Shared") {
$path_parts = explode('/', $path, 5);
$user = $path_parts[1];
- $intPath = '/'.$path_parts[4];
+ $intPath = '/' . $path_parts[4];
$query = \OC_DB::prepare('SELECT `item_source` FROM `*PREFIX*share` WHERE `uid_owner` = ? AND `file_target` = ? ');
$result = $query->execute(array($user, $intPath));
$row = $result->fetchRow();
$fileSource = $row['item_source'];
} else {
- $fileSource = OC_Filecache::getId($path, '');
+ $rootView = new \OC\Files\View('');
+ $meta = $rootView->getFileInfo($path);
+ $fileSource = $meta['fileid'];
}
return $fileSource;
}
+
// Enf of backward compatibility
/**
* lookup file path and owner by fetching it from the fscache
- * needed becaus OC_FileCache::getPath($id, $user) already requires the user
+ * needed because OC_FileCache::getPath($id, $user) already requires the user
* @param int $id
* @return array
*/
@@ -61,60 +65,62 @@ if (isset($_GET['t'])) {
$type = $linkItem['item_type'];
$fileSource = $linkItem['file_source'];
$shareOwner = $linkItem['uid_owner'];
-
- if (OCP\User::userExists($shareOwner) && $fileSource != -1 ) {
-
+
+ if (OCP\User::userExists($shareOwner) && $fileSource != -1) {
+
$pathAndUser = getPathAndUser($linkItem['file_source']);
$fileOwner = $pathAndUser['user'];
-
+
//if this is a reshare check the file owner also exists
- if ($shareOwner != $fileOwner && ! OCP\User::userExists($fileOwner)) {
- OCP\Util::writeLog('share', 'original file owner '.$fileOwner.' does not exist for share '.$linkItem['id'], \OCP\Util::ERROR);
- header('HTTP/1.0 404 Not Found');
- $tmpl = new OCP\Template('', '404', 'guest');
- $tmpl->printPage();
- exit();
+ if ($shareOwner != $fileOwner && !OCP\User::userExists($fileOwner)) {
+ OCP\Util::writeLog('share', 'original file owner ' . $fileOwner . ' does not exist for share ' . $linkItem['id'], \OCP\Util::ERROR);
+ header('HTTP/1.0 404 Not Found');
+ $tmpl = new OCP\Template('', '404', 'guest');
+ $tmpl->printPage();
+ exit();
}
-
+
//mount filesystem of file owner
OC_Util::setupFS($fileOwner);
}
}
-} else if (isset($_GET['file']) || isset($_GET['dir'])) {
- OCP\Util::writeLog('share', 'Missing token, trying fallback file/dir links', \OCP\Util::DEBUG);
- if (isset($_GET['dir'])) {
- $type = 'folder';
- $path = $_GET['dir'];
- if(strlen($path)>1 and substr($path, -1, 1)==='/') {
- $path=substr($path, 0, -1);
- }
- $baseDir = $path;
- $dir = $baseDir;
- } else {
- $type = 'file';
- $path = $_GET['file'];
- if(strlen($path)>1 and substr($path, -1, 1)==='/') {
- $path=substr($path, 0, -1);
+} else {
+ if (isset($_GET['file']) || isset($_GET['dir'])) {
+ OCP\Util::writeLog('share', 'Missing token, trying fallback file/dir links', \OCP\Util::DEBUG);
+ if (isset($_GET['dir'])) {
+ $type = 'folder';
+ $path = $_GET['dir'];
+ if (strlen($path) > 1 and substr($path, -1, 1) === '/') {
+ $path = substr($path, 0, -1);
+ }
+ $baseDir = $path;
+ $dir = $baseDir;
+ } else {
+ $type = 'file';
+ $path = $_GET['file'];
+ if (strlen($path) > 1 and substr($path, -1, 1) === '/') {
+ $path = substr($path, 0, -1);
+ }
}
- }
- $shareOwner = substr($path, 1, strpos($path, '/', 1) - 1);
-
- if (OCP\User::userExists($shareOwner)) {
- OC_Util::setupFS($shareOwner);
- $fileSource = getId($path);
- if ($fileSource != -1 ) {
- $linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $shareOwner);
- $pathAndUser['path'] = $path;
- $path_parts = explode('/', $path, 5);
- $pathAndUser['user'] = $path_parts[1];
- $fileOwner = $path_parts[1];
+ $shareOwner = substr($path, 1, strpos($path, '/', 1) - 1);
+
+ if (OCP\User::userExists($shareOwner)) {
+ OC_Util::setupFS($shareOwner);
+ $fileSource = getId($path);
+ if ($fileSource != -1) {
+ $linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $shareOwner);
+ $pathAndUser['path'] = $path;
+ $path_parts = explode('/', $path, 5);
+ $pathAndUser['user'] = $path_parts[1];
+ $fileOwner = $path_parts[1];
+ }
}
}
}
if ($linkItem) {
if (!isset($linkItem['item_type'])) {
- OCP\Util::writeLog('share', 'No item type set for share id: '.$linkItem['id'], \OCP\Util::ERROR);
+ OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
@@ -122,11 +128,13 @@ if ($linkItem) {
}
if (isset($linkItem['share_with'])) {
// Authenticate share_with
- $url = OCP\Util::linkToPublic('files').'&t='.$token;
+ $url = OCP\Util::linkToPublic('files') . '&t=' . $token;
if (isset($_GET['file'])) {
- $url .= '&file='.urlencode($_GET['file']);
- } else if (isset($_GET['dir'])) {
- $url .= '&dir='.urlencode($_GET['dir']);
+ $url .= '&file=' . urlencode($_GET['file']);
+ } else {
+ if (isset($_GET['dir'])) {
+ $url .= '&dir=' . urlencode($_GET['dir']);
+ }
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
@@ -134,7 +142,7 @@ if ($linkItem) {
// Check Password
$forcePortable = (CRYPT_BLOWFISH != 1);
$hasher = new PasswordHash(8, $forcePortable);
- if (!($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $linkItem['share_with']))) {
+ if (!($hasher->CheckPassword($password . OC_Config::getValue('passwordsalt', ''), $linkItem['share_with']))) {
$tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
$tmpl->assign('URL', $url);
$tmpl->assign('error', true);
@@ -145,28 +153,30 @@ if ($linkItem) {
$_SESSION['public_link_authenticated'] = $linkItem['id'];
}
} else {
- OCP\Util::writeLog('share', 'Unknown share type '.$linkItem['share_type'].' for share id '.$linkItem['id'], \OCP\Util::ERROR);
+ OCP\Util::writeLog('share', 'Unknown share type ' . $linkItem['share_type'] . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
exit();
}
- // Check if item id is set in session
- } else if (!isset($_SESSION['public_link_authenticated']) || $_SESSION['public_link_authenticated'] !== $linkItem['id']) {
- // Prompt for password
- $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
- $tmpl->assign('URL', $url);
- $tmpl->printPage();
- exit();
+ // Check if item id is set in session
+ } else {
+ if (!isset($_SESSION['public_link_authenticated']) || $_SESSION['public_link_authenticated'] !== $linkItem['id']) {
+ // Prompt for password
+ $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
+ $tmpl->assign('URL', $url);
+ $tmpl->printPage();
+ exit();
+ }
}
}
- $basePath = substr($pathAndUser['path'], strlen('/'.$fileOwner.'/files'));
+ $basePath = substr($pathAndUser['path'], strlen('/' . $fileOwner . '/files'));
$path = $basePath;
if (isset($_GET['path'])) {
$path .= $_GET['path'];
}
- if (!$path || !OC_Filesystem::isValidPath($path) || !OC_Filesystem::file_exists($path)) {
- OCP\Util::writeLog('share', 'Invalid path '.$path.' for share id '.$linkItem['id'], \OCP\Util::ERROR);
+ if (!$path || !\OC\Files\Filesystem::isValidPath($path) || !OC_Filesystem::file_exists($path)) {
+ OCP\Util::writeLog('share', 'Invalid path ' . $path . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
@@ -176,13 +186,15 @@ if ($linkItem) {
$file = basename($path);
// Download the file
if (isset($_GET['download'])) {
- if (isset($_GET['path']) && $_GET['path'] !== '' ) {
- if ( isset($_GET['files']) ) { // download selected files
+ if (isset($_GET['path']) && $_GET['path'] !== '') {
+ if (isset($_GET['files'])) { // download selected files
OC_Files::get($path, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
- } else if (isset($_GET['path']) && $_GET['path'] != '' ) { // download a file from a shared directory
- OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
- } else { // download the whole shared directory
- OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+ } else {
+ if (isset($_GET['path']) && $_GET['path'] != '') { // download a file from a shared directory
+ OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+ } else { // download the whole shared directory
+ OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+ }
}
} else { // download a single shared file
OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
@@ -203,7 +215,7 @@ if ($linkItem) {
$getPath = '';
}
//
- $urlLinkIdentifiers= (isset($token)?'&t='.$token:'').(isset($_GET['dir'])?'&dir='.$_GET['dir']:'').(isset($_GET['file'])?'&file='.$_GET['file']:'');
+ $urlLinkIdentifiers = (isset($token) ? '&t=' . $token : '') . (isset($_GET['dir']) ? '&dir=' . $_GET['dir'] : '') . (isset($_GET['file']) ? '&file=' . $_GET['file'] : '');
// Show file list
if (OC_Filesystem::is_dir($path)) {
OCP\Util::addStyle('files', 'files');
@@ -216,9 +228,9 @@ if ($linkItem) {
if ($i['type'] == 'file') {
$fileinfo = pathinfo($i['name']);
$i['basename'] = $fileinfo['filename'];
- $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
+ $i['extension'] = isset($fileinfo['extension']) ? ('.' . $fileinfo['extension']) : '';
}
- $i['directory'] = '/'.substr($i['directory'], $rootLength);
+ $i['directory'] = '/' . substr($i['directory'], $rootLength);
if ($i['directory'] == '/') {
$i['directory'] = '';
}
@@ -235,9 +247,137 @@ if ($linkItem) {
//add subdir breadcrumbs
foreach (explode('/', urldecode($getPath)) as $i) {
if ($i != '') {
- $pathtohere .= '/'.$i;
+ $pathtohere .= '/' . $i;
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
+ $path = $linkItem['path'];
+ if (isset($_GET['path'])) {
+ $path .= $_GET['path'];
+ $dir .= $_GET['path'];
+ if (!\OC\Files\Filesystem::file_exists($path)) {
+ header('HTTP/1.0 404 Not Found');
+ $tmpl = new OCP\Template('', '404', 'guest');
+ $tmpl->printPage();
+ exit();
+ }
+ }
+
+ $list = new OCP\Template('files', 'part.list', '');
+ $list->assign('files', $files, false);
+ $list->assign('publicListView', true);
+ $list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=', false);
+ $list->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=', false);
+ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
+ $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+ $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=', false);
+ $folder = new OCP\Template('files', 'index', '');
+ $folder->assign('fileList', $list->fetchPage(), false);
+ $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
+ $folder->assign('isCreatable', false);
+ $folder->assign('permissions', 0);
+ $folder->assign('files', $files);
+ $folder->assign('uploadMaxFilesize', 0);
+ $folder->assign('uploadMaxHumanFilesize', 0);
+ $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('folder', $folder->fetchPage(), false);
+ $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath));
+ } else {
+ // Show file preview if viewer is available
+ if ($type == 'file') {
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download');
+ } else {
+ OCP\Util::addStyle('files_sharing', 'public');
+ OCP\Util::addScript('files_sharing', 'public');
+ OCP\Util::addScript('files', 'fileactions');
+ $tmpl = new OCP\Template('files_sharing', 'public', 'base');
+ $tmpl->assign('owner', $uidOwner);
+ // Show file list
+ if (OC_Filesystem::is_dir($path)) {
+ OCP\Util::addStyle('files', 'files');
+ OCP\Util::addScript('files', 'files');
+ OCP\Util::addScript('files', 'filelist');
+ $files = array();
+ $rootLength = strlen($baseDir) + 1;
+ foreach (OC_Files::getDirectoryContent($path) as $i) {
+ $i['date'] = OCP\Util::formatDate($i['mtime']);
+ if ($i['type'] == 'file') {
+ $fileinfo = pathinfo($i['name']);
+ $i['basename'] = $fileinfo['filename'];
+ $i['extension'] = isset($fileinfo['extension']) ? ('.' . $fileinfo['extension']) : '';
+ }
+ $i['directory'] = '/' . substr('/' . $uidOwner . '/files' . $i['directory'], $rootLength);
+ if ($i['directory'] == '/') {
+ $i['directory'] = '';
+ }
+ $i['permissions'] = OCP\PERMISSION_READ;
+ $files[] = $i;
+ }
+ // Make breadcrumb
+ $breadcrumb = array();
+ $pathtohere = '';
+ $count = 1;
+ foreach (explode('/', $dir) as $i) {
+ if ($i != '') {
+ if ($i != $baseDir) {
+ $pathtohere .= '/' . $i;
+ }
+ if (strlen($pathtohere) < strlen($_GET['dir'])) {
+ continue;
+ }
+ $breadcrumb[] = array('dir' => str_replace($_GET['dir'], "", $pathtohere, $count), 'name' => $i);
+ }
+ }
+ $list = new OCP\Template('files', 'part.list', '');
+ $list->assign('files', $files, false);
+ $list->assign('publicListView', true);
+ $list->assign('baseURL', OCP\Util::linkToPublic('files') . '&dir=' . urlencode($_GET['dir']) . '&path=', false);
+ $list->assign('downloadURL', OCP\Util::linkToPublic('files') . '&download&dir=' . urlencode($_GET['dir']) . '&path=', false);
+ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
+ $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+ $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . '&dir=' . urlencode($_GET['dir']) . '&path=', false);
+ $folder = new OCP\Template('files', 'index', '');
+ $folder->assign('fileList', $list->fetchPage(), false);
+ $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
+ $folder->assign('dir', basename($dir));
+ $folder->assign('isCreatable', false);
+ $folder->assign('permissions', 0);
+ $folder->assign('files', $files);
+ $folder->assign('uploadMaxFilesize', 0);
+ $folder->assign('uploadMaxHumanFilesize', 0);
+ $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('folder', $folder->fetchPage(), false);
+ $tmpl->assign('uidOwner', $uidOwner);
+ $tmpl->assign('dir', basename($dir));
+ $tmpl->assign('filename', basename($path));
+ $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
+ $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ if (isset($_GET['path'])) {
+ $getPath = $_GET['path'];
+ } else {
+ $getPath = '';
+ }
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . '&download&dir=' . urlencode($_GET['dir']) . '&path=' . urlencode($getPath), false);
+ } else {
+ // Show file preview if viewer is available
+ $tmpl->assign('uidOwner', $uidOwner);
+ $tmpl->assign('dir', dirname($path));
+ $tmpl->assign('filename', basename($path));
+ $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
+ if ($type == 'file') {
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . '&file=' . urlencode($_GET['file']) . '&download', false);
+ } else {
+ if (isset($_GET['path'])) {
+ $getPath = $_GET['path'];
+ } else {
+ $getPath = '';
+ }
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . '&download&dir=' . urlencode($_GET['dir']) . '&path=' . urlencode($getPath), false);
+ }
+ }
+ $tmpl->printPage();
+ }
}
+ $tmpl->printPage();
}
$list = new OCP\Template('files', 'part.list', '');
@@ -262,19 +402,11 @@ if ($linkItem) {
$tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').$urlLinkIdentifiers.'&download&path='.urlencode($getPath));
} else {
- // Show file preview if viewer is available
- if ($type == 'file') {
- $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').$urlLinkIdentifiers.'&download');
- } else {
- $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').$urlLinkIdentifiers.'&download&path='.urlencode($getPath));
- }
+ OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
}
- $tmpl->printPage();
}
- exit();
-} else {
- OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
}
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
+
diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php
index e897a81f7af..4c07ed9bb71 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 0ccaaf1095d..7fe3d5549e9 100644
--- a/apps/files_versions/lib/versions.php
+++ b/apps/files_versions/lib/versions.php
@@ -58,8 +58,8 @@ class Storage {
public function store($filename) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
- $files_view = new \OC_FilesystemView('/'.$uid .'/files');
- $users_view = new \OC_FilesystemView('/'.$uid);
+ $files_view = new \OC\Files\View('/'.\OCP\User::getUser() .'/files');
+ $users_view = new \OC\Files\View('/'.\OCP\User::getUser());
//check if source file already exist as version to avoid recursions.
// todo does this check work?
@@ -94,7 +94,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('/'.$uid.'/files_versions');
+ $versions_fileview = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_versions');
$versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
$versionsFolderName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('');
$matches=glob($versionsName.'.v*');
@@ -128,7 +128,7 @@ class Storage {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
- $users_view = new \OC_FilesystemView('/'.$uid);
+ $users_view = new \OC\Files\View('/' . \OCP\User::getUser());
// rollback
if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) {
@@ -151,7 +151,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('/'.$uid.'/files_versions');
+ $versions_fileview = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_versions');
$versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
@@ -178,7 +178,7 @@ class Storage {
public static function getVersions( $filename, $count = 0 ) {
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('/' . \OCP\User::getUser() . '/files_versions');
$versionsName = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
$versions = array();
@@ -189,7 +189,7 @@ class Storage {
$i = 0;
- $files_view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files');
+ $files_view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files');
$local_file = $files_view->getLocalFile($filename);
foreach( $matches as $ma ) {
@@ -244,7 +244,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');
$versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);