From 8983465210c9dcd91cc178a072775efbcda85ca8 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 26 Feb 2013 01:21:48 -0500 Subject: Correct parent folders' ETags for all users with access to a shared file --- apps/files_sharing/lib/updater.php | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 apps/files_sharing/lib/updater.php (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php new file mode 100644 index 00000000000..af6f9215598 --- /dev/null +++ b/apps/files_sharing/lib/updater.php @@ -0,0 +1,77 @@ +. + */ + +namespace OC\Files\Cache; + +class Shared_Updater { + + /** + * Correct the parent folders' ETags for all users shared the file at $target + * + * @param string $target + */ + static public function correctFolders($target) { + $uid = \OCP\User::getUser(); + $uidOwner = \OC\Files\Filesystem::getOwner($target); + $info = \OC\Files\Filesystem::getFileInfo($target); + // Correct Shared folders of other users shared with + $users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true); + if (!empty($users)) { + foreach ($users as $user) { + // The ETag of the logged in user should already be updated + if ($user !== $uid) { + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + } + } + // Correct folders of shared file owner + if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) { + \OC\Files\Filesystem::initMountPoints($source['uid_owner']); + $source = '/'.$source['uid_owner'].'/'.$source['path']; + $mtime = \OC\Files\Filesystem::filemtime($target); + \OC\Files\Cache\Updater::correctFolder($source, $mtime); + } + } + } + + /** + * @param array $params + */ + static public function writeHook($params) { + self::correctFolders($params['path']); + } + + /** + * @param array $params + */ + static public function renameHook($params) { + self::correctFolders($params['oldpath']); + self::correctFolders($params['newpath']); + } + + /** + * @param array $params + */ + static public function deleteHook($params) { + self::correctFolders($params['path']); + } + +} \ No newline at end of file -- cgit v1.2.3 From ea83acedebbcf70b19643efe82b72fb139cf8ad2 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 26 Feb 2013 01:43:04 -0500 Subject: Fix target path and reuse mtime --- apps/files_sharing/lib/updater.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index af6f9215598..a41ce76f933 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -43,11 +43,11 @@ class Shared_Updater { } } // Correct folders of shared file owner + $target = substr($target, 8); if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) { - \OC\Files\Filesystem::initMountPoints($source['uid_owner']); - $source = '/'.$source['uid_owner'].'/'.$source['path']; - $mtime = \OC\Files\Filesystem::filemtime($target); - \OC\Files\Cache\Updater::correctFolder($source, $mtime); + \OC\Files\Filesystem::initMountPoints($uidOwner); + $source = '/'.$uidOwner.'/'.$source['path']; + \OC\Files\Cache\Updater::correctFolder($source, $info['mtime']); } } } -- cgit v1.2.3 From 9b4d7d99253885fadeed61b988c3c7528ca6d43a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 2 Mar 2013 12:57:29 -0500 Subject: Update ETag when file is shared --- apps/files_sharing/lib/sharedstorage.php | 1 + apps/files_sharing/lib/updater.php | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 19abc838258..f61a47c1900 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -420,6 +420,7 @@ class Shared extends \OC\Files\Storage\Common { \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Shared_Updater', 'writeHook'); \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook'); \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook'); + \OC_Hook::connect('OCP\Share', 'post_shared', '\OC\Files\Cache\Shared_Updater', 'shareHook'); } } diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index a41ce76f933..8d00d44c3b9 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -74,4 +74,14 @@ class Shared_Updater { self::correctFolders($params['path']); } + /** + * @param array $params + */ + static public function shareHook($params) { + if ($params['itemType'] === 'file' || $param['itemType'] === 'folder') { + $id = \OC\Files\Filesystem::getPath($params['itemSource']); + self::correctFolders($id); + } + } + } \ No newline at end of file -- cgit v1.2.3 From e466d680fea1738bfa5eeb12a13b6e8fa858a986 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 2 Mar 2013 13:11:57 -0500 Subject: Fix variable name in Shared_Updater --- apps/files_sharing/lib/updater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 8d00d44c3b9..cc04835b7d7 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -78,7 +78,7 @@ class Shared_Updater { * @param array $params */ static public function shareHook($params) { - if ($params['itemType'] === 'file' || $param['itemType'] === 'folder') { + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $id = \OC\Files\Filesystem::getPath($params['itemSource']); self::correctFolders($id); } -- cgit v1.2.3 From 812e306e6e1a10b879052bccaa6b94a6bb8bf9f4 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 6 Mar 2013 17:33:27 -0500 Subject: Update Shared folders ETags of users with reshares --- apps/files_sharing/lib/updater.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index cc04835b7d7..030180543c9 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -35,12 +35,18 @@ class Shared_Updater { // Correct Shared folders of other users shared with $users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true); if (!empty($users)) { - foreach ($users as $user) { - // The ETag of the logged in user should already be updated - if ($user !== $uid) { - $etag = \OC\Files\Filesystem::getETag(''); - \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + while (!empty($users)) { + $reshareUsers = array(); + foreach ($users as $user) { + // The ETag of the logged in user should already be updated + if ($user !== $uid) { + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + // Look for reshares + $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true)); + } } + $users = $reshareUsers; } // Correct folders of shared file owner $target = substr($target, 8); -- cgit v1.2.3 From 4cb5cb9693a2b5d13905079f2ba7c6300c26d9b2 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 7 Mar 2013 10:00:03 -0500 Subject: itemSource parameter should be fileSource --- apps/files_sharing/lib/updater.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 030180543c9..66f0d30c77b 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -85,9 +85,9 @@ class Shared_Updater { */ static public function shareHook($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - $id = \OC\Files\Filesystem::getPath($params['itemSource']); + $id = \OC\Files\Filesystem::getPath($params['fileSource']); self::correctFolders($id); } } -} \ No newline at end of file +} -- cgit v1.2.3 From 20828488bc99ceb22516367f8c6be02cb300a882 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 8 Mar 2013 10:59:22 -0500 Subject: Fix share hook for updater --- apps/files_sharing/lib/updater.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 66f0d30c77b..69219db8cb3 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -85,8 +85,20 @@ class Shared_Updater { */ static public function shareHook($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - $id = \OC\Files\Filesystem::getPath($params['fileSource']); - self::correctFolders($id); + $uidOwner = \OCP\User::getUser(); + $users = \OCP\Share::getUsersItemShared('file', $params['fileSource'], $uidOwner, true); + if (!empty($users)) { + while (!empty($users)) { + $reshareUsers = array(); + foreach ($users as $user) { + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + // Look for reshares + $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true)); + } + $users = $reshareUsers; + } + } } } -- cgit v1.2.3 From 02e2f7384eca440ce38cec98808cbd8aeb04e9c9 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 8 Mar 2013 17:32:04 +0100 Subject: not only files can be reshared but also folders --- apps/files_sharing/lib/updater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 69219db8cb3..861025c5933 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -86,7 +86,7 @@ class Shared_Updater { static public function shareHook($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $uidOwner = \OCP\User::getUser(); - $users = \OCP\Share::getUsersItemShared('file', $params['fileSource'], $uidOwner, true); + $users = \OCP\Share::getUsersItemShared($params['itemType'], $params['fileSource'], $uidOwner, true); if (!empty($users)) { while (!empty($users)) { $reshareUsers = array(); -- cgit v1.2.3 From e743386acffe6cb7de4b8d2dac5aeac70f1a74e0 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 8 Mar 2013 14:27:30 -0500 Subject: Fix correctFolders and retrieve the correct storage cache --- apps/files_sharing/lib/cache.php | 23 +++++++++++++---------- apps/files_sharing/lib/updater.php | 11 ++++------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 6f834e08999..9fccd0b46f3 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -42,16 +42,19 @@ class Shared_Cache extends 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']); - if ($storage) { - $this->files[$target] = $internalPath; - $cache = $storage->getCache(); - $this->storageId = $storage->getId(); - $this->numericId = $cache->getNumericStorageId(); - return $cache; + if (isset($source['path']) && isset($source['fileOwner'])) { + \OC\Files\Filesystem::initMountPoints($source['fileOwner']); + $mount = \OC\Files\Mount::findByNumericId($source['storage']); + if ($mount) { + $fullPath = $mount->getMountPoint().$source['path']; + list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath); + if ($storage) { + $this->files[$target] = $internalPath; + $cache = $storage->getCache(); + $this->storageId = $storage->getId(); + $this->numericId = $cache->getNumericStorageId(); + return $cache; + } } } return false; diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 861025c5933..73e7808f24a 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -38,13 +38,10 @@ class Shared_Updater { while (!empty($users)) { $reshareUsers = array(); foreach ($users as $user) { - // The ETag of the logged in user should already be updated - if ($user !== $uid) { - $etag = \OC\Files\Filesystem::getETag(''); - \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); - // Look for reshares - $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true)); - } + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + // Look for reshares + $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true)); } $users = $reshareUsers; } -- cgit v1.2.3 From 102120f105fd0f88349e3202024fca7c765e3587 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 20 Mar 2013 12:45:24 +0100 Subject: skip update if the recipient is the same user as the owner, otherwise we run in a infinite loop for group shares --- apps/files_sharing/lib/updater.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 73e7808f24a..221aaee5421 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -38,10 +38,12 @@ class Shared_Updater { while (!empty($users)) { $reshareUsers = array(); foreach ($users as $user) { - $etag = \OC\Files\Filesystem::getETag(''); + if ( $user !== $uidOwner ) { + $etag = \OC\Files\Filesystem::getETag(''); \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); // Look for reshares $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true)); + } } $users = $reshareUsers; } @@ -88,10 +90,12 @@ class Shared_Updater { while (!empty($users)) { $reshareUsers = array(); foreach ($users as $user) { - $etag = \OC\Files\Filesystem::getETag(''); - \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); - // Look for reshares - $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true)); + if ($user !== $uidOwner) { + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + // Look for reshares + $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true)); + } } $users = $reshareUsers; } -- cgit v1.2.3 From abd48496d2ea07adc47fd393167d0686de9b2245 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 20 Mar 2013 12:58:39 +0100 Subject: fix indention --- apps/files_sharing/lib/updater.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 221aaee5421..503aef68483 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -38,12 +38,12 @@ class Shared_Updater { while (!empty($users)) { $reshareUsers = array(); foreach ($users as $user) { - if ( $user !== $uidOwner ) { - $etag = \OC\Files\Filesystem::getETag(''); - \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); - // Look for reshares - $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true)); - } + if ( $user !== $uidOwner ) { + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + // Look for reshares + $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true)); + } } $users = $reshareUsers; } @@ -90,12 +90,12 @@ class Shared_Updater { while (!empty($users)) { $reshareUsers = array(); foreach ($users as $user) { - if ($user !== $uidOwner) { - $etag = \OC\Files\Filesystem::getETag(''); - \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); - // Look for reshares - $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true)); - } + if ($user !== $uidOwner) { + $etag = \OC\Files\Filesystem::getETag(''); + \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); + // Look for reshares + $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true)); + } } $users = $reshareUsers; } -- cgit v1.2.3 From c2a49b5c1f7c06497da9285b82775914b0445ddb Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Mar 2013 16:20:40 +0100 Subject: the old path no longer exists after rename, update the parent folder instead --- apps/files_sharing/lib/updater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/updater.php') diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 503aef68483..a43ab2e2a0a 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -68,8 +68,8 @@ class Shared_Updater { * @param array $params */ static public function renameHook($params) { - self::correctFolders($params['oldpath']); self::correctFolders($params['newpath']); + self::correctFolders(pathinfo($params['oldpath'], PATHINFO_DIRNAME)); } /** -- cgit v1.2.3