Fix bugs in getSource() and implement new target path standard

This commit is contained in:
Michael Gapczynski 2011-07-05 11:56:02 -04:00
parent 607f1a2738
commit 9deab8302f
3 changed files with 18 additions and 15 deletions

View File

@ -82,6 +82,8 @@ class OC_SHARE {
* @return source path
*/
public static function getSource($target) {
// Remove any trailing '/'
$target = rtrim($target, "/");
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1");
$result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll();
if (count($result) > 0) {
@ -89,7 +91,7 @@ class OC_SHARE {
} else {
// Check if the parent directory of this target is shared
$parentDir = dirname($target);
if ($parentDir != ".") {
if ($parentDir != "" && $parentDir != "/" && $parentDir != ".") {
$result = OC_SHARE::getSource($parentDir);
if ($result) {
return $result."/".basename($target);

View File

@ -43,22 +43,13 @@ class OC_FILESTORAGE_SHARED {
}
public function getSource($target) {
if ($target == "") {
return false;
} elseif (array_key_exists($target, $this->sourcePaths)) {
$target = OC_FILESYSTEM::getStorageMountPoint($this).$target;
if (array_key_exists($target, $this->sourcePaths)) {
return $this->sourcePaths[$target];
} else {
$parentDir = dirname($target);
if ($parentDir != ".") {
$source = $this->getSource($parentDir);
return $source."/".basename($target);
} else {
$source = OC_SHARE::getSource($target);
if ($source) {
$this->sourcePaths[$target] = $source;
}
return $source;
}
$source = OC_SHARE::getSource($target);
$this->sourcePaths[$target] = $source;
return $source;
}
}

View File

@ -214,6 +214,16 @@ class OC_FILESYSTEM{
}
return $foundMountPoint;
}
/**
* get the mountpoint of the storage object
* @param OC_FILESTORAGE storage
* @return string
*/
static public function getStorageMountPoint($storage){
return array_search($storage, self::$storages);
}
/**
* return the path to a local version of the file
* we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed