[Pkg-owncloud-commits] [owncloud] 57/85: Repair broken parent link in the scanner
David Prévot
taffit at moszumanska.debian.org
Tue Jun 17 19:12:45 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch 6.0
in repository owncloud.
commit 6e0a218d1110fcf076cc93277fd97a9d409778c9
Author: Robin Appelman <icewind at owncloud.com>
Date: Tue Jun 10 15:26:18 2014 +0200
Repair broken parent link in the scanner
---
lib/private/files/cache/scanner.php | 74 +++++++++++++++++++------------------
tests/lib/files/cache/scanner.php | 50 ++++++++++++++++++++++++-
2 files changed, 87 insertions(+), 37 deletions(-)
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index 8c10d0f..f1c4313 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -105,48 +105,50 @@ class Scanner extends BasicEmitter {
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
$data = $this->getData($file);
if ($data) {
- if ($file and !$parentExistsInCache) {
- $parent = dirname($file);
- if ($parent === '.' or $parent === '/') {
- $parent = '';
- }
- if (!$this->cache->inCache($parent)) {
- $this->scanFile($parent);
- }
+ $parent = dirname($file);
+ if ($parent === '.' or $parent === '/') {
+ $parent = '';
+ }
+ $parentId = $this->cache->getId($parent);
+ if ($file and $parentId === -1) {
+ $parentData = $this->scanFile($parent);
+ $parentId = $parentData['fileid'];
+ }
+ if ($parent) {
+ $data['parent'] = $parentId;
}
- $newData = $data;
$cacheData = $this->cache->get($file);
- if ($cacheData) {
- if (isset($cacheData['fileid'])) {
- $this->permissionsCache->remove($cacheData['fileid']);
- }
- if ($reuseExisting) {
- // prevent empty etag
+ if ( $cacheData and isset($cacheData['fileid'])) {
+ $this->permissionsCache->remove($cacheData['fileid']);
+ }
+ if ($cacheData and $reuseExisting) {
+ // prevent empty etag
+ if (empty($cacheData['etag'])) {
+ $etag = $data['etag'];
+ } else {
$etag = $cacheData['etag'];
- if (empty($etag)) {
- $etag = $data['etag'];
- } else {
- $etag = $cacheData['etag'];
- }
- // only reuse data if the file hasn't explicitly changed
- if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) {
- if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
- $data['size'] = $cacheData['size'];
- }
- if ($reuseExisting & self::REUSE_ETAG) {
- $data['etag'] = $etag;
- }
+ }
+ // only reuse data if the file hasn't explicitly changed
+ if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) {
+ $data['mtime'] = $cacheData['mtime'];
+ if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
+ $data['size'] = $cacheData['size'];
}
- // Only update metadata that has changed
- $newData = array_diff_assoc($data, $cacheData);
- if (isset($newData['etag'])) {
- $cacheDataString = print_r($cacheData, true);
- $dataString = print_r($data, true);
- \OCP\Util::writeLog('OC\Files\Cache\Scanner',
- "!!! No reuse of etag for '$file' !!! \ncache: $cacheDataString \ndata: $dataString",
- \OCP\Util::DEBUG);
+ if ($reuseExisting & self::REUSE_ETAG) {
+ $data['etag'] = $etag;
}
}
+ // Only update metadata that has changed
+ $newData = array_diff_assoc($data, $cacheData);
+ if (isset($newData['etag'])) {
+ $cacheDataString = print_r($cacheData, true);
+ $dataString = print_r($data, true);
+ \OCP\Util::writeLog('OC\Files\Cache\Scanner',
+ "!!! No reuse of etag for '$file' !!! \ncache: $cacheDataString \ndata: $dataString",
+ \OCP\Util::DEBUG);
+ }
+ } else {
+ $newData = $data;
}
if (!empty($newData)) {
$data['fileid'] = $this->addToCache($file, $newData);
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index 92d75aa..3b86df5 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -199,7 +199,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
}
- public function testScanRemovedFile(){
+ public function testScanRemovedFile() {
$this->fillTestFolders();
$this->scanner->scan('');
@@ -230,4 +230,52 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->assertInternalType('string', $newData0['etag']);
$this->assertNotEmpty($newData0['etag']);
}
+
+ public function testRepairParent() {
+ $this->fillTestFolders();
+ $this->scanner->scan('');
+ $this->assertTrue($this->cache->inCache('folder/bar.txt'));
+ $oldFolderId = $this->cache->getId('folder');
+
+ // delete the folder without removing the childs
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, array($oldFolderId));
+
+ $cachedData = $this->cache->get('folder/bar.txt');
+ $this->assertEquals($oldFolderId, $cachedData['parent']);
+ $this->assertFalse($this->cache->inCache('folder'));
+
+ $this->scanner->scan('');
+
+ $this->assertTrue($this->cache->inCache('folder'));
+ $newFolderId = $this->cache->getId('folder');
+ $this->assertNotEquals($oldFolderId, $newFolderId);
+
+ $cachedData = $this->cache->get('folder/bar.txt');
+ $this->assertEquals($newFolderId, $cachedData['parent']);
+ }
+
+ public function testRepairParentShallow() {
+ $this->fillTestFolders();
+ $this->scanner->scan('');
+ $this->assertTrue($this->cache->inCache('folder/bar.txt'));
+ $oldFolderId = $this->cache->getId('folder');
+
+ // delete the folder without removing the childs
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, array($oldFolderId));
+
+ $cachedData = $this->cache->get('folder/bar.txt');
+ $this->assertEquals($oldFolderId, $cachedData['parent']);
+ $this->assertFalse($this->cache->inCache('folder'));
+
+ $this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+
+ $this->assertTrue($this->cache->inCache('folder'));
+ $newFolderId = $this->cache->getId('folder');
+ $this->assertNotEquals($oldFolderId, $newFolderId);
+
+ $cachedData = $this->cache->get('folder/bar.txt');
+ $this->assertEquals($newFolderId, $cachedData['parent']);
+ }
}
--
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