Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/files
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-08-06 01:30:36 +0400
committerThomas Müller <thomas.mueller@tmit.eu>2013-08-06 01:30:36 +0400
commit6c8a0b2c8dbb7917e7ed4df14315b2bd93a491de (patch)
treef9940b74f39ab7819258bc6e19c7f14414490ed8 /lib/files
parentd8b14ed47af4ebb3463c3daacd560c32dc853478 (diff)
parentf8ce76c4233efd32ad1e505356980caf78f0a801 (diff)
Merge pull request #4317 from owncloud/backport-cli-scanner-stable5
Backport cli scanner to stable5
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/cache/scanner.php15
-rw-r--r--lib/files/storage/common.php24
-rw-r--r--lib/files/utils/scanner.php90
3 files changed, 123 insertions, 6 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 54f5d79eca7..65759a34fd2 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
*/
@@ -70,6 +80,7 @@ class Scanner {
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) {
@@ -133,7 +144,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();
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index d1386acd44e..f2651f77070 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -21,6 +21,10 @@ namespace OC\Files\Storage;
*/
abstract class Common implements \OC\Files\Storage\Storage {
+ private $cache;
+ private $scanner;
+ private $permissioncache;
+ private $watcher;
public function __construct($parameters) {
}
@@ -263,19 +267,31 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
public function getCache($path = '') {
- return new \OC\Files\Cache\Cache($this);
+ if (!isset($this->cache)) {
+ $this->cache = new \OC\Files\Cache\Cache($this);
+ }
+ return $this->cache;
}
public function getScanner($path = '') {
- return new \OC\Files\Cache\Scanner($this);
+ if (!isset($this->scanner)) {
+ $this->scanner = new \OC\Files\Cache\Scanner($this);
+ }
+ return $this->scanner;
}
public function getPermissionsCache($path = '') {
- return new \OC\Files\Cache\Permissions($this);
+ if (!isset($this->permissioncache)) {
+ $this->permissioncache = new \OC\Files\Cache\Permissions($this);
+ }
+ return $this->permissioncache;
}
public function getWatcher($path = '') {
- return new \OC\Files\Cache\Watcher($this);
+ if (!isset($this->watcher)) {
+ $this->watcher = new \OC\Files\Cache\Watcher($this);
+ }
+ return $this->watcher;
}
/**
diff --git a/lib/files/utils/scanner.php b/lib/files/utils/scanner.php
new file mode 100644
index 00000000000..a98d4611f78
--- /dev/null
+++ b/lib/files/utils/scanner.php
@@ -0,0 +1,90 @@
+<?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\Files\Filesystem;
+use OC\Files\Mount;
+use OC\Hooks\PublicEmitter;
+
+/**
+ * Class Scanner
+ *
+ * Hooks available in scope \OC\Utils\Scanner
+ * - scanFile(string $absolutePath)
+ * - scanFolder(string $absolutePath)
+ *
+ * @package OC\Files\Utils
+ */
+class Scanner extends PublicEmitter {
+ /**
+ * @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[]
+ */
+ 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);
+
+ $mounts = Mount::findIn($absolutePath);
+ $mounts[] = Mount::find($absolutePath);
+ $mounts = array_reverse($mounts); //start with the mount of $dir
+
+ return $mounts;
+ }
+
+ /**
+ * attach listeners to the scanner
+ *
+ * @param \OC\Files\Mount $mount
+ */
+ protected function attachListener($mount) {
+ $scanner = $mount->getStorage()->getScanner();
+ $emitter = $this;
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) {
+ $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path));
+ });
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) {
+ $emitter->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);
+ }
+ }
+}
+