Filter out files you unshare from yourself in opendir()

This commit is contained in:
Michael Gapczynski 2011-07-23 14:41:01 -04:00
parent e6e673d7c0
commit 4993fb4665
2 changed files with 22 additions and 13 deletions

View File

@ -108,20 +108,21 @@ class OC_SHARE {
/** /**
* Get the items within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself * Get the items within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself
* *
* Also can be used for getting all items shared with you e.g. pass '/MTGap/files' * Works for both target and source folders. Can be used for getting all items shared with you e.g. pass '/MTGap/files'
* *
* @param $targetFolder The target folder of the items to look for * @param $folder The folder of the items to look for
* @return An array with all items in the database that are in the target folder * @return An array with all items in the database that are in the folder
*/ */
public static function getItemsInFolder($targetFolder) { public static function getItemsInFolder($folder) {
// Append '/' in order to filter out the folder itself if not already there // Append '/' in order to filter out the folder itself if not already there
if (substr($targetFolder, -1) !== "/") { if (substr($folder, -1) !== "/") {
$targetFolder .= "/"; $folder .= "/";
} }
// Remove any duplicate '/' // Remove any duplicate '/'
$targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder); $folder = preg_replace('{(/)\1+}', "/", $folder);
$query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ?"); $length = strlen($folder);
return $query->execute(array(strlen($targetFolder), $targetFolder, OC_USER::getUser()))->fetchAll(); $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with = ?");
return $query->execute(array($length, $folder, $length, $folder, OC_USER::getUser()))->fetchAll();
} }
/** /**
@ -133,13 +134,13 @@ class OC_SHARE {
// Remove any duplicate or trailing '/' // Remove any duplicate or trailing '/'
$target = rtrim($target, "/"); $target = rtrim($target, "/");
$target = preg_replace('{(/)\1+}', "/", $target); $target = preg_replace('{(/)\1+}', "/", $target);
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ? LIMIT 1"); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1");
// Prevent searching for user directory e.g. '/MTGap/files' // Prevent searching for user directory e.g. '/MTGap/files'
$userDirectory = substr($target, 0, strpos($target, "files") + 5); $userDirectory = substr($target, 0, strpos($target, "files") + 5);
while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) {
// Check if the parent directory of this target location is shared // Check if the parent directory of this target location is shared
$target = dirname($target); $target = dirname($target);
$result = $query->execute(array(strlen($target), $target, OC_USER::getUser()))->fetchAll(); $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll();
if (count($result) > 0) { if (count($result) > 0) {
break; break;
} }

View File

@ -93,7 +93,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
// Remove any duplicate or trailing '/' // Remove any duplicate or trailing '/'
$path = rtrim($this->datadir.$path, "/"); $path = rtrim($this->datadir.$path, "/");
$path = preg_replace('{(/)\1+}', "/", $path); $path = preg_replace('{(/)\1+}', "/", $path);
$modifiedItems = OC_SHARE::getItemsInFolder($path); $modifiedItems = OC_SHARE::getItemsInFolder($source);
if ($modifiedItems && $dh) { if ($modifiedItems && $dh) {
global $FAKEDIRS; global $FAKEDIRS;
$sources = array(); $sources = array();
@ -103,6 +103,10 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
if (dirname($item['target']) == $path && basename($item['source']) != basename($item['target'])) { if (dirname($item['target']) == $path && basename($item['source']) != basename($item['target'])) {
$sources[] = basename($item['source']); $sources[] = basename($item['source']);
$targets[] = basename($item['target']); $targets[] = basename($item['target']);
// If the item was unshared from self, add it it to the arrays
} elseif ($item['target'] == "/") {
$sources[] = basename($item['source']);
$targets[] = "";
} }
} }
// Don't waste time if there aren't any modified items in the current directory // Don't waste time if there aren't any modified items in the current directory
@ -116,7 +120,11 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
$files[] = $filename; $files[] = $filename;
// The file has a different name than the source and is added to the fakedirs // The file has a different name than the source and is added to the fakedirs
} else { } else {
$files[] = $targets[array_search($filename, $sources)]; $target = $targets[array_search($filename, $sources)];
// Don't add the file if it was unshared from self by the user
if ($target != "") {
$files[] = $target;
}
} }
} }
} }