]> source.dussan.org Git - nextcloud-server.git/commitdiff
remove deleted files when re-scanning a folder
authorRobin Appelman <icewind@owncloud.com>
Wed, 19 Jun 2013 22:42:34 +0000 (00:42 +0200)
committerThomas Mueller <thomas.mueller@tmit.eu>
Thu, 20 Jun 2013 11:05:45 +0000 (13:05 +0200)
lib/files/cache/scanner.php
tests/lib/files/cache/scanner.php

index fe237c26cfadf249203fa517af0be71e59e06399..cb62f2ba31032bebe4ea7062ca758bbf502c2179 100644 (file)
@@ -136,11 +136,20 @@ class Scanner {
                \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_folder', array('path' => $path, 'storage' => $this->storageId));
                $size = 0;
                $childQueue = array();
+               $existingChildren = array();
+               if ($this->cache->inCache($path)) {
+                       $children = $this->cache->getFolderContents($path);
+                       foreach ($children as $child) {
+                               $existingChildren[] = $child['name'];
+                       }
+               }
+               $newChildren = array();
                if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
                        \OC_DB::beginTransaction();
                        while ($file = readdir($dh)) {
                                $child = ($path) ? $path . '/' . $file : $file;
                                if (!Filesystem::isIgnoredDir($file)) {
+                                       $newChildren[] = $file;
                                        $data = $this->scanFile($child, $reuse);
                                        if ($data) {
                                                if ($data['size'] === -1) {
@@ -155,6 +164,11 @@ class Scanner {
                                        }
                                }
                        }
+                       $removedChildren = \array_diff($existingChildren, $newChildren);
+                       foreach ($removedChildren as $childName) {
+                               $child = ($path) ? $path . '/' . $childName : $childName;
+                               $this->cache->remove($child);
+                       }
                        \OC_DB::commit();
                        foreach ($childQueue as $child) {
                                $childSize = $this->scanChildren($child, self::SCAN_RECURSIVE);
index 3dacefa2b801dab56f6a34b8d26ddfb4f5312218..3ee7f099f388e8f93850216b8d74fa18edc83f58 100644 (file)
@@ -144,6 +144,16 @@ class Scanner extends \PHPUnit_Framework_TestCase {
                $this->assertEquals(-1, $newData['size']);
        }
 
+       public function testRemovedFile() {
+               $this->fillTestFolders();
+
+               $this->scanner->scan('');
+               $this->assertTrue($this->cache->inCache('foo.txt'));
+               $this->storage->unlink('foo.txt');
+               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+               $this->assertFalse($this->cache->inCache('foo.txt'));
+       }
+
        function setUp() {
                $this->storage = new \OC\Files\Storage\Temporary(array());
                $this->scanner = new \OC\Files\Cache\Scanner($this->storage);