more tests and fixes for the filesystem scanner
This commit is contained in:
parent
85be00be65
commit
b9b9fd9dba
|
@ -86,15 +86,24 @@ class Scanner {
|
|||
if ($file !== '.' and $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);
|
||||
if ($data['mimetype'] === 'httpd/unix-directory') {
|
||||
if ($recursive === self::SCAN_RECURSIVE) {
|
||||
$data['size'] = $this->scan($child, self::SCAN_RECURSIVE);
|
||||
} else {
|
||||
$data['size'] = -1;
|
||||
}
|
||||
}
|
||||
if ($data['size'] >= 0 and $size >= 0) {
|
||||
if ($data['size'] === -1) {
|
||||
$size = -1;
|
||||
} elseif ($size !== -1) {
|
||||
$size += $data['size'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($size !== -1) {
|
||||
$this->cache->put($path, array('size' => $size));
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,15 +45,52 @@ class Scanner extends \UnitTestCase {
|
|||
$this->assertEqual($cachedData['mimetype'], 'image/png');
|
||||
}
|
||||
|
||||
function testFolder() {
|
||||
private function fillTestFolders() {
|
||||
$textData = "dummy file data\n";
|
||||
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
|
||||
$this->storage->mkdir('folder');
|
||||
$this->storage->file_put_contents('foo.txt', $textData);
|
||||
$this->storage->file_put_contents('foo.png', $imgData);
|
||||
$this->storage->file_put_contents('folder/bar.txt', $textData);
|
||||
}
|
||||
|
||||
function testFolder() {
|
||||
$this->fillTestFolders();
|
||||
|
||||
$this->scanner->scan('');
|
||||
$this->assertEqual($this->cache->inCache(''), true);
|
||||
$this->assertEqual($this->cache->inCache('foo.txt'), true);
|
||||
$this->assertEqual($this->cache->inCache('foo.png'), true);
|
||||
$this->assertEqual($this->cache->inCache('folder'), true);
|
||||
$this->assertEqual($this->cache->inCache('folder/bar.txt'), true);
|
||||
|
||||
$cachedDataText = $this->cache->get('foo.txt');
|
||||
$cachedDataText2 = $this->cache->get('foo.txt');
|
||||
$cachedDataImage = $this->cache->get('foo.png');
|
||||
$cachedDataFolder = $this->cache->get('');
|
||||
$cachedDataFolder2 = $this->cache->get('folder');
|
||||
|
||||
$this->assertEqual($cachedDataImage['parent'], $cachedDataText['parent']);
|
||||
$this->assertEqual($cachedDataFolder['fileid'], $cachedDataImage['parent']);
|
||||
$this->assertEqual($cachedDataFolder['size'], $cachedDataImage['size'] + $cachedDataText['size'] + $cachedDataText2['size']);
|
||||
$this->assertEqual($cachedDataFolder2['size'], $cachedDataText2['size']);
|
||||
}
|
||||
|
||||
function testShallow() {
|
||||
$this->fillTestFolders();
|
||||
|
||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||
$this->assertEqual($this->cache->inCache(''), true);
|
||||
$this->assertEqual($this->cache->inCache('foo.txt'), true);
|
||||
$this->assertEqual($this->cache->inCache('foo.png'), true);
|
||||
$this->assertEqual($this->cache->inCache('folder'), true);
|
||||
$this->assertEqual($this->cache->inCache('folder/bar.txt'), false);
|
||||
|
||||
$cachedDataFolder = $this->cache->get('');
|
||||
$cachedDataFolder2 = $this->cache->get('folder');
|
||||
|
||||
$this->assertEqual($cachedDataFolder['size'], -1);
|
||||
$this->assertEqual($cachedDataFolder2['size'], -1);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
|
|
Loading…
Reference in New Issue