fix etag propagation
This commit is contained in:
parent
aae22b2d6a
commit
b712393e72
|
@ -17,6 +17,4 @@ OCP\Util::addScript('files_sharing', 'share');
|
||||||
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook');
|
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook');
|
||||||
\OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook');
|
\OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook');
|
||||||
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook');
|
\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');
|
|
||||||
\OC_Hook::connect('OCP\Share', 'pre_unshare', '\OC\Files\Cache\Shared_Updater', 'shareHook');
|
|
||||||
\OC_Hook::connect('OC_Appconfig', 'post_set_value', '\OCA\Files\Share\Maintainer', 'configChangeHook');
|
\OC_Hook::connect('OC_Appconfig', 'post_set_value', '\OCA\Files\Share\Maintainer', 'configChangeHook');
|
||||||
|
|
|
@ -111,4 +111,39 @@ class Helper {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getSharesFromItem($target) {
|
||||||
|
$result = array();
|
||||||
|
$owner = \OC\Files\Filesystem::getOwner($target);
|
||||||
|
\OC\Files\Filesystem::initMountPoints($owner);
|
||||||
|
$info = \OC\Files\Filesystem::getFileInfo($target);
|
||||||
|
$ownerView = new \OC\Files\View('/'.$owner.'/files');
|
||||||
|
if ( $owner != \OCP\User::getUser() ) {
|
||||||
|
$path = $ownerView->getPath($info['fileid']);
|
||||||
|
} else {
|
||||||
|
$path = $target;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$ids = array();
|
||||||
|
while ($path !== '' && $path !== '.' && $path !== '/') {
|
||||||
|
$info = $ownerView->getFileInfo($path);
|
||||||
|
$ids[] = $info['fileid'];
|
||||||
|
$path = dirname($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($ids)) {
|
||||||
|
|
||||||
|
$idList = array_chunk($ids, 99, true);
|
||||||
|
|
||||||
|
foreach ($idList as $subList) {
|
||||||
|
$statement = "SELECT `share_with`, `share_type`, `file_target` FROM `*PREFIX*share` WHERE `file_source` IN (" . implode(',', $subList) . ") AND `share_type` IN (0, 1, 2)";
|
||||||
|
$query = \OCP\DB::prepare($statement);
|
||||||
|
$r = $query->execute();
|
||||||
|
$result = array_merge($result, $r->fetchAll());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,31 +26,48 @@ class Shared_Updater {
|
||||||
// shares which can be removed from oc_share after the delete operation was successful
|
// shares which can be removed from oc_share after the delete operation was successful
|
||||||
static private $toRemove = array();
|
static private $toRemove = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief walk up the users file tree and update the etags
|
||||||
|
* @param string $user
|
||||||
|
* @param string $path
|
||||||
|
*/
|
||||||
|
static private function correctUsersFolder($user, $path) {
|
||||||
|
// $path points to the mount point which is a virtual folder, so we start with
|
||||||
|
// the parent
|
||||||
|
$path = '/files' . dirname($path);
|
||||||
|
\OC\Files\Filesystem::initMountPoints($user);
|
||||||
|
$view = new \OC\Files\View('/' . $user);
|
||||||
|
if ($view->file_exists($path)) {
|
||||||
|
while ($path !== '/') {
|
||||||
|
$etag = $view->getETag($path);
|
||||||
|
$view->putFileInfo($path, array('etag' => $etag));
|
||||||
|
$path = dirname($path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log("error!" . 'can not update etags on ' . $path . ' for user ' . $user);
|
||||||
|
\OCP\Util::writeLog('files_sharing', 'can not update etags on ' . $path . ' for user ' . $user, \OCP\Util::ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Correct the parent folders' ETags for all users shared the file at $target
|
* Correct the parent folders' ETags for all users shared the file at $target
|
||||||
*
|
*
|
||||||
* @param string $target
|
* @param string $target
|
||||||
*/
|
*/
|
||||||
static public function correctFolders($target) {
|
static public function correctFolders($target) {
|
||||||
$uid = \OCP\User::getUser();
|
|
||||||
$uidOwner = \OC\Files\Filesystem::getOwner($target);
|
|
||||||
$info = \OC\Files\Filesystem::getFileInfo($target);
|
|
||||||
$checkedUser = array($uidOwner);
|
|
||||||
// Correct Shared folders of other users shared with
|
// Correct Shared folders of other users shared with
|
||||||
$users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true);
|
$shares = \OCA\Files_Sharing\Helper::getSharesFromItem($target);
|
||||||
if (!empty($users)) {
|
|
||||||
while (!empty($users)) {
|
foreach ($shares as $share) {
|
||||||
$reshareUsers = array();
|
if ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_USER) {
|
||||||
|
self::correctUsersFolder($share['share_with'], $share['file_target']);
|
||||||
|
} elseif ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
|
||||||
|
$users = \OC_Group::usersInGroup($share['share_with']);
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
if ( !in_array($user, $checkedUser) ) {
|
self::correctUsersFolder($user, $share['file_target']);
|
||||||
$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));
|
|
||||||
$checkedUser[] = $user;
|
|
||||||
}
|
}
|
||||||
}
|
} else { //unique name for group share
|
||||||
$users = $reshareUsers;
|
self::correctUsersFolder($share['share_with'], $share['file_target']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,34 +124,6 @@ class Shared_Updater {
|
||||||
self::removeShare($params['path']);
|
self::removeShare($params['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $params
|
|
||||||
*/
|
|
||||||
static public function shareHook($params) {
|
|
||||||
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
|
||||||
if (isset($params['uidOwner'])) {
|
|
||||||
$uidOwner = $params['uidOwner'];
|
|
||||||
} else {
|
|
||||||
$uidOwner = \OCP\User::getUser();
|
|
||||||
}
|
|
||||||
$users = \OCP\Share::getUsersItemShared($params['itemType'], $params['fileSource'], $uidOwner, true, false);
|
|
||||||
if (!empty($users)) {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$users = $reshareUsers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clean up oc_share table from files which are no longer exists
|
* clean up oc_share table from files which are no longer exists
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue