From: Thomas Müller Date: Fri, 15 Jan 2016 13:31:49 +0000 (+0100) Subject: Merge pull request #21702 from owncloud/fix_emit_scanFiles_II X-Git-Tag: v9.0beta1~273 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b7c0dc46bedea0729f27742b4ed15348b19004d9;p=nextcloud-server.git Merge pull request #21702 from owncloud/fix_emit_scanFiles_II Fix: emit 'scanFiles' will only fire on files and not on folders (II) --- b7c0dc46bedea0729f27742b4ed15348b19004d9 diff --cc lib/private/files/cache/scanner.php index 743b50f54a9,d70a1e4d416..1c50978a2e5 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@@ -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 = ''; @@@ -194,13 -209,15 +208,17 @@@ } 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; }