Still trying to fix some sharing use cases

This commit is contained in:
Michael Gapczynski 2012-05-09 13:51:24 -04:00
parent a589a700e1
commit 14b240a3f4
2 changed files with 23 additions and 10 deletions

View file

@ -76,7 +76,7 @@ class OC_Share {
throw new Exception("This item is already shared with ".$uid); throw new Exception("This item is already shared with ".$uid);
} }
// Check if the target already exists for the user, if it does append a number to the name // Check if the target already exists for the user, if it does append a number to the name
$sharedFolder = "/".$uid."/files/Shared"; $sharedFolder = '/'.$uid.'/files/Shared';
$target = $sharedFolder."/".basename($source); $target = $sharedFolder."/".basename($source);
if (self::getSource($target)) { if (self::getSource($target)) {
if ($pos = strrpos($target, ".")) { if ($pos = strrpos($target, ".")) {
@ -98,8 +98,14 @@ class OC_Share {
$uid = $uid."@".$gid; $uid = $uid."@".$gid;
} }
$query->execute(array($uid_owner, $uid, $source, $target, $permissions)); $query->execute(array($uid_owner, $uid, $source, $target, $permissions));
// Update mtime of shared folder to invoke a file cache rescan // Emit post_write hook to invoke a file cache rescan
OC_Filesystem::getStorage($sharedFolder)->touch($sharedFolder); $storage = OC_Filesystem::getStorage($sharedFolder);
if (!$storage->is_dir($sharedFolder)) {
$storage->mkdir($sharedFolder);
OCP\Util::emitHook('OC_Filesystem', 'post_write', array('path' => $sharedFolder));
} else {
OCP\Util::emitHook('OC_Filesystem', 'post_write', array('path' => $target));
}
} }
} }
} }
@ -374,12 +380,22 @@ class OC_Share {
*/ */
public static function unshare($source, $uid_shared_with) { public static function unshare($source, $uid_shared_with) {
$source = self::cleanPath($source); $source = self::cleanPath($source);
$uid_owner = OCP\USER::getUser();
$query = OCP\DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query = OCP\DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with));
$query->execute(array(strlen($source), $source, OCP\USER::getUser())); $query->execute(array(strlen($source), $source, $uid_owner));
// Update mtime of shared folder to invoke a file cache rescan
if ($uid_shared_with != self::PUBLICLINK) { if ($uid_shared_with != self::PUBLICLINK) {
$sharedFolder = '/'.$uid_shared_with.'/files/Shared'; if (OC_Group::groupExists($uid_shared_with)) {
OC_Filesystem::getStorage($sharedFolder)->touch($sharedFolder); $uid_shared_with = OC_Group::usersInGroup($uid_shared_with);
// Remove the owner from the list of users in the group
$uid_shared_with = array_diff($uid_shared_with, array($uid_owner));
} else {
$uid_shared_with = array($uid_shared_with);
}
foreach ($uid_shared_with as $uid) {
$sharedFolder = '/'.$uid.'/files/'.'Shared';
// Emit post_write hook to invoke a file cache rescan
OCP\Util::emitHook('OC_Filesystem', 'post_write', array('path' => $sharedFolder));
}
} }
} }

View file

@ -22,9 +22,6 @@
require_once( 'lib_share.php' ); require_once( 'lib_share.php' );
if (OC_Filesystem::$loaded and !OC_Filesystem::is_dir('/Shared')) {
OC_Filesystem::mkdir('/Shared');
}
OC_Filesystem::mount('OC_Filestorage_Shared',array('datadir'=>'/'.OCP\USER::getUser().'/files/Shared'),'/'.OCP\USER::getUser().'/files/Shared/'); OC_Filesystem::mount('OC_Filestorage_Shared',array('datadir'=>'/'.OCP\USER::getUser().'/files/Shared'),'/'.OCP\USER::getUser().'/files/Shared/');
/** /**