aboutsummaryrefslogtreecommitdiffstats
path: root/lib/files/cache/cache.php
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-06-12 20:53:45 +0200
committerBjörn Schießle <schiessle@owncloud.com>2013-06-12 20:53:45 +0200
commit27fcdb3af5d1b1012695a09e04c0a654a1dde710 (patch)
tree6de492454c862852de3f51bd8834e2012139b5ac /lib/files/cache/cache.php
parent46e5e9bd73a68f7b50bb79f883a8bc6efacaca97 (diff)
parent3584d48d65900b15dc3ef6831926f4a52e508625 (diff)
downloadnextcloud-server-27fcdb3af5d1b1012695a09e04c0a654a1dde710.tar.gz
nextcloud-server-27fcdb3af5d1b1012695a09e04c0a654a1dde710.zip
Merge branch 'master' into files_encryption_upgrade_fix
Conflicts: apps/files_encryption/tests/crypt.php
Diffstat (limited to 'lib/files/cache/cache.php')
-rw-r--r--lib/files/cache/cache.php55
1 files changed, 51 insertions, 4 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 0210d5a73f1..5b2fcfaadf9 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -96,10 +96,13 @@ class Cache {
* get the stored metadata of a file or folder
*
* @param string/int $file
- * @return array
+ * @return array | false
*/
public function get($file) {
if (is_string($file) or $file == '') {
+ // normalize file
+ $file = $this->normalize($file);
+
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
$params = array($this->getNumericStorageId(), md5($file));
} else { //file id
@@ -112,6 +115,12 @@ class Cache {
$result = $query->execute($params);
$data = $result->fetchRow();
+ //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
+ //PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
+ if ($data === null) {
+ $data = false;
+ }
+
//merge partial data
if (!$data and is_string($file)) {
if (isset($this->partial[$file])) {
@@ -179,6 +188,9 @@ class Cache {
$this->update($id, $data);
return $id;
} else {
+ // normalize file
+ $file = $this->normalize($file);
+
if (isset($this->partial[$file])) { //add any saved partial data
$data = array_merge($this->partial[$file], $data);
unset($this->partial[$file]);
@@ -220,11 +232,22 @@ class Cache {
* @param array $data
*/
public function update($id, array $data) {
+
+ if(isset($data['path'])) {
+ // normalize path
+ $data['path'] = $this->normalize($data['path']);
+ }
+
+ if(isset($data['name'])) {
+ // normalize path
+ $data['name'] = $this->normalize($data['name']);
+ }
+
list($queryParts, $params) = $this->buildParts($data);
$params[] = $id;
$query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=?'
- . ' WHERE fileid = ?');
+ . ' WHERE `fileid` = ?');
$query->execute($params);
}
@@ -267,6 +290,9 @@ class Cache {
* @return int
*/
public function getId($file) {
+ // normalize file
+ $file = $this->normalize($file);
+
$pathHash = md5($file);
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
@@ -334,6 +360,10 @@ class Cache {
* @param string $target
*/
public function move($source, $target) {
+ // normalize source and target
+ $source = $this->normalize($source);
+ $target = $this->normalize($target);
+
$sourceData = $this->get($source);
$sourceId = $sourceData['fileid'];
$newParentId = $this->getParentId($target);
@@ -361,10 +391,10 @@ class Cache {
* remove all entries for files that are stored on the storage from the cache
*/
public function clear() {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?');
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?');
$query->execute(array($this->getNumericStorageId()));
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?');
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE `id` = ?');
$query->execute(array($this->storageId));
}
@@ -374,6 +404,9 @@ class Cache {
* @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
*/
public function getStatus($file) {
+ // normalize file
+ $file = $this->normalize($file);
+
$pathHash = md5($file);
$query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
$result = $query->execute(array($this->getNumericStorageId(), $pathHash));
@@ -402,6 +435,10 @@ class Cache {
* @return array of file data
*/
public function search($pattern) {
+
+ // normalize pattern
+ $pattern = $this->normalize($pattern);
+
$query = \OC_DB::prepare('
SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?'
@@ -551,4 +588,14 @@ class Cache {
return null;
}
}
+
+ /**
+ * normalize the given path
+ * @param $path
+ * @return string
+ */
+ public function normalize($path) {
+
+ return \OC_Util::normalizeUnicode($path);
+ }
}