delete child entries when a folder gets removed from cache

remotes/origin/stable5
Robin Appelman 13 years ago
parent 56e9ce44c3
commit 79d0ac21cc
  1. 12
      lib/files/cache/cache.php
  2. 16
      lib/files/cache/scanner.php
  3. 6
      tests/lib/files/cache/cache.php
  4. 9
      tests/lib/files/cache/scanner.php

@ -231,9 +231,15 @@ class Cache {
* @param string $file
*/
public function remove($file) {
$pathHash = md5($file);
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
$query->execute(array($this->storageId, $pathHash));
$entry = $this->get($file);
if ($entry['mimetype'] === 'httpd/unix-directory') {
$children = $this->getFolderContents($file);
foreach($children as $child){
$this->remove($child['path']);
}
}
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?');
$query->execute(array($entry['fileid']));
}
/**

@ -107,4 +107,20 @@ class Scanner {
}
return $size;
}
/**
* update the folder size and the size of all parent folders
*
* @param $path
*/
public function correctFolderSize($path) {
$this->cache->calculateFolderSize($path);
if ($path !== '') {
$parent = dirname($path);
if ($parent === '.') {
$parent = '';
}
$this->correctFolderSize($parent);
}
}
}

@ -82,7 +82,7 @@ class Cache extends \UnitTestCase {
$file1 = 'folder';
$file2 = 'folder/bar';
$file3 = 'folder/foo';
$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
$fileData = array();
$fileData['bar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
$fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
@ -110,6 +110,10 @@ class Cache extends \UnitTestCase {
$this->cache->put($file4, $fileData['unkownSize']);
$this->assertEquals(1025, $this->cache->calculateFolderSize($file1));
$this->cache->remove('folder');
$this->assertFalse($this->cache->inCache('folder/foo'));
$this->assertFalse($this->cache->inCache('folder/bar'));
}
function testStatus() {

@ -89,14 +89,19 @@ class Scanner extends \UnitTestCase {
$cachedDataFolder = $this->cache->get('');
$cachedDataFolder2 = $this->cache->get('folder');
$this->assertEqual($cachedDataFolder['size'], -1);
$this->assertEqual($cachedDataFolder2['size'], -1);
$this->assertEqual(-1, $cachedDataFolder['size']);
$this->assertEqual(-1, $cachedDataFolder2['size']);
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
$cachedDataFolder2 = $this->cache->get('folder');
$this->assertNotEqual($cachedDataFolder2['size'], -1);
$this->scanner->correctFolderSize('folder');
$cachedDataFolder = $this->cache->get('');
$this->assertNotEqual($cachedDataFolder['size'], -1);
}
function setUp() {

Loading…
Cancel
Save