summaryrefslogtreecommitdiffstats
path: root/lib/files
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-07-30 00:37:05 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-07-30 00:37:05 +0200
commitf658852276204fbf1a76d58ac2f585cf9db8c75d (patch)
tree5fbd6d93c7435022e8539065a45469bd249799ad /lib/files
parent085fdfec2f298fd89d0265d0f97edfdda5a12954 (diff)
parent7c6246fa451c4646dfaa1396dd37e0b3eb9706ba (diff)
downloadnextcloud-server-f658852276204fbf1a76d58ac2f585cf9db8c75d.tar.gz
nextcloud-server-f658852276204fbf1a76d58ac2f585cf9db8c75d.zip
Merge branch 'master' into fixing-testGetById-master
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/cache/scanner.php28
-rw-r--r--lib/files/filesystem.php9
-rw-r--r--lib/files/utils/scanner.php89
3 files changed, 117 insertions, 9 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 9b94a24f481..dd212d84cc5 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -9,8 +9,18 @@
namespace OC\Files\Cache;
use OC\Files\Filesystem;
+use OC\Hooks\BasicEmitter;
-class Scanner {
+/**
+ * Class Scanner
+ *
+ * Hooks available in scope \OC\Files\Cache\Scanner:
+ * - scanFile(string $path, string $storageId)
+ * - scanFolder(string $path, string $storageId)
+ *
+ * @package OC\Files\Cache
+ */
+class Scanner extends BasicEmitter {
/**
* @var \OC\Files\Storage\Storage $storage
*/
@@ -65,16 +75,18 @@ class Scanner {
*
* @param string $file
* @param int $reuseExisting
+ * @param bool $parentExistsInCache
* @return array with metadata of the scanned file
*/
- public function scanFile($file, $reuseExisting = 0) {
+ public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) {
if (!self::isPartialFile($file)
and !Filesystem::isFileBlacklisted($file)
) {
+ $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) {
- if ($file) {
+ if ($file and !$parentExistsInCache) {
$parent = dirname($file);
if ($parent === '.' or $parent === '/') {
$parent = '';
@@ -97,9 +109,9 @@ class Scanner {
// Only update metadata that has changed
$newData = array_diff($data, $cacheData);
}
- }
- if (!empty($newData)) {
- $this->cache->put($file, $newData);
+ if (!empty($newData)) {
+ $this->cache->put($file, $newData);
+ }
}
return $data;
}
@@ -134,7 +146,7 @@ class Scanner {
if ($reuse === -1) {
$reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
}
- \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_folder', array('path' => $path, 'storage' => $this->storageId));
+ $this->emit('\OC\Files\Cache\Scanner', 'scanFolder', array($path, $this->storageId));
$size = 0;
$childQueue = array();
$existingChildren = array();
@@ -151,7 +163,7 @@ class Scanner {
$child = ($path) ? $path . '/' . $file : $file;
if (!Filesystem::isIgnoredDir($file)) {
$newChildren[] = $file;
- $data = $this->scanFile($child, $reuse);
+ $data = $this->scanFile($child, $reuse, true);
if ($data) {
if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) {
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index 1bf7270c7f1..d6ebe7d629a 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -148,13 +148,20 @@ class Filesystem {
*/
private static $loader;
- public static function getLoader(){
+ public static function getLoader() {
if (!self::$loader) {
self::$loader = new Loader();
}
return self::$loader;
}
+ public static function getMountManager() {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
+ return self::$mounts;
+ }
+
/**
* get the mountpoint of the storage object for a path
* ( note: because a storage is not always mounted inside the fakeroot, the
diff --git a/lib/files/utils/scanner.php b/lib/files/utils/scanner.php
new file mode 100644
index 00000000000..800bb649934
--- /dev/null
+++ b/lib/files/utils/scanner.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Utils;
+
+use OC\Hooks\BasicEmitter;
+use OC\Files\Filesystem;
+
+/**
+ * Class Scanner
+ *
+ * Hooks available in scope \OC\Utils\Scanner
+ * - scanFile(string $absolutePath)
+ * - scanFolder(string $absolutePath)
+ *
+ * @package OC\Files\Utils
+ */
+class Scanner extends BasicEmitter {
+ /**
+ * @var string $user
+ */
+ private $user;
+
+ /**
+ * @param string $user
+ */
+ public function __construct($user) {
+ $this->user = $user;
+ }
+
+ /**
+ * get all storages for $dir
+ *
+ * @param string $dir
+ * @return \OC\Files\Mount\Mount[]
+ */
+ protected function getMounts($dir) {
+ //TODO: move to the node based fileapi once that's done
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($this->user);
+ $absolutePath = Filesystem::getView()->getAbsolutePath($dir);
+
+ $mountManager = Filesystem::getMountManager();
+ $mounts = $mountManager->findIn($absolutePath);
+ $mounts[] = $mountManager->find($absolutePath);
+ $mounts = array_reverse($mounts); //start with the mount of $dir
+
+ return $mounts;
+ }
+
+ /**
+ * attach listeners to the scanner
+ *
+ * @param \OC\Files\Mount\Mount $mount
+ */
+ protected function attachListener($mount) {
+ $scanner = $mount->getStorage()->getScanner();
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount) {
+ $this->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path));
+ });
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount) {
+ $this->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path));
+ });
+ }
+
+ public function backgroundScan($dir) {
+ $mounts = $this->getMounts($dir);
+ foreach ($mounts as $mount) {
+ $scanner = $mount->getStorage()->getScanner();
+ $this->attachListener($mount);
+ $scanner->backgroundScan();
+ }
+ }
+
+ public function scan($dir) {
+ $mounts = $this->getMounts($dir);
+ foreach ($mounts as $mount) {
+ $scanner = $mount->getStorage()->getScanner();
+ $this->attachListener($mount);
+ $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
+ }
+ }
+}
+