aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/files/cache/scanner.php6
-rw-r--r--tests/lib/files/cache/scanner.php23
2 files changed, 26 insertions, 3 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 721d0d825ec..7d449204e81 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -77,12 +77,14 @@ class Scanner {
* @param SCAN_RECURSIVE/SCAN_SHALLOW $recursive
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
*/
- public function scan($path, $recursive) {
+ public function scan($path, $recursive = self::SCAN_RECURSIVE) {
+ $this->scanFile($path);
+
$size = 0;
if ($dh = $this->storage->opendir($path)) {
while ($file = readdir($dh)) {
if ($file !== '.' and $file !== '..') {
- $child = $path . '/' . $file;
+ $child = ($path !== '') ? $path . '/' . $file : $file;
$data = $this->scanFile($child);
if ($recursive === self::SCAN_RECURSIVE and $data['mimetype'] === 'httpd/unix-directory') {
$data['size'] = $this->scan($child, self::SCAN_RECURSIVE);
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index 3d1c1546ab0..7ee28dfc3fd 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -33,6 +33,27 @@ class Scanner extends \UnitTestCase {
$cachedData = $this->cache->get('foo.txt');
$this->assertEqual($cachedData['size'], strlen($data));
$this->assertEqual($cachedData['mimetype'], 'text/plain');
+ $this->assertNotEqual($cachedData['parent'], -1); //parent folders should be scanned automatically
+
+ $data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->file_put_contents('foo.png', $data);
+ $this->scanner->scanFile('foo.png');
+
+ $this->assertEqual($this->cache->inCache('foo.png'), true);
+ $cachedData = $this->cache->get('foo.png');
+ $this->assertEqual($cachedData['size'], strlen($data));
+ $this->assertEqual($cachedData['mimetype'], 'image/png');
+ }
+
+ function testFolder() {
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->file_put_contents('foo.txt', $textData);
+ $this->storage->file_put_contents('foo.png', $imgData);
+
+ $this->scanner->scan('');
+ $this->assertEqual($this->cache->inCache('foo.txt'), true);
+ $this->assertEqual($this->cache->inCache('foo.png'), true);
}
function setUp() {
@@ -42,6 +63,6 @@ class Scanner extends \UnitTestCase {
}
function tearDown() {
-// $this->cache->clear();
+ $this->cache->clear();
}
}