[Pkg-owncloud-commits] [owncloud] 38/74: Fix mapping of relative paths
David Prévot
taffit at moszumanska.debian.org
Tue Dec 2 22:04:36 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit f235e8b80345ee68ec6d56f12df2a8e77b6da7e0
Author: Lukas Reschke <lukas at owncloud.com>
Date: Wed Sep 17 11:36:08 2014 +0200
Fix mapping of relative paths
---
lib/private/files/mapper.php | 44 ++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/lib/private/files/mapper.php b/lib/private/files/mapper.php
index 94dda80..5e78ef0 100644
--- a/lib/private/files/mapper.php
+++ b/lib/private/files/mapper.php
@@ -66,8 +66,8 @@ class Mapper
*/
public function copy($path1, $path2)
{
- $path1 = $this->stripLast($path1);
- $path2 = $this->stripLast($path2);
+ $path1 = $this->resolveRelativePath($path1);
+ $path2 = $this->resolveRelativePath($path2);
$physicPath1 = $this->logicToPhysical($path1, true);
$physicPath2 = $this->logicToPhysical($path2, true);
@@ -113,18 +113,11 @@ class Mapper
return '';
}
- private function stripLast($path) {
- if (substr($path, -1) == '/') {
- $path = substr_replace($path, '', -1);
- }
- return $path;
- }
-
/**
* @param string $logicPath
*/
private function resolveLogicPath($logicPath) {
- $logicPath = $this->stripLast($logicPath);
+ $logicPath = $this->resolveRelativePath($logicPath);
$sql = 'SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?';
$result = \OC_DB::executeAudited($sql, array(md5($logicPath)));
$result = $result->fetchRow();
@@ -136,7 +129,7 @@ class Mapper
}
private function resolvePhysicalPath($physicalPath) {
- $physicalPath = $this->stripLast($physicalPath);
+ $physicalPath = $this->resolveRelativePath($physicalPath);
$sql = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
$result = \OC_DB::executeAudited($sql, array(md5($physicalPath)));
$result = $result->fetchRow();
@@ -144,12 +137,35 @@ class Mapper
return $result['logic_path'];
}
+ private function resolveRelativePath($path) {
+ $explodedPath = explode('/', $path);
+ $pathArray = array();
+ foreach ($explodedPath as $pathElement) {
+ if (empty($pathElement) || ($pathElement == '.')) {
+ continue;
+ } elseif ($pathElement == '..') {
+ if (count($pathArray) == 0) {
+ return false;
+ }
+ array_pop($pathArray);
+ } else {
+ array_push($pathArray, $pathElement);
+ }
+ }
+ if (substr($path, 0, 1) == '/') {
+ $path = '/';
+ } else {
+ $path = '';
+ }
+ return $path.implode('/', $pathArray);
+ }
+
/**
* @param string $logicPath
* @param boolean $store
*/
private function create($logicPath, $store) {
- $logicPath = $this->stripLast($logicPath);
+ $logicPath = $this->resolveRelativePath($logicPath);
$index = 0;
// create the slugified path
@@ -205,8 +221,8 @@ class Mapper
}
}
- $sluggedPath = $this->unchangedPhysicalRoot . implode('/', $sluggedElements);
- return $this->stripLast($sluggedPath);
+ $sluggedPath = $this->unchangedPhysicalRoot.implode('/', $sluggedElements);
+ return $this->resolveRelativePath($sluggedPath);
}
/**
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list