summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/files/cache/cache.php19
-rw-r--r--tests/lib/files/cache/cache.php17
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 7c6bba4fadb..b52c0f40677 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -402,4 +402,23 @@ class Cache {
}
return $ids;
}
+
+ /**
+ * find a folder in the cache which has not been fully scanned
+ *
+ * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
+ * use the one with the highest id gives the best result with the background scanner, since that is most
+ * likely the folder where we stopped scanning previously
+ *
+ * @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->execute(array($this->storageId));
+ if($row = $query->fetchRow()){
+ return $row['path'];
+ }else{
+ return false;
+ }
+ }
}
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 9c469aa9374..e9105cd5abd 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -175,6 +175,23 @@ class Cache extends \UnitTestCase {
$this->assertTrue($this->cache->inCache('folder/foobar/2'));
}
+ function testGetIncomplete() {
+ $file1 = 'folder1';
+ $file2 = 'folder2';
+ $file3 = 'folder3';
+ $file4 = 'folder4';
+ $data = array('size' => 10, 'mtime' => 50, 'mimetype' => 'foo/bar');
+
+ $this->cache->put($file1, $data);
+ $data['size'] = -1;
+ $this->cache->put($file2, $data);
+ $this->cache->put($file3, $data);
+ $data['size'] = 12;
+ $this->cache->put($file4, $data);
+
+ $this->assertEquals($file3, $this->cache->getIncomplete());
+ }
+
public function tearDown() {
$this->cache->clear();
}