]> source.dussan.org Git - nextcloud-server.git/commitdiff
Merge pull request #21702 from owncloud/fix_emit_scanFiles_II
authorThomas Müller <thomas.mueller@tmit.eu>
Fri, 15 Jan 2016 13:31:49 +0000 (14:31 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Fri, 15 Jan 2016 13:31:49 +0000 (14:31 +0100)
Fix: emit 'scanFiles' will only fire on files and not on folders (II)

1  2 
lib/private/files/cache/scanner.php

index 743b50f54a923b491c14cab816ed49d7591cb1ef,d70a1e4d416bb8fec6b185c1f3edfaf639841e29..1c50978a2e528fa7cddcc7cf7828c9b59f9a5472
@@@ -129,18 -133,25 +129,27 @@@ class Scanner extends BasicEmitter impl
         * @throws \OCP\Lock\LockedException
         */
        public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) {
-               if (!self::isPartialFile($file)
-                       and !Filesystem::isFileBlacklisted($file)
-               ) {
+               // only proceed if $file is not a partial file nor a blacklisted file
+               if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file)) {
+                       //acquire a lock
                        if ($lock) {
 -                              $this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
 +                              if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
 +                                      $this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
 +                              }
                        }
-                       $this->emit('\OC\Files\Cache\Scanner', 'scanFile', array($file, $this->storageId));
-                       \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
                        $data = $this->getData($file);
                        if ($data) {
+                               // pre-emit only if it was a file. By that we avoid counting/treating folders as files
+                               if ($data['mimetype'] !== 'httpd/unix-directory') {
+                                       $this->emit('\OC\Files\Cache\Scanner', 'scanFile', array($file, $this->storageId));
+                                       \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
+                               }
                                $parent = dirname($file);
                                if ($parent === '.' or $parent === '/') {
                                        $parent = '';
                        } else {
                                $this->removeFromCache($file);
                        }
+                       //release the acquired lock
                        if ($lock) {
 -                              $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
 +                              if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
 +                                      $this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
 +                              }
                        }
                        return $data;
                }
                return null;
        }