aboutsummaryrefslogtreecommitdiffstats
path: root/lib/files/cache
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-02-15 21:04:48 +0100
committerRobin Appelman <icewind@owncloud.com>2013-02-15 21:04:48 +0100
commit2ed850e05b46d820528813c2f2415dad60c1c570 (patch)
treea46c29c4fd7c01f71261499c7a33996a23830fc5 /lib/files/cache
parent9738fae3cf1ad18593d21eb62e138e00c01f5f36 (diff)
parent425d41aaf93e1cd3a44ddc794414683e8e2c4648 (diff)
downloadnextcloud-server-2ed850e05b46d820528813c2f2415dad60c1c570.tar.gz
nextcloud-server-2ed850e05b46d820528813c2f2415dad60c1c570.zip
merge master into filecache_mtime
Diffstat (limited to 'lib/files/cache')
-rw-r--r--lib/files/cache/cache.php14
-rw-r--r--lib/files/cache/legacy.php6
-rw-r--r--lib/files/cache/permissions.php11
-rw-r--r--lib/files/cache/scanner.php43
-rw-r--r--lib/files/cache/upgrade.php3
5 files changed, 57 insertions, 20 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index d696f003c57..65f33c5f797 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -56,7 +56,7 @@ class Cache {
} else {
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)');
$query->execute(array($this->storageId));
- $this->numericId = \OC_DB::insertid('*PREFIX*filecache');
+ $this->numericId = \OC_DB::insertid('*PREFIX*storages');
}
}
@@ -204,7 +204,8 @@ class Cache {
$params[] = $this->numericId;
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ') VALUES(' . implode(', ', $valuesPlaceholder) . ')');
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')'
+ .' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
$query->execute($params);
return (int)\OC_DB::insertid('*PREFIX*filecache');
@@ -221,7 +222,8 @@ class Cache {
list($queryParts, $params) = $this->buildParts($data);
$params[] = $id;
- $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? WHERE fileid = ?');
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=?'
+ .' WHERE fileid = ?');
$query->execute($params);
}
@@ -343,7 +345,8 @@ class Cache {
$query->execute(array($targetPath, md5($targetPath), $child['fileid']));
}
- $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `parent` =? WHERE `fileid` = ?');
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `parent` =?'
+ .' WHERE `fileid` = ?');
$query->execute(array($target, md5($target), $newParentId, $sourceId));
}
@@ -503,7 +506,8 @@ class Cache {
* @return string|bool the path of the folder or false when no folder matched
*/
public function getIncomplete() {
- $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1');
+ $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`'
+ .' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1');
$query->execute(array($this->numericId));
if ($row = $query->fetchRow()) {
return $row['path'];
diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php
index 33d4b8e7c9f..6d1ffa7b40b 100644
--- a/lib/files/cache/legacy.php
+++ b/lib/files/cache/legacy.php
@@ -51,6 +51,12 @@ class Legacy {
$this->cacheHasItems = false;
return false;
}
+
+ if ($result === false || property_exists($result, 'error_message_prefix')) {
+ $this->cacheHasItems = false;
+ return false;
+ }
+
$this->cacheHasItems = (bool)$result->fetchRow();
return $this->cacheHasItems;
}
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
index d0968337f02..e1735831b94 100644
--- a/lib/files/cache/permissions.php
+++ b/lib/files/cache/permissions.php
@@ -18,7 +18,7 @@ class Permissions {
* @param \OC\Files\Storage\Storage|string $storage
*/
public function __construct($storage){
- if($storage instanceof \OC\Files\Storage\Storage){
+ if($storage instanceof \OC\Files\Storage\Storage) {
$this->storageId = $storage->getId();
}else{
$this->storageId = $storage;
@@ -51,9 +51,11 @@ class Permissions {
*/
public function set($fileId, $user, $permissions) {
if (self::get($fileId, $user) !== -1) {
- $query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ? WHERE `user` = ? AND `fileid` = ?');
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ?'
+ .' WHERE `user` = ? AND `fileid` = ?');
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`) VALUES(?, ?,? )');
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`)'
+ .' VALUES(?, ?,? )');
}
$query->execute(array($permissions, $user, $fileId));
}
@@ -73,7 +75,8 @@ class Permissions {
$params[] = $user;
$inPart = implode(', ', array_fill(0, count($fileIds), '?'));
- $query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions` WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
+ $query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`'
+ .' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
$result = $query->execute($params);
$filePermissions = array();
while ($row = $result->fetchRow()) {
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 2623a167e9f..9c5ce9df7fc 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -59,9 +59,10 @@ class Scanner {
* scan a single file and store it in the cache
*
* @param string $file
+ * @param bool $checkExisting check existing folder sizes in the cache instead of always using -1 for folder size
* @return array with metadata of the scanned file
*/
- public function scanFile($file) {
+ public function scanFile($file, $checkExisting = false) {
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
$data = $this->getData($file);
if ($data) {
@@ -74,7 +75,15 @@ class Scanner {
$this->scanFile($parent);
}
}
- $id = $this->cache->put($file, $data);
+ if ($checkExisting and $cacheData = $this->cache->get($file)) {
+ if ($data['size'] === -1) {
+ $data['size'] = $cacheData['size'];
+ }
+ if ($data['mtime'] === $cacheData['mtime']) {
+ $data['etag'] = $cacheData['etag'];
+ }
+ }
+ $this->cache->put($file, $data);
}
return $data;
}
@@ -98,22 +107,20 @@ 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);
+ $data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
- if ($data['mimetype'] === 'httpd/unix-directory') {
+ if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) {
$childQueue[] = $child;
$data['size'] = 0;
} else {
- $data['size'] = -1;
+ $size = -1;
}
- } else {
}
- if ($data['size'] === -1) {
- $size = -1;
- } elseif ($size !== -1) {
+
+ if ($size !== -1) {
$size += $data['size'];
}
}
@@ -136,6 +143,22 @@ class Scanner {
}
/**
+ * @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
*/
public function backgroundScan() {
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index eb8c7297c3e..1fe4c584686 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -69,7 +69,8 @@ class Upgrade {
( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
- $insertQuery->execute(array($data['id'], $data['storage'], $data['path'], $data['path_hash'], $data['parent'], $data['name'],
+ $insertQuery->execute(array($data['id'], $data['storage'],
+ $data['path'], $data['path_hash'], $data['parent'], $data['name'],
$data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted']));
}
}