diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index cc471f278d..53f3fb3c90 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -53,7 +53,7 @@ class OC_SHARE { * Change is writeable for the specified item and user * @param $source * @param $uid_shared_with - * @param $is_writeable + * @param $is_writeable */ public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); @@ -68,7 +68,7 @@ class OC_SHARE { /** * Check if the specified item is writeable for the user - * @param $target + * @param $target * @return true or false */ public static function isWriteable($target) { @@ -82,7 +82,7 @@ class OC_SHARE { if (count($result) > 0) { return $result[0]['is_writeable']; } else { - return false; + return false; } } } @@ -91,17 +91,26 @@ class OC_SHARE { * Unshare the item, removes it from all users specified * @param array $uid_shared_with */ - public static function unshare($item, $uid_shared_with) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); + public static function unshare($source, $uid_shared_with) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($item, $uid, $_SESSION['user_id'])); + $query->execute(array($source, $uid, $_SESSION['user_id'])); } } + /** + * Unshare the item from the current user - used when the user deletes the item + * @param $target + */ + public static function unshareFromSelf($target) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); + $query->execute(array($target, $_SESSION['user_id'])); + } + /** * Set the source location to a new value * @param $oldSource The current source location - * @param $newTarget The new source location + * @param $newTarget The new source location */ public static function setSource($oldSource, $newSource) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3d1a5c8391..1f651a1b10 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -27,7 +27,7 @@ OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datad /** * Convert target path to source path and pass the function call to the correct storage provider */ -class OC_FILESTORAGE_SHARED { +class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { private $sourcePaths = array(); @@ -320,17 +320,16 @@ class OC_FILESTORAGE_SHARED { } } - // TODO OC_SHARE::getPermissions() public function unlink($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->unlink($this->getInternalPath($source)); - } + // The file will be removed from the database, but won't be deleted from the owner's filesystem + $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; + OC_SHARE::unshareFromSelf($target); } public function rename($path1, $path2) { - OC_SHARE::setTarget($path1, $path2); + $oldTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path1; + $newTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path2; + OC_SHARE::setTarget($oldTarget, $newTarget); } public function copy($path1, $path2) {