getUidAndFilename() always get uid from path

This commit is contained in:
Bjoern Schiessle 2015-04-01 14:24:42 +02:00 committed by Thomas Müller
parent cac83642f2
commit 51302d5812
1 changed files with 6 additions and 46 deletions

View File

@ -226,7 +226,7 @@ class Util {
}
/**
* get the owner and the path for the owner
* get the owner and the path for the file relative to the owners files folder
*
* @param string $path
* @return array
@ -240,57 +240,17 @@ class Util {
$uid = $parts[1];
}
if (!$this->userManager->userExists($uid)) {
throw new \BadMethodCallException('path needs to be relative to the system wide data folder and point to a user specific file');
}
$pathInfo = pathinfo($path);
$partFile = false;
$parentFolder = false;
if (array_key_exists('extension', $pathInfo) && $pathInfo['extension'] === 'part') {
// if the real file exists we check this file
$filePath = $pathInfo['dirname'] . '/' . $pathInfo['filename'];
if ($this->view->file_exists($filePath)) {
$pathToCheck = $pathInfo['dirname'] . '/' . $pathInfo['filename'];
} else { // otherwise we look for the parent
$pathToCheck = $pathInfo['dirname'];
$parentFolder = true;
}
$partFile = true;
} else {
$pathToCheck = $path;
}
$pathToCheck = substr($pathToCheck, strlen('/' . $uid));
$this->view->chroot('/' . $uid);
$owner = $this->view->getOwner($pathToCheck);
// Check that UID is valid
if (!$this->userManager->userExists($owner)) {
throw new \BadMethodCallException('path needs to be relative to the system wide data folder and point to a user specific file');
}
\OC\Files\Filesystem::initMountPoints($owner);
$info = $this->view->getFileInfo($pathToCheck);
$this->view->chroot('/' . $owner);
$ownerPath = $this->view->getPath($info->getId());
$this->view->chroot('/');
if ($parentFolder) {
$ownerPath = $ownerPath . '/'. $pathInfo['filename'];
}
if ($partFile) {
$ownerPath = $ownerPath . '.' . $pathInfo['extension'];
}
return array(
$owner,
\OC\Files\Filesystem::normalizePath($ownerPath)
throw new \BadMethodCallException(
'path needs to be relative to the system wide data folder and point to a user specific file'
);
}
$ownerPath = implode('/', array_slice($parts, 2));
return array($uid, \OC\Files\Filesystem::normalizePath($ownerPath));
}
/**
* Remove .path extension from a file path
* @param string $path Path that may identify a .part file