summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_sharing/appinfo/app.php3
-rw-r--r--apps/files_sharing/lib/cache.php220
-rw-r--r--apps/files_sharing/lib/permissions.php82
-rw-r--r--apps/files_sharing/lib/scanner.php69
-rw-r--r--apps/files_sharing/lib/share/file.php74
-rw-r--r--apps/files_sharing/lib/share/folder.php28
-rw-r--r--apps/files_sharing/lib/sharedstorage.php148
-rw-r--r--lib/public/share.php8
8 files changed, 475 insertions, 157 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 210c78ad174..189fd20cae3 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -3,6 +3,9 @@
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\Files\Storage\Shared'] = "apps/files_sharing/lib/sharedstorage.php";
+OC::$CLASSPATH['OC\Files\Cache\Shared_Cache'] = 'apps/files_sharing/lib/cache.php';
+OC::$CLASSPATH['OC\Files\Cache\Shared_Permissions'] = 'apps/files_sharing/lib/permissions.php';
+OC::$CLASSPATH['OC\Files\Cache\Shared_Scanner'] = 'apps/files_sharing/lib/scanner.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');
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
new file mode 100644
index 00000000000..196e767cf6e
--- /dev/null
+++ b/apps/files_sharing/lib/cache.php
@@ -0,0 +1,220 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+namespace OC\Files\Cache;
+
+/**
+ * Metadata cache for shared files
+ *
+ * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
+ */
+class Shared_Cache extends Cache {
+
+ private $files = array();
+
+ /**
+ * @brief Get the source cache of a shared file or folder
+ * @param string Shared target file path
+ * @return \OC\Files\Storage\Cache
+ */
+ private function getSourceCache($target) {
+ $source = \OC_Share_Backend_File::getSource($target);
+ if (isset($source['path'])) {
+ $source['path'] = '/'.$source['uid_owner'].'/'.$source['path'];
+ \OC\Files\Filesystem::initMountPoints($source['uid_owner']);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source['path']);
+ $this->files[$target] = $internalPath;
+ return $storage->getCache();
+ }
+ return false;
+ }
+
+ /**
+ * get the stored metadata of a file or folder
+ *
+ * @param string/int $file
+ * @return array
+ */
+ public function get($file) {
+ if (is_string($file)) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->get($this->files[$file]);
+ }
+ } else {
+ $query = \OC_DB::prepare(
+ 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` WHERE `fileid` = ?');
+ $result = $query->execute(array($file));
+ $data = $result->fetchRow();
+ $data['fileid'] = (int)$data['fileid'];
+ $data['size'] = (int)$data['size'];
+ $data['mtime'] = (int)$data['mtime'];
+ $data['encrypted'] = (bool)$data['encrypted'];
+ return $data;
+ }
+ return false;
+ }
+
+ /**
+ * get the metadata of all files stored in $folder
+ *
+ * @param string $folder
+ * @return array
+ */
+ public function getFolderContents($folder) {
+ if ($folder == '') {
+ return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS);
+ } else {
+ return $this->getSourceCache($folder)->getFolderContents('/'.$this->files[$folder]);
+ }
+ }
+
+ /**
+ * store meta data for a file or folder
+ *
+ * @param string $file
+ * @param array $data
+ *
+ * @return int file id
+ */
+ public function put($file, array $data) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->put($this->files[$file]);
+ }
+ return false;
+ }
+
+ /**
+ * get the file id for a file
+ *
+ * @param string $file
+ * @return int
+ */
+ public function getId($file) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->getId($this->files[$file]);
+ }
+ return -1;
+ }
+
+ /**
+ * remove a file or folder from the cache
+ *
+ * @param string $file
+ */
+ public function remove($file) {
+ if ($cache = $this->getSourceCache($file)) {
+ $cache->remove($this->files[$file]);
+ }
+ }
+
+ /**
+ * Move a file or folder in the cache
+ *
+ * @param string $source
+ * @param string $target
+ */
+ public function move($source, $target) {
+ if ($cache = $this->getSourceCache($source)) {
+ $targetPath = \OC_Share_Backend_File::getSourcePath(dirname($target));
+ if ($targetPath) {
+ $targetPath .= '/'.basename($target);
+ $cache->move($this->files[$source], $targetPath);
+ }
+
+ }
+ }
+
+ /**
+ * remove all entries for files that are stored on the storage from the cache
+ */
+ public function clear() {
+ // Not a valid action for Shared Cache
+ }
+
+ /**
+ * @param string $file
+ *
+ * @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
+ */
+ public function getStatus($file) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->getStatus($this->files[$file]);
+ }
+ return false;
+ }
+
+ /**
+ * search for files matching $pattern
+ *
+ * @param string $pattern
+ * @return array of file data
+ */
+ public function search($pattern) {
+ // TODO
+ }
+
+ /**
+ * search for files by mimetype
+ *
+ * @param string $part1
+ * @param string $part2
+ * @return array
+ */
+ public function searchByMime($mimetype) {
+ if (strpos($mimetype, '/')) {
+ $where = '`mimetype` = ?';
+ } else {
+ $where = '`mimepart` = ?';
+ }
+ $ids = $this->getAll();
+ $placeholders = join(',', array_fill(0, count($ids), '?'));
+ $query = \OC_DB::prepare('
+ SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `fileid` IN = ('.$placeholders.')'
+ );
+ $result = $query->execute(array_merge(array($mimetype), $ids));
+ return $result->fetchAll();
+ }
+
+ /**
+ * get the size of a folder and set it in the cache
+ *
+ * @param string $path
+ * @return int
+ */
+ public function calculateFolderSize($path) {
+ if ($cache = $this->getSourceCache($path)) {
+ return $cache->calculateFolderSize($this->files[$path]);
+ }
+ return 0;
+ }
+
+ /**
+ * get all file ids on the files on the storage
+ *
+ * @return int[]
+ */
+ public function getAll() {
+ return OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL);
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/permissions.php b/apps/files_sharing/lib/permissions.php
new file mode 100644
index 00000000000..51ae4cf102b
--- /dev/null
+++ b/apps/files_sharing/lib/permissions.php
@@ -0,0 +1,82 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+namespace OC\Files\Cache;
+
+class Shared_Permissions {
+
+ /**
+ * get the permissions for a single file
+ *
+ * @param int $fileId
+ * @param string $user
+ * @return int (-1 if file no permissions set)
+ */
+ static public function get($fileId, $user) {
+ $source = \OCP\Share::getItemSharedWithBySource('file', $fileId, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($source) {
+ return $source['permissions'];
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * set the permissions of a file
+ *
+ * @param int $fileId
+ * @param string $user
+ * @param int $permissions
+ */
+ static public function set($fileId, $user, $permissions) {
+ // Not a valid action for Shared Permissions
+ }
+
+ /**
+ * get the permissions of multiply files
+ *
+ * @param int[] $fileIds
+ * @param string $user
+ * @return int[]
+ */
+ static public function getMultiple($fileIds, $user) {
+ if (count($fileIds) === 0) {
+ return array();
+ }
+ foreach ($fileIds as $fileId) {
+ $filePermissions[$fileId] = self::get($fileId, $user);
+ }
+ return $filePermissions;
+ }
+
+ /**
+ * remove the permissions for a file
+ *
+ * @param int $fileId
+ * @param string $user
+ */
+ static public function remove($fileId, $user) {
+ // Not a valid action for Shared Permissions
+ }
+
+ static public function removeMultiple($fileIds, $user) {
+ // Not a valid action for Shared Permissions
+ }
+}
diff --git a/apps/files_sharing/lib/scanner.php b/apps/files_sharing/lib/scanner.php
new file mode 100644
index 00000000000..d13d2f9cbc3
--- /dev/null
+++ b/apps/files_sharing/lib/scanner.php
@@ -0,0 +1,69 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+namespace OC\Files\Cache;
+
+class Shared_Scanner extends Scanner {
+
+ public function __construct(\OC\Files\Storage\Storage $storage) {
+
+ }
+
+ /**
+ * get all the metadata of a file or folder
+ * *
+ *
+ * @param string $path
+ * @return array with metadata of the file
+ */
+ public function getData($path) {
+ // Not a valid action for Shared Scanner
+ }
+
+ /**
+ * scan a single file and store it in the cache
+ *
+ * @param string $file
+ * @return array with metadata of the scanned file
+ */
+ public function scanFile($file) {
+ // Not a valid action for Shared Scanner
+ }
+
+ /**
+ * scan all the files in a folder and store them in the cache
+ *
+ * @param string $path
+ * @param SCAN_RECURSIVE/SCAN_SHALLOW $recursive
+ * @return int the size of the scanned folder or -1 if the size is unknown at this stage
+ */
+ public function scan($path, $recursive = self::SCAN_RECURSIVE) {
+ // Not a valid action for Shared Scanner
+ }
+
+ /**
+ * walk over any folders that are not fully scanned yet and scan them
+ */
+ public function backgroundScan() {
+ // Not a valid action for Shared Scanner
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index ac585236831..52220dc5b2b 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -22,16 +22,17 @@
class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
const FORMAT_SHARED_STORAGE = 0;
- const FORMAT_FILE_APP = 1;
- const FORMAT_FILE_APP_ROOT = 2;
+ const FORMAT_GET_FOLDER_CONTENTS = 1;
+ const FORMAT_GET_ALL = 2;
const FORMAT_OPENDIR = 3;
private $path;
public function isValidSource($itemSource, $uidOwner) {
- $path = OC_FileCache::getPath($itemSource, $uidOwner);
- if ($path) {
- $this->path = $path;
+ $query = \OC_DB::prepare('SELECT `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
+ $result = $query->execute(array($itemSource));
+ if ($row = $result->fetchRow()) {
+ $this->path = $row['name'];
return true;
}
return false;
@@ -70,50 +71,29 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
- return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']);
- } else if ($format == self::FORMAT_FILE_APP) {
- if (isset($parameters['mimetype_filter']) && $parameters['mimetype_filter']) {
- $mimetype_filter = $parameters['mimetype_filter'];
- }
+ return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner']);
+ } else if ($format == self::FORMAT_GET_FOLDER_CONTENTS) {
$files = array();
foreach ($items as $item) {
- if (isset($mimetype_filter)
- && strpos($item['mimetype'], $mimetype_filter) !== 0
- && $item['mimetype'] != 'httpd/unix-directory') {
- continue;
- }
$file = array();
- $file['id'] = $item['file_source'];
+ $file['fileid'] = $item['file_source'];
+ $file['storage'] = $item['storage'];
$file['path'] = $item['file_target'];
+ $file['parent'] = $item['file_parent'];
$file['name'] = basename($item['file_target']);
- $file['ctime'] = $item['ctime'];
- $file['mtime'] = $item['mtime'];
$file['mimetype'] = $item['mimetype'];
$file['size'] = $item['size'];
+ $file['mtime'] = $item['mtime'];
$file['encrypted'] = $item['encrypted'];
- $file['versioned'] = $item['versioned'];
- $file['directory'] = $parameters['folder'];
- $file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
- $file['permissions'] = $item['permissions'];
- if ($file['type'] == 'file') {
- // Remove Create permission if type is file
- $file['permissions'] &= ~OCP\PERMISSION_CREATE;
- }
- // NOTE: Temporary fix to allow unsharing of files in root of Shared directory
- $file['permissions'] |= OCP\PERMISSION_DELETE;
$files[] = $file;
}
return $files;
- } else if ($format == self::FORMAT_FILE_APP_ROOT) {
- $mtime = 0;
- $size = 0;
+ } else if ($format == self::FORMAT_GET_ALL) {
+ $ids = array();
foreach ($items as $item) {
- if ($item['mtime'] > $mtime) {
- $mtime = $item['mtime'];
- }
- $size += $item['size'];
+ $ids[] = $item['file_source'];
}
- return array(0 => array('id' => -1, 'name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\PERMISSION_READ));
+ return $ids;
} else if ($format == self::FORMAT_OPENDIR) {
$files = array();
foreach ($items as $item) {
@@ -124,4 +104,26 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
return array();
}
+ public static function getSource($target) {
+ $target = '/'.$target;
+ $target = rtrim($target, '/');
+ $pos = strpos($target, '/', 1);
+ // Get shared folder name
+ if ($pos !== false) {
+ $folder = substr($target, 0, $pos);
+ $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($source) {
+ $source['path'] = $source['path'].substr($target, strlen($folder));
+ return $source;
+ }
+ } else {
+ $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($source) {
+ return $source;
+ }
+ }
+ \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR);
+ return false;
+ }
+
}
diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php
index d414fcf10fc..a1bb843d726 100644
--- a/apps/files_sharing/lib/share/folder.php
+++ b/apps/files_sharing/lib/share/folder.php
@@ -21,34 +21,6 @@
class OC_Share_Backend_Folder extends OC_Share_Backend_File implements OCP\Share_Backend_Collection {
- public function formatItems($items, $format, $parameters = null) {
- if ($format == self::FORMAT_SHARED_STORAGE) {
- // Only 1 item should come through for this format call
- return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']);
- } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
- // Only 1 item should come through for this format call
- $folder = $items[key($items)];
- if (isset($parameters['mimetype_filter'])) {
- $mimetype_filter = $parameters['mimetype_filter'];
- } else {
- $mimetype_filter = '';
- }
- $path = $folder['path'].substr($parameters['folder'], 7 + strlen($folder['file_target']));
- $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter);
- foreach ($files as &$file) {
- $file['directory'] = $parameters['folder'];
- $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
- $file['permissions'] = $folder['permissions'];
- if ($file['type'] == 'file') {
- // Remove Create permission if type is file
- $file['permissions'] &= ~OCP\PERMISSION_CREATE;
- }
- }
- return $files;
- }
- return array();
- }
-
public function getChildren($itemSource) {
$children = array();
$parents = array($itemSource);
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 5abdbf29f03..960aa64099e 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -34,41 +34,8 @@ class Shared extends \OC\Files\Storage\Common {
$this->sharedFolder = $arguments['sharedFolder'];
}
- /**
- * @brief Get the source file path and the permissions granted for a shared file
- * @param string Shared target file path
- * @return array with the keys path and permissions or false if not found
- */
- private function getFile($target) {
- $target = '/'.$target;
- $target = rtrim($target, '/');
- if (isset($this->files[$target])) {
- return $this->files[$target];
- } else {
- $pos = strpos($target, '/', 1);
- // Get shared folder name
- if ($pos !== false) {
- $folder = substr($target, 0, $pos);
- if (isset($this->files[$folder])) {
- $file = $this->files[$folder];
- } else {
- $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));
- $this->files[$target]['permissions'] = $file['permissions'];
- return $this->files[$target];
- }
- } else {
- $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);
- return false;
- }
+ public function getId(){
+ return 'shared::' . $this->sharedFolder;
}
/**
@@ -77,13 +44,13 @@ class Shared extends \OC\Files\Storage\Common {
* @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\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => \OC_User::getHome($uid)), $uid);
- return $file['path'];
+ if (!isset($this->files[$target])) {
+ $source = \OC_Share_Backend_File::getSource($target);
+ $source['path'] = '/'.$source['uid_owner'].'/'.$source['path'];
+ $this->files[$target] = $source;
+ \OC\Files\Filesystem::initMountPoints($source['uid_owner']);
}
- return false;
+ return $this->files[$target]['path'];
}
/**
@@ -92,26 +59,18 @@ class Shared extends \OC\Files\Storage\Common {
* @return int CRUDS permissions granted or false if not found
*/
public function getPermissions($target) {
- $file = $this->getFile($target);
- if (isset($file['permissions'])) {
- return $file['permissions'];
+ if (!isset($this->files[$target])) {
+ $source = \OC_Share_Backend_File::getSource($target);
+ $this->files[$target] = $source;
}
- return false;
- }
-
- public function getOwner($target) {
- $shared_item = \OCP\Share::getItemSharedWith('folder', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
- if ($shared_item) {
- return $shared_item[0]["uid_owner"];
- }
- return null;
+ return $this->files[$target]['permissions'];
}
public function mkdir($path) {
if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
return false;
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->mkdir($internalPath);
}
return false;
@@ -119,7 +78,7 @@ class Shared extends \OC\Files\Storage\Common {
public function rmdir($path) {
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->rmdir($internalPath);
}
return false;
@@ -131,7 +90,7 @@ class Shared extends \OC\Files\Storage\Common {
\OC_FakeDirStream::$dirs['shared'] = $files;
return opendir('fakedir://shared');
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->opendir($internalPath);
}
return false;
@@ -141,7 +100,7 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->is_dir($internalPath);
}
return false;
@@ -149,7 +108,7 @@ class Shared extends \OC\Files\Storage\Common {
public function is_file($path) {
if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->is_file($internalPath);
}
return false;
@@ -161,7 +120,7 @@ class Shared extends \OC\Files\Storage\Common {
$stat['mtime'] = $this->filemtime($path);
return $stat;
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->stat($internalPath);
}
return false;
@@ -171,7 +130,7 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->filetype($internalPath);
}
return false;
@@ -181,7 +140,7 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/' || $this->is_dir($path)) {
return 0;
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->filesize($internalPath);
}
return false;
@@ -191,7 +150,7 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_CREATE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE);
}
public function isReadable($path) {
@@ -202,28 +161,28 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_UPDATE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_UPDATE);
}
public function isDeletable($path) {
if ($path == '') {
return true;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_DELETE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_DELETE);
}
public function isSharable($path) {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_SHARE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_SHARE);
}
public function file_exists($path) {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->file_exists($internalPath);
}
return false;
@@ -244,7 +203,7 @@ class Shared extends \OC\Files\Storage\Common {
} else {
$source = $this->getSourcePath($path);
if ($source) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->filemtime($internalPath);
}
}
@@ -258,7 +217,7 @@ class Shared extends \OC\Files\Storage\Common {
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->file_get_contents($internalPath);
}
}
@@ -274,7 +233,7 @@ class Shared extends \OC\Files\Storage\Common {
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
$result = $storage->file_put_contents($internalPath, $data);
return $result;
}
@@ -285,7 +244,7 @@ class Shared extends \OC\Files\Storage\Common {
// Delete the file if DELETE permission is granted
if ($source = $this->getSourcePath($path)) {
if ($this->isDeletable($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($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
@@ -309,8 +268,8 @@ class Shared extends \OC\Files\Storage\Common {
if (dirname($path1) == dirname($path2)) {
// Rename the file if UPDATE permission is granted
if ($this->isUpdatable($path1)) {
- list($storage, $oldInternalPath)=\OC\Files\Filesystem::resolvePath($oldSource);
- list( , $newInternalPath)=\OC\Files\Filesystem::resolvePath($newSource);
+ list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
return $storage->rename($oldInternalPath, $newInternalPath);
}
} else {
@@ -325,8 +284,8 @@ class Shared extends \OC\Files\Storage\Common {
return $this->unlink($path1);
}
} else {
- list($storage, $oldInternalPath)=\OC\Files\Filesystem::resolvePath($oldSource);
- list( , $newInternalPath)=\OC\Files\Filesystem::resolvePath($newSource);
+ list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
return $storage->rename($oldInternalPath, $newInternalPath);
}
}
@@ -372,7 +331,7 @@ class Shared extends \OC\Files\Storage\Common {
'mode' => $mode,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->fopen($internalPath, $mode);
}
return false;
@@ -383,7 +342,7 @@ class Shared extends \OC\Files\Storage\Common {
return 'httpd/unix-directory';
}
if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->getMimeType($internalPath);
}
return false;
@@ -392,21 +351,21 @@ class Shared extends \OC\Files\Storage\Common {
public function free_space($path) {
$source = $this->getSourcePath($path);
if ($source) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->free_space($internalPath);
}
}
public function getLocalFile($path) {
if ($source = $this->getSourcePath($path)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($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)) {
- list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->touch($internalPath, $mtime);
}
return false;
@@ -417,17 +376,28 @@ class Shared extends \OC\Files\Storage\Common {
\OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
}
- /**
- * check if a file or folder has been updated since $time
- * @param int $time
- * @return bool
- */
- public function hasUpdated($path, $time) {
- //TODO
- return false;
+ public function getCache() {
+ return new \OC\Files\Cache\Shared_Cache($this);
}
- public function getId(){
- return 'shared::' . $this->sharedFolder;
+ public function getScanner(){
+ return new \OC\Files\Cache\Shared_Scanner($this);
}
+
+ public function getPermissionsCache() {
+ return new \OC\Files\Cache\Shared_Permissions($this);
+ }
+
+ public function getOwner($path) {
+ if (!isset($this->files[$path])) {
+ $source = \OC_Share_Backend_File::getSource($path);
+ $this->files[$path] = $source;
+ }
+ return $this->files[$path]['uid_owner'];
+ }
+
+ public function getETag($path) {
+
+ }
+
}
diff --git a/lib/public/share.php b/lib/public/share.php
index 9bb64a38c8b..8981de1b508 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -552,7 +552,7 @@ class Share {
// Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache
if ($itemType == 'file' || $itemType == 'folder') {
$root = \OC\Files\Filesystem::getRoot();
- $where = 'INNER JOIN `*PREFIX*fscache` ON `file_source` = `*PREFIX*fscache`.`id`';
+ $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid`';
if (!isset($item)) {
$where .= ' WHERE `file_target` IS NOT NULL';
}
@@ -569,7 +569,7 @@ class Share {
$itemTypes = $collectionTypes;
}
$placeholders = join(',', array_fill(0, count($itemTypes), '?'));
- $where .= ' WHERE `item_type` IN ('.$placeholders.'))';
+ $where = ' WHERE `item_type` IN ('.$placeholders.'))';
$queryArgs = $itemTypes;
} else {
$where = ' WHERE `item_type` = ?';
@@ -681,8 +681,8 @@ class Share {
}
} else {
if ($fileDependent) {
- if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) {
- $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`';
+ if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS) {
+ $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `*PREFIX*filecache`.`parent` as `file_parent`, `name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`';
} else {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`';
}