Fix bugs in unlink(), rename(), pullOutOfFolders(), and getItemsInFolder()

This commit is contained in:
Michael Gapczynski 2011-07-16 13:06:59 -04:00
parent 8ed0223bd6
commit 8ad4a44171
2 changed files with 13 additions and 5 deletions

View File

@ -59,7 +59,7 @@ class OC_SHARE {
*/
public static function pullOutOfFolder($oldTarget, $newTarget) {
$folders = self::getParentFolders($oldTarget);
$source = $folders['source'].substr($target, strlen($folders['target']));
$source = $folders['source'].substr($oldTarget, strlen($folders['target']));
$item = self::getItem($folders['target']);
$query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
$query->execute(array($item[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $item[0]['is_writeable']));
@ -97,6 +97,8 @@ class OC_SHARE {
if (substr($targetFolder, -1) !== "/") {
$targetFolder .= "/";
}
// Remove any duplicate '/'
$targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder);
$query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?");
return $query->execute(array($targetFolder."%", $_SESSION['user_id']))->fetchAll();
}

View File

@ -348,10 +348,16 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
public function unlink($path) {
// The file will be removed from the database, but won't be touched on the owner's filesystem
$target = $this->datadir.$path;
if (OC_SHARE::getItem($target)) {
OC_SHARE::unshareFromMySelf($target);
// If file is inside a shared folder
if (OC_SHARE::getParentFolders($target)) {
// If entry for file already exists
if (OC_SHARE::getItem($target)) {
OC_SHARE::setTarget($target, "/");
} else {
OC_SHARE::pullOutOfFolder($target, "/");
}
} else {
OC_SHARE::pullOutOfFolder($target, "");
OC_SHARE::unshareFromMySelf($target);
}
}
@ -359,7 +365,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
// The file will be renamed in the database, but won't be touched on the owner's filesystem
$oldTarget = $this->datadir.$path1;
$newTarget = $this->datadir.$path2;
if (dirname($path1) == dirname($path2)) {
if (OC_SHARE::getItem($oldTarget)) {
OC_SHARE::setTarget($oldTarget, $newTarget);
} else {
OC_SHARE::pullOutOfFolder($oldTarget, $newTarget);