summaryrefslogtreecommitdiffstats
path: root/lib/files
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2013-02-10 19:10:06 -0500
committerMichael Gapczynski <mtgap@owncloud.com>2013-02-10 19:10:06 -0500
commiteeb409a6ec0f5f682ed4893320d70a3a5e3a1483 (patch)
tree1aebaf98634e98eaed238206e336e9f56db3e193 /lib/files
parent8e3b8c7f47ab12e1612d3fa025e6b9eb7f5ffdb3 (diff)
parent04146f2059e2d038177db544ea9f37a124f0781e (diff)
downloadnextcloud-server-eeb409a6ec0f5f682ed4893320d70a3a5e3a1483.tar.gz
nextcloud-server-eeb409a6ec0f5f682ed4893320d70a3a5e3a1483.zip
Merge branch 'master' into fix-shared-links
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/cache/scanner.php18
-rw-r--r--lib/files/mapper.php12
-rw-r--r--lib/files/storage/common.php23
3 files changed, 46 insertions, 7 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 9a5546dce3f..5a9a119458e 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -97,7 +97,7 @@ class Scanner {
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
- if ($file !== '.' and $file !== '..') {
+ if (!$this->isIgnoredFile($file)) {
$child = ($path) ? $path . '/' . $file : $file;
$data = $this->scanFile($child);
if ($data) {
@@ -133,6 +133,22 @@ class Scanner {
}
return $size;
}
+
+ /**
+ * @brief check if the file should be ignored when scanning
+ * NOTE: files with a '.part' extension are ignored as well!
+ * prevents unfinished put requests to be scanned
+ * @param String $file
+ * @return boolean
+ */
+ private function isIgnoredFile($file) {
+ if ($file === '.' || $file === '..'
+ || pathinfo($file,PATHINFO_EXTENSION) === 'part')
+ {
+ return true;
+ }
+ return false;
+ }
/**
* walk over any folders that are not fully scanned yet and scan them
diff --git a/lib/files/mapper.php b/lib/files/mapper.php
index 90e4e1ca669..71b665e49bb 100644
--- a/lib/files/mapper.php
+++ b/lib/files/mapper.php
@@ -114,8 +114,8 @@ class Mapper
private function resolveLogicPath($logicPath) {
$logicPath = $this->stripLast($logicPath);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` = ?');
- $result = $query->execute(array($logicPath));
+ $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?');
+ $result = $query->execute(array(md5($logicPath)));
$result = $result->fetchRow();
return $result['physic_path'];
@@ -123,8 +123,8 @@ class Mapper
private function resolvePhysicalPath($physicalPath) {
$physicalPath = $this->stripLast($physicalPath);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path` = ?');
- $result = $query->execute(array($physicalPath));
+ $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
+ $result = $query->execute(array(md5($physicalPath)));
$result = $result->fetchRow();
return $result['logic_path'];
@@ -151,8 +151,8 @@ class Mapper
}
private function insert($logicPath, $physicalPath) {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`,`physic_path`) VALUES(?,?)');
- $query->execute(array($logicPath, $physicalPath));
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`) VALUES(?, ?, ?, ?)');
+ $query->execute(array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath)));
}
private function slugifyPath($path, $index=null) {
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index 591803f0440..ce9e7ead6d1 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -277,4 +277,27 @@ abstract class Common implements \OC\Files\Storage\Storage {
return uniqid();
}
}
+
+ /**
+ * clean a path, i.e. remove all redundant '.' and '..'
+ * making sure that it can't point to higher than '/'
+ * @param $path The path to clean
+ * @return string cleaned path
+ */
+ public function cleanPath($path) {
+ if (strlen($path) == 0 or $path[0] != '/') {
+ $path = '/' . $path;
+ }
+
+ $output = array();
+ foreach (explode('/', $path) as $chunk) {
+ if ($chunk == '..') {
+ array_pop($output);
+ } else if ($chunk == '.') {
+ } else {
+ $output[] = $chunk;
+ }
+ }
+ return implode('/', $output);
+ }
}