From a521949bafdaba0cb94061967b6b8307bbbebc05 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Jan 2014 15:41:56 +0100 Subject: Allow passing a root folder to get the used space from in the quota wrapper --- lib/private/files/storage/wrapper/quota.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/private/files') diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php index a430e3e4617..83a5de5ca30 100644 --- a/lib/private/files/storage/wrapper/quota.php +++ b/lib/private/files/storage/wrapper/quota.php @@ -15,12 +15,18 @@ class Quota extends Wrapper { */ protected $quota; + /** + * @var string $freeSpaceRoot + */ + protected $sizeRoot; + /** * @param array $parameters */ public function __construct($parameters) { $this->storage = $parameters['storage']; $this->quota = $parameters['quota']; + $this->freeSpaceRoot = isset($parameters['root']) ? $parameters['root'] : ''; } protected function getSize($path) { @@ -43,7 +49,7 @@ class Quota extends Wrapper { if ($this->quota < 0) { return $this->storage->free_space($path); } else { - $used = $this->getSize(''); + $used = $this->getSize($this->freeSpaceRoot); if ($used < 0) { return \OC\Files\SPACE_NOT_COMPUTED; } else { -- cgit v1.2.3 From c8207312c73f61b2be4aa8ca1d9ae6a8c33453cf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Jan 2014 16:00:10 +0100 Subject: Fix phpdoc --- lib/private/files/storage/wrapper/quota.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private/files') diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php index 83a5de5ca30..2fc3119fc7d 100644 --- a/lib/private/files/storage/wrapper/quota.php +++ b/lib/private/files/storage/wrapper/quota.php @@ -16,7 +16,7 @@ class Quota extends Wrapper { protected $quota; /** - * @var string $freeSpaceRoot + * @var string $sizeRoot */ protected $sizeRoot; -- cgit v1.2.3 From 20c2aaab00e92d74547ccd6c964102e10ea34cbf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Jan 2014 16:26:54 +0100 Subject: Actually rename the variable --- lib/private/files/storage/wrapper/quota.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/private/files') diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php index 2fc3119fc7d..16127403181 100644 --- a/lib/private/files/storage/wrapper/quota.php +++ b/lib/private/files/storage/wrapper/quota.php @@ -26,7 +26,7 @@ class Quota extends Wrapper { public function __construct($parameters) { $this->storage = $parameters['storage']; $this->quota = $parameters['quota']; - $this->freeSpaceRoot = isset($parameters['root']) ? $parameters['root'] : ''; + $this->sizeRoot = isset($parameters['root']) ? $parameters['root'] : ''; } protected function getSize($path) { @@ -49,7 +49,7 @@ class Quota extends Wrapper { if ($this->quota < 0) { return $this->storage->free_space($path); } else { - $used = $this->getSize($this->freeSpaceRoot); + $used = $this->getSize($this->sizeRoot); if ($used < 0) { return \OC\Files\SPACE_NOT_COMPUTED; } else { -- cgit v1.2.3 From 1331de554c0ab619df1826424e502803535481e2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 19 Feb 2014 10:46:02 +0100 Subject: Reuse the folder id in View->getFolderContents --- lib/private/files/cache/cache.php | 7 +++++-- lib/private/files/view.php | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/private/files') diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index 4cab4619149..dbdc42ecc48 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -162,10 +162,13 @@ class Cache { * get the metadata of all files stored in $folder * * @param string $folder + * @param int $fileId (optional) the file id of the folder * @return array */ - public function getFolderContents($folder) { - $fileId = $this->getId($folder); + public function getFolderContents($folder, $fileId = null) { + if (is_null($fileId)) { + $fileId = $this->getId($folder); + } if ($fileId > -1) { $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `unencrypted_size`, `etag` diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 530aa8f7514..3fbc9080d1f 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -880,12 +880,13 @@ class View { $watcher->checkUpdate($internalPath); } + $folderId = $cache->getId($internalPath); $files = array(); - $contents = $cache->getFolderContents($internalPath); //TODO: mimetype_filter + $contents = $cache->getFolderContents($internalPath, $folderId); //TODO: mimetype_filter foreach ($contents as $content) { $files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content); } - $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user); + $permissions = $permissionsCache->getDirectoryPermissions($folderId, $user); $ids = array(); foreach ($files as $i => $file) { -- cgit v1.2.3 From f11658698d48e0fdd2065466651c4c86c22a80f2 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 20 Feb 2014 18:53:37 +0100 Subject: Fix path to the mount file --- lib/private/files/filesystem.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/private/files') diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 952f9f9febf..7f7b6f7f468 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -320,7 +320,8 @@ class Filesystem { else { self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); } - $mount_file = \OC_Config::getValue("mount_file", \OC::$SERVERROOT . "/data/mount.json"); + $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); + $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json"); //move config file to it's new position if (is_file(\OC::$SERVERROOT . '/config/mount.json')) { -- cgit v1.2.3 From dd98e6333f59de05e04a1bd6a887ff1554233e28 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 21 Feb 2014 15:35:12 +0100 Subject: Split getFolderContentById --- lib/private/files/cache/cache.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/private/files') diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index dbdc42ecc48..fcc7099bbc9 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -169,6 +169,16 @@ class Cache { if (is_null($fileId)) { $fileId = $this->getId($folder); } + return $this->getFolderContentsById($fileId); + } + + /** + * get the metadata of all files stored in $folder + * + * @param int $fileId the file id of the folder + * @return array + */ + public function getFolderContentsById($fileId) { if ($fileId > -1) { $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `unencrypted_size`, `etag` -- cgit v1.2.3 From 3487a95eaba04e6ced29d86a7cba9151513a1703 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 21 Feb 2014 15:36:24 +0100 Subject: Remove fileid parameter for getFolderContent --- lib/private/files/cache/cache.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/private/files') diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index fcc7099bbc9..9b18257088c 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -162,13 +162,10 @@ class Cache { * get the metadata of all files stored in $folder * * @param string $folder - * @param int $fileId (optional) the file id of the folder * @return array */ - public function getFolderContents($folder, $fileId = null) { - if (is_null($fileId)) { - $fileId = $this->getId($folder); - } + public function getFolderContents($folder) { + $fileId = $this->getId($folder); return $this->getFolderContentsById($fileId); } -- cgit v1.2.3 From c465835e856601ccbe2643f690b0bc38ca5c3aa8 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 24 Feb 2014 12:20:11 +0100 Subject: Replace deleteAll call with unlink call The method deleteAll() doesn't officially exist on the Storage class as it's not defined on the interface, which means it fails on the Quota storage wrapper and might fail on some external storage classes. Also, this here is the only use case for that one method. --- lib/private/files/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private/files') diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 530aa8f7514..5206e4f01b7 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -413,7 +413,7 @@ class View { $result = $this->copy($path1, $path2); if ($result === true) { list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); - $result = $storage1->deleteAll($internalPath1); + $result = $storage1->unlink($internalPath1); } } else { $source = $this->fopen($path1 . $postFix1, 'r'); -- cgit v1.2.3 From a23ef25010f8232c36337bb6b48c9a0bd7a59b40 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 24 Feb 2014 12:21:48 +0100 Subject: Removed unused deleteAll method on Common storage class The "deleteAll" method on the Common storage class isn't used anywhere. Also, it isn't defined on the Storage interface so this fix removes it completely. --- lib/private/files/storage/common.php | 37 ------------------------------------ 1 file changed, 37 deletions(-) (limited to 'lib/private/files') diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index d4dca780ff3..9e826dd6192 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -140,43 +140,6 @@ abstract class Common implements \OC\Files\Storage\Storage { return $result; } - /** - * @brief Deletes all files and folders recursively within a directory - * @param string $directory The directory whose contents will be deleted - * @param bool $empty Flag indicating whether directory will be emptied - * @returns bool - * - * @note By default the directory specified by $directory will be - * deleted together with its contents. To avoid this set $empty to true - */ - public function deleteAll($directory, $empty = false) { - $directory = trim($directory, '/'); - if (!$this->is_dir($directory) || !$this->isReadable($directory)) { - return false; - } else { - $directoryHandle = $this->opendir($directory); - if (is_resource($directoryHandle)) { - while (($contents = readdir($directoryHandle)) !== false) { - if (!\OC\Files\Filesystem::isIgnoredDir($contents)) { - $path = $directory . '/' . $contents; - if ($this->is_dir($path)) { - $this->deleteAll($path); - } else { - $this->unlink($path); - } - } - } - } - if ($empty === false) { - if (!$this->rmdir($directory)) { - return false; - } - } - return true; - } - - } - public function getMimeType($path) { if ($this->is_dir($path)) { return 'httpd/unix-directory'; -- cgit v1.2.3 From ebd73aee8ff96f7252fab65ab4dc7230d2eb551c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 24 Feb 2014 13:56:53 +0100 Subject: don't overwrite keys if rename was done by a stream copy --- apps/files_encryption/hooks/hooks.php | 17 +++++++++++++---- lib/private/files/view.php | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/private/files') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 3af43f10264..0b6c5adf3fb 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -501,11 +501,20 @@ class Hooks { * @param array $params with the old path and the new path */ public static function preRename($params) { - $util = new Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); + $user = \OCP\User::getUser(); + $view = new \OC_FilesystemView('/'); + $util = new Util($view, $user); list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']); - self::$renamedFiles[$params['oldpath']] = array( - 'uid' => $ownerOld, - 'path' => $pathOld); + + // we only need to rename the keys if the rename happens on the same mountpoint + // otherwise we perform a stream copy, so we get a new set of keys + $mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']); + $mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']); + if ($mp1 === $mp2) { + self::$renamedFiles[$params['oldpath']] = array( + 'uid' => $ownerOld, + 'path' => $pathOld); + } } /** diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 530aa8f7514..e2c565c5cbb 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -534,6 +534,8 @@ class View { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); list($count, $result) = \OC_Helper::streamCopy($source, $target); + fclose($source); + fclose($target); } } if ($this->shouldEmitHooks() && $result !== false) { -- cgit v1.2.3 From 7c92e2e3ad9555746aca7df38431a56bc4aced83 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 27 Feb 2014 14:04:19 +0100 Subject: Update rawlist to work with new fileinfo object --- apps/files/ajax/rawlist.php | 59 +++++++++++++++++++--------------------- lib/private/files/filesystem.php | 2 +- 2 files changed, 29 insertions(+), 32 deletions(-) (limited to 'lib/private/files') diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 40da32b223a..89c21a172fc 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -1,12 +1,12 @@ getPreviewManager()->isMimeSupported($file['mimetype']); - $file["date"] = OCP\Util::formatDate($file["mtime"]); - $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file); - $files[] = $file; - } +if ($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { + $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, 'httpd/unix-directory')); } if (is_array($mimetypes) && count($mimetypes)) { foreach ($mimetypes as $mimetype) { - foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) { - $file['directory'] = $dir; - $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']); - $file["date"] = OCP\Util::formatDate($file["mtime"]); - $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file); - $files[] = $file; - } + $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, $mimetype)); } } else { - foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) { - $file['directory'] = $dir; - $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']); - $file["date"] = OCP\Util::formatDate($file["mtime"]); - $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file); - $files[] = $file; - } + $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir)); +} + +$result = array(); +foreach ($files as $file) { + $fileData = array(); + $fileData['directory'] = $dir; + $fileData['name'] = $file->getName(); + $fileData['type'] = $file->getType(); + $fileData['path'] = $file['path']; + $fileData['id'] = $file->getId(); + $fileData['size'] = $file->getSize(); + $fileData['mtime'] = $file->getMtime(); + $fileData['mimetype'] = $file->getMimetype(); + $fileData['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file->getMimetype()); + $fileData["date"] = OCP\Util::formatDate($file->getMtime()); + $fileData['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file); + $result[] = $fileData; } // Sort by name -usort($files, function ($a, $b) { - if ($a['name'] === $b['name']) { - return 0; - } - return ($a['name'] < $b['name']) ? -1 : 1; -}); +usort($result, array('\OCA\Files\Helper', 'fileCmp')); -OC_JSON::success(array('data' => $files)); +OC_JSON::success(array('data' => $result)); diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 7f7b6f7f468..6478854eae8 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -761,7 +761,7 @@ class Filesystem { * * @param string $directory path under datadirectory * @param string $mimetype_filter limit returned content to this mimetype or mimepart - * @return array + * @return \OC\Files\FileInfo[] */ public static function getDirectoryContent($directory, $mimetype_filter = '') { return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter); -- cgit v1.2.3