diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-12-13 14:02:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-13 14:02:49 +0100 |
commit | edd01e3ce4809e040c4a75432c531be6a80022d2 (patch) | |
tree | 0f222c5068f52be220036817ccd53e72a4d09303 | |
parent | 3b3ab256a51339c0c7278274a4ba7d4835049bd9 (diff) | |
parent | 14a561ddad8bbd6ae1d524a49c70a7926c06310f (diff) | |
download | nextcloud-server-edd01e3ce4809e040c4a75432c531be6a80022d2.tar.gz nextcloud-server-edd01e3ce4809e040c4a75432c531be6a80022d2.zip |
Merge pull request #2637 from nextcloud/mount-cache-storageid
also compare storage ids when checking for changed mounts
-rw-r--r-- | apps/files_sharing/lib/SharedMount.php | 34 | ||||
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 7 | ||||
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 7 | ||||
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 1 |
4 files changed, 28 insertions, 21 deletions
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 5436f476f1a..b7fb96b711b 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -130,12 +130,12 @@ class SharedMount extends MountPoint implements MoveableMount { */ private function generateUniqueTarget($path, $view, array $mountpoints) { $pathinfo = pathinfo($path); - $ext = (isset($pathinfo['extension'])) ? '.'.$pathinfo['extension'] : ''; + $ext = (isset($pathinfo['extension'])) ? '.' . $pathinfo['extension'] : ''; $name = $pathinfo['filename']; $dir = $pathinfo['dirname']; // Helper function to find existing mount points - $mountpointExists = function($path) use ($mountpoints) { + $mountpointExists = function ($path) use ($mountpoints) { foreach ($mountpoints as $mountpoint) { if ($mountpoint->getShare()->getTarget() === $path) { return true; @@ -146,7 +146,7 @@ class SharedMount extends MountPoint implements MoveableMount { $i = 2; while ($view->file_exists($path) || $mountpointExists($path)) { - $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext); + $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); $i++; } @@ -240,18 +240,22 @@ class SharedMount extends MountPoint implements MoveableMount { * @return int */ public function getNumericStorageId() { - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); - - $query = $builder->select('storage') - ->from('filecache') - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); - - $result = $query->execute(); - $row = $result->fetch(); - $result->closeCursor(); - if ($row) { - return $row['storage']; + if (!is_null($this->getShare()->getNodeCacheEntry())) { + return $this->getShare()->getNodeCacheEntry()->getStorageId(); + } else { + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + + $query = $builder->select('storage') + ->from('filecache') + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); + + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + if ($row) { + return $row['storage']; + } + return -1; } - return -1; } } diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 3a3f51488e6..a966d621c58 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -142,7 +142,7 @@ class Cache implements ICache { } return $data; } else { - return self::cacheEntryFromData($data, $this->storageId, $this->mimetypeLoader); + return self::cacheEntryFromData($data, $this->mimetypeLoader); } } @@ -150,11 +150,10 @@ class Cache implements ICache { * Create a CacheEntry from database row * * @param array $data - * @param string $storageId * @param IMimeTypeLoader $mimetypeLoader * @return CacheEntry */ - public static function cacheEntryFromData($data, $storageId, IMimeTypeLoader $mimetypeLoader) { + public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) { //fix types $data['fileid'] = (int)$data['fileid']; $data['parent'] = (int)$data['parent']; @@ -163,7 +162,7 @@ class Cache implements ICache { $data['storage_mtime'] = (int)$data['storage_mtime']; $data['encryptedVersion'] = (int)$data['encrypted']; $data['encrypted'] = (bool)$data['encrypted']; - $data['storage'] = $storageId; + $data['storage_id'] = $data['storage']; $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); if ($data['storage_mtime'] == 0) { diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index c9a701d24b6..423eb5c423d 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -141,7 +141,11 @@ class UserMountCache implements IUserMountCache { foreach ($cachedMounts as $cachedMount) { if ( $newMount->getRootId() === $cachedMount->getRootId() && - ($newMount->getMountPoint() !== $cachedMount->getMountPoint() || $newMount->getMountId() !== $cachedMount->getMountId()) + ( + $newMount->getMountPoint() !== $cachedMount->getMountPoint() || + $newMount->getStorageId() !== $cachedMount->getStorageId() || + $newMount->getMountId() !== $cachedMount->getMountId() + ) ) { $changed[] = $newMount; } @@ -169,6 +173,7 @@ class UserMountCache implements IUserMountCache { $builder = $this->connection->getQueryBuilder(); $query = $builder->update('mounts') + ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 7a602950171..fded7442d20 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -853,7 +853,6 @@ class DefaultShareProvider implements IShareProvider { $entryData['permissions'] = $entryData['f_permissions']; $entryData['parent'] = $entryData['f_parent'];; $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, - $entryData['storage_string_id'], \OC::$server->getMimeTypeLoader())); } |