[Pkg-owncloud-commits] [owncloud] 112/223: Scan the entire remote share at once by requesting the full file tree from the remote server

David Prévot taffit at moszumanska.debian.org
Sun Jun 22 01:54:13 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 87b0021e5606888642b5798ba39b0525bf3f3e14
Author: Robin Appelman <icewind at owncloud.com>
Date:   Mon May 19 16:39:57 2014 +0200

    Scan the entire remote share at once by requesting the full file tree from the remote server
---
 apps/files_sharing/ajax/external.php        |  9 ++++-
 apps/files_sharing/ajax/shareinfo.php       | 62 +++++++++++++++++++++++++++++
 apps/files_sharing/lib/external/scanner.php | 52 ++++++++++++++++++++++++
 apps/files_sharing/lib/external/storage.php | 25 ++++++++++++
 4 files changed, 147 insertions(+), 1 deletion(-)

diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php
index e7bf903..c25b34a 100644
--- a/apps/files_sharing/ajax/external.php
+++ b/apps/files_sharing/ajax/external.php
@@ -23,6 +23,13 @@ $externalManager = new \OCA\Files_Sharing\External\Manager(
 );
 
 $mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
-$result = $mount->getStorage()->file_exists('');
+/**
+ * @var \OCA\Files_Sharing\External\Storage $storage
+ */
+$storage = $mount->getStorage();
+$result = $storage->file_exists('');
+if($result){
+	$storage->getScanner()->scanAll();
+}
 
 echo json_encode($result);
diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php
new file mode 100644
index 0000000..4aefdbe
--- /dev/null
+++ b/apps/files_sharing/ajax/shareinfo.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+if (!\OC_App::isEnabled('files_sharing')) {
+	exit;
+}
+
+if (!isset($_GET['t'])) {
+	\OC_Response::setStatus(400); //400 Bad Request
+	exit;
+}
+
+$token = $_GET['t'];
+
+$password = null;
+if (isset($_POST['password'])) {
+	$password = $_POST['password'];
+}
+
+$relativePath = null;
+if (isset($_GET['dir'])) {
+	$relativePath = $_GET['dir'];
+}
+
+$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
+
+$linkItem = $data['linkItem'];
+// Load the files
+$path = $data['realPath'];
+
+$rootInfo = \OC\Files\Filesystem::getFileInfo($path);
+$rootView = new \OC\Files\View('');
+
+/**
+ * @param \OCP\Files\FileInfo $dir
+ * @param \OC\Files\View $view
+ * @return array
+ */
+function getChildInfo($dir, $view) {
+	$children = $view->getDirectoryContent($dir->getPath());
+	$result = array();
+	foreach ($children as $child) {
+		$formated = \OCA\Files\Helper::formatFileInfo($child);
+		if ($child->getType() === 'dir') {
+			$formated['children'] = getChildInfo($child, $view);
+		}
+		$result[] = $formated;
+	}
+	return $result;
+}
+
+$result = \OCA\Files\Helper::formatFileInfo($rootInfo);
+if ($rootInfo->getType() === 'dir') {
+	$result['children'] = getChildInfo($rootInfo, $rootView);
+}
+
+OCP\JSON::success(array('data' => $result));
diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php
new file mode 100644
index 0000000..1f32d79
--- /dev/null
+++ b/apps/files_sharing/lib/external/scanner.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_Sharing\External;
+
+class Scanner extends \OC\Files\Cache\Scanner {
+	/**
+	 * @var \OCA\Files_Sharing\External\Storage
+	 */
+	protected $storage;
+
+	public function scanAll() {
+		$remote = $this->storage->getRemote();
+		$token = $this->storage->getToken();
+		$password = $this->storage->getPassword();
+		$url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
+
+		$ch = curl_init();
+
+		curl_setopt($ch, CURLOPT_URL, $url);
+		curl_setopt($ch, CURLOPT_POST, 1);
+		if ($password) {
+			curl_setopt($ch, CURLOPT_POSTFIELDS,
+				http_build_query(array('password' => $password)));
+		}
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+		$result = curl_exec($ch);
+		curl_close($ch);
+
+		$data = json_decode($result, true);
+		if ($data['status'] === 'success') {
+			$this->addResult($data['data'], '');
+		} else {
+			throw new \Exception('Error while scanning remote share');
+		}
+	}
+
+	private function addResult($data, $path) {
+		$this->cache->put($path, $data);
+		if ($data['children']) {
+			foreach ($data['children'] as $child) {
+				$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
+			}
+		}
+	}
+}
diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php
index 0e799a0..741e219 100644
--- a/apps/files_sharing/lib/external/storage.php
+++ b/apps/files_sharing/lib/external/storage.php
@@ -28,6 +28,11 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
 	private $mountPoint;
 
 	/**
+	 * @var string
+	 */
+	private $token;
+
+	/**
 	 * @var \OCA\Files_Sharing\External\Manager
 	 */
 	private $manager;
@@ -41,6 +46,7 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
 		$secure = $protocol === 'https';
 		$root .= '/public.php/webdav';
 		$this->mountPoint = $options['mountpoint'];
+		$this->token = $options['token'];
 		parent::__construct(array(
 			'secure' => $secure,
 			'host' => $host,
@@ -62,6 +68,14 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
 		return $this->mountPoint;
 	}
 
+	public function getToken() {
+		return $this->token;
+	}
+
+	public function getPassword() {
+		return $this->password;
+	}
+
 	/**
 	 * @brief get id of the mount point
 	 * @return string
@@ -77,6 +91,17 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
 		return $this->cache;
 	}
 
+	/**
+	 * @param string $path
+	 * @return \OCA\Files_Sharing\External\Scanner
+	 */
+	public function getScanner($path = '') {
+		if (!isset($this->scanner)) {
+			$this->scanner = new Scanner($this);
+		}
+		return $this->scanner;
+	}
+
 	public function rename($path1, $path2) {
 		// if we renamed the mount point we need to adjust the mountpoint in the database
 		if (Filesystem::normalizePath($this->mountPoint) === Filesystem::normalizePath($path1)) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list