Skip to content
Snippets Groups Projects
Commit 87b0021e authored by Robin Appelman's avatar Robin Appelman Committed by Bjoern Schiessle
Browse files

Scan the entire remote share at once by requesting the full file tree from the remote server

parent 30f5b2bd
No related branches found
No related tags found
No related merge requests found
......@@ -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);
<?php
/**
* Copyright (c) 2014 Robin Appelman <icewind@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));
<?php
/**
* Copyright (c) 2014 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 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'], '/'));
}
}
}
}
......@@ -27,6 +27,11 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage {
*/
private $mountPoint;
/**
* @var string
*/
private $token;
/**
* @var \OCA\Files_Sharing\External\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)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment