2013-09-01 17:47:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2013-09-01 17:47:48 +00:00
|
|
|
namespace OC\Files\Node;
|
|
|
|
|
2016-07-22 12:37:37 +00:00
|
|
|
use OC\DB\QueryBuilder\Literal;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2016-09-18 16:36:53 +00:00
|
|
|
use OCP\Files\Config\ICachedMountInfo;
|
2015-09-08 20:38:50 +00:00
|
|
|
use OCP\Files\FileInfo;
|
2016-07-22 12:37:37 +00:00
|
|
|
use OCP\Files\Mount\IMountPoint;
|
2013-09-10 17:44:23 +00:00
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\NotPermittedException;
|
2017-02-02 17:20:08 +00:00
|
|
|
use OCP\Files\Search\ISearchOperator;
|
2013-09-01 17:47:48 +00:00
|
|
|
|
2013-09-10 17:44:23 +00:00
|
|
|
class Folder extends Node implements \OCP\Files\Folder {
|
2016-11-14 17:29:11 +00:00
|
|
|
/**
|
|
|
|
* Creates a Folder that represents a non-existing path
|
|
|
|
*
|
|
|
|
* @param string $path path
|
|
|
|
* @return string non-existing node class
|
|
|
|
*/
|
|
|
|
protected function createNonExistingNode($path) {
|
|
|
|
return new NonExistingFolder($this->root, $this->view, $path);
|
|
|
|
}
|
|
|
|
|
2013-09-01 17:47:48 +00:00
|
|
|
/**
|
|
|
|
* @param string $path path relative to the folder
|
|
|
|
* @return string
|
2013-09-10 17:44:23 +00:00
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function getFullPath($path) {
|
|
|
|
if (!$this->isValidPath($path)) {
|
2016-10-24 09:32:17 +00:00
|
|
|
throw new NotPermittedException('Invalid path');
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
return $this->path . $this->normalizePath($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRelativePath($path) {
|
|
|
|
if ($this->path === '' or $this->path === '/') {
|
|
|
|
return $this->normalizePath($path);
|
|
|
|
}
|
2014-08-05 14:58:10 +00:00
|
|
|
if ($path === $this->path) {
|
|
|
|
return '/';
|
|
|
|
} else if (strpos($path, $this->path . '/') !== 0) {
|
2014-08-06 10:06:41 +00:00
|
|
|
return null;
|
2013-09-01 17:47:48 +00:00
|
|
|
} else {
|
|
|
|
$path = substr($path, strlen($this->path));
|
2014-08-05 14:58:10 +00:00
|
|
|
return $this->normalizePath($path);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a node is a (grand-)child of the folder
|
|
|
|
*
|
|
|
|
* @param \OC\Files\Node\Node $node
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isSubNode($node) {
|
|
|
|
return strpos($node->getPath(), $this->path . '/') === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the content of this directory
|
|
|
|
*
|
2013-09-10 17:44:23 +00:00
|
|
|
* @throws \OCP\Files\NotFoundException
|
2013-09-01 17:47:48 +00:00
|
|
|
* @return Node[]
|
|
|
|
*/
|
|
|
|
public function getDirectoryListing() {
|
2015-09-08 20:38:50 +00:00
|
|
|
$folderContent = $this->view->getDirectoryContent($this->path);
|
2013-09-01 17:47:48 +00:00
|
|
|
|
2016-09-18 16:36:53 +00:00
|
|
|
return array_map(function (FileInfo $info) {
|
2015-09-08 20:38:50 +00:00
|
|
|
if ($info->getMimetype() === 'httpd/unix-directory') {
|
|
|
|
return new Folder($this->root, $this->view, $info->getPath(), $info);
|
|
|
|
} else {
|
|
|
|
return new File($this->root, $this->view, $info->getPath(), $info);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
2015-09-08 20:38:50 +00:00
|
|
|
}, $folderContent);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
2016-03-21 13:20:33 +00:00
|
|
|
* @param FileInfo $info
|
2013-09-01 17:47:48 +00:00
|
|
|
* @return File|Folder
|
|
|
|
*/
|
2016-03-21 13:20:33 +00:00
|
|
|
protected function createNode($path, FileInfo $info = null) {
|
|
|
|
if (is_null($info)) {
|
2013-09-01 17:47:48 +00:00
|
|
|
$isDir = $this->view->is_dir($path);
|
|
|
|
} else {
|
2016-03-21 13:20:33 +00:00
|
|
|
$isDir = $info->getType() === FileInfo::TYPE_FOLDER;
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
if ($isDir) {
|
2016-02-18 14:41:10 +00:00
|
|
|
return new Folder($this->root, $this->view, $path, $info);
|
2013-09-01 17:47:48 +00:00
|
|
|
} else {
|
2016-02-18 14:41:10 +00:00
|
|
|
return new File($this->root, $this->view, $path, $info);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the node at $path
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return \OC\Files\Node\Node
|
2013-09-10 17:44:23 +00:00
|
|
|
* @throws \OCP\Files\NotFoundException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function get($path) {
|
|
|
|
return $this->root->get($this->getFullPath($path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function nodeExists($path) {
|
|
|
|
try {
|
|
|
|
$this->get($path);
|
|
|
|
return true;
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
2013-09-10 17:44:23 +00:00
|
|
|
* @return \OC\Files\Node\Folder
|
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function newFolder($path) {
|
2014-11-25 15:28:41 +00:00
|
|
|
if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
|
2013-09-01 17:47:48 +00:00
|
|
|
$fullPath = $this->getFullPath($path);
|
|
|
|
$nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath);
|
|
|
|
$this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
|
|
|
|
$this->root->emit('\OC\Files', 'preCreate', array($nonExisting));
|
|
|
|
$this->view->mkdir($fullPath);
|
|
|
|
$node = new Folder($this->root, $this->view, $fullPath);
|
|
|
|
$this->root->emit('\OC\Files', 'postWrite', array($node));
|
|
|
|
$this->root->emit('\OC\Files', 'postCreate', array($node));
|
|
|
|
return $node;
|
|
|
|
} else {
|
2016-10-24 09:32:17 +00:00
|
|
|
throw new NotPermittedException('No create permission for folder');
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
2013-09-10 17:44:23 +00:00
|
|
|
* @return \OC\Files\Node\File
|
|
|
|
* @throws \OCP\Files\NotPermittedException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function newFile($path) {
|
2014-11-25 15:28:41 +00:00
|
|
|
if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
|
2013-09-01 17:47:48 +00:00
|
|
|
$fullPath = $this->getFullPath($path);
|
|
|
|
$nonExisting = new NonExistingFile($this->root, $this->view, $fullPath);
|
|
|
|
$this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
|
|
|
|
$this->root->emit('\OC\Files', 'preCreate', array($nonExisting));
|
|
|
|
$this->view->touch($fullPath);
|
|
|
|
$node = new File($this->root, $this->view, $fullPath);
|
|
|
|
$this->root->emit('\OC\Files', 'postWrite', array($node));
|
|
|
|
$this->root->emit('\OC\Files', 'postCreate', array($node));
|
|
|
|
return $node;
|
|
|
|
} else {
|
2016-10-24 09:32:17 +00:00
|
|
|
throw new NotPermittedException('No create permission for path');
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files with the name matching $query
|
|
|
|
*
|
2017-02-02 17:20:08 +00:00
|
|
|
* @param string|ISearchOperator $query
|
2013-09-10 17:44:23 +00:00
|
|
|
* @return \OC\Files\Node\Node[]
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function search($query) {
|
2017-02-02 17:20:08 +00:00
|
|
|
if (is_string($query)) {
|
|
|
|
return $this->searchCommon('search', array('%' . $query . '%'));
|
|
|
|
} else {
|
|
|
|
return $this->searchCommon('searchQuery', array($query));
|
|
|
|
}
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files by mimetype
|
|
|
|
*
|
|
|
|
* @param string $mimetype
|
|
|
|
* @return Node[]
|
|
|
|
*/
|
|
|
|
public function searchByMime($mimetype) {
|
2014-12-12 10:18:35 +00:00
|
|
|
return $this->searchCommon('searchByMime', array($mimetype));
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-04 13:01:15 +00:00
|
|
|
/**
|
|
|
|
* search for files by tag
|
|
|
|
*
|
2014-12-12 10:18:35 +00:00
|
|
|
* @param string|int $tag name or tag id
|
|
|
|
* @param string $userId owner of the tags
|
2014-12-04 13:01:15 +00:00
|
|
|
* @return Node[]
|
|
|
|
*/
|
2014-12-12 10:18:35 +00:00
|
|
|
public function searchByTag($tag, $userId) {
|
|
|
|
return $this->searchCommon('searchByTag', array($tag, $userId));
|
2014-12-04 13:01:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 17:47:48 +00:00
|
|
|
/**
|
2014-12-12 10:18:35 +00:00
|
|
|
* @param string $method cache method
|
|
|
|
* @param array $args call args
|
2013-09-10 17:44:23 +00:00
|
|
|
* @return \OC\Files\Node\Node[]
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
2014-12-12 10:18:35 +00:00
|
|
|
private function searchCommon($method, $args) {
|
2013-09-01 17:47:48 +00:00
|
|
|
$files = array();
|
|
|
|
$rootLength = strlen($this->path);
|
2016-03-21 13:20:33 +00:00
|
|
|
$mount = $this->root->getMount($this->path);
|
|
|
|
$storage = $mount->getStorage();
|
|
|
|
$internalPath = $mount->getInternalPath($this->path);
|
2015-10-06 13:02:47 +00:00
|
|
|
$internalPath = rtrim($internalPath, '/');
|
|
|
|
if ($internalPath !== '') {
|
|
|
|
$internalPath = $internalPath . '/';
|
|
|
|
}
|
2013-09-01 17:47:48 +00:00
|
|
|
$internalRootLength = strlen($internalPath);
|
|
|
|
|
|
|
|
$cache = $storage->getCache('');
|
|
|
|
|
2014-12-12 10:18:35 +00:00
|
|
|
$results = call_user_func_array(array($cache, $method), $args);
|
2013-09-01 17:47:48 +00:00
|
|
|
foreach ($results as $result) {
|
2015-10-06 13:02:47 +00:00
|
|
|
if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) {
|
2013-09-01 17:47:48 +00:00
|
|
|
$result['internalPath'] = $result['path'];
|
|
|
|
$result['path'] = substr($result['path'], $internalRootLength);
|
|
|
|
$result['storage'] = $storage;
|
2016-03-21 13:20:33 +00:00
|
|
|
$files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mounts = $this->root->getMountsIn($this->path);
|
|
|
|
foreach ($mounts as $mount) {
|
|
|
|
$storage = $mount->getStorage();
|
|
|
|
if ($storage) {
|
|
|
|
$cache = $storage->getCache('');
|
|
|
|
|
2018-07-02 12:16:12 +00:00
|
|
|
$relativeMountPoint = ltrim(substr($mount->getMountPoint(), $rootLength), '/');
|
2014-12-12 10:18:35 +00:00
|
|
|
$results = call_user_func_array(array($cache, $method), $args);
|
2013-09-01 17:47:48 +00:00
|
|
|
foreach ($results as $result) {
|
|
|
|
$result['internalPath'] = $result['path'];
|
|
|
|
$result['path'] = $relativeMountPoint . $result['path'];
|
|
|
|
$result['storage'] = $storage;
|
2016-03-21 13:20:33 +00:00
|
|
|
$files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 16:36:53 +00:00
|
|
|
return array_map(function (FileInfo $file) {
|
2016-03-21 13:20:33 +00:00
|
|
|
return $this->createNode($file->getPath(), $file);
|
|
|
|
}, $files);
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-11 20:51:30 +00:00
|
|
|
* @param int $id
|
2013-09-10 17:44:23 +00:00
|
|
|
* @return \OC\Files\Node\Node[]
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function getById($id) {
|
2016-09-18 16:36:53 +00:00
|
|
|
$mountCache = $this->root->getUserMountCache();
|
2017-04-21 15:11:26 +00:00
|
|
|
if (strpos($this->getPath(), '/', 1) > 0) {
|
|
|
|
list(, $user) = explode('/', $this->getPath());
|
|
|
|
} else {
|
|
|
|
$user = null;
|
|
|
|
}
|
|
|
|
$mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user);
|
2014-08-05 14:58:10 +00:00
|
|
|
$mounts = $this->root->getMountsIn($this->path);
|
|
|
|
$mounts[] = $this->root->getMount($this->path);
|
2016-09-18 16:36:53 +00:00
|
|
|
/** @var IMountPoint[] $folderMounts */
|
|
|
|
$folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) {
|
|
|
|
return $mountPoint->getMountPoint();
|
|
|
|
}, $mounts), $mounts);
|
2014-08-05 14:58:10 +00:00
|
|
|
|
2016-09-18 16:36:53 +00:00
|
|
|
/** @var ICachedMountInfo[] $mountsContainingFile */
|
|
|
|
$mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) {
|
|
|
|
return isset($folderMounts[$cachedMountInfo->getMountPoint()]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (count($mountsContainingFile) === 0) {
|
|
|
|
return [];
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
2016-09-18 16:36:53 +00:00
|
|
|
|
2018-03-19 21:05:04 +00:00
|
|
|
$nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) {
|
2016-09-18 16:36:53 +00:00
|
|
|
$mount = $folderMounts[$cachedMountInfo->getMountPoint()];
|
2018-03-19 21:05:04 +00:00
|
|
|
$cacheEntry = $mount->getStorage()->getCache()->get((int)$id);
|
|
|
|
if (!$cacheEntry) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cache jails will hide the "true" internal path
|
|
|
|
$internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/');
|
2016-09-18 16:36:53 +00:00
|
|
|
$pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath()));
|
|
|
|
$pathRelativeToMount = ltrim($pathRelativeToMount, '/');
|
|
|
|
$absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount;
|
|
|
|
return $this->root->createNode($absolutePath, new \OC\Files\FileInfo(
|
|
|
|
$absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
|
|
|
|
\OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
|
|
|
|
));
|
|
|
|
}, $mountsContainingFile);
|
|
|
|
|
2018-03-19 21:05:04 +00:00
|
|
|
$nodes = array_filter($nodes);
|
|
|
|
|
2016-09-18 16:36:53 +00:00
|
|
|
return array_filter($nodes, function (Node $node) {
|
|
|
|
return $this->getRelativePath($node->getPath());
|
|
|
|
});
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getFreeSpace() {
|
|
|
|
return $this->view->free_space($this->path);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete() {
|
2014-11-25 15:28:41 +00:00
|
|
|
if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
|
2013-09-01 17:47:48 +00:00
|
|
|
$this->sendHooks(array('preDelete'));
|
2015-12-01 12:22:58 +00:00
|
|
|
$fileInfo = $this->getFileInfo();
|
2013-09-01 17:47:48 +00:00
|
|
|
$this->view->rmdir($this->path);
|
2015-12-01 12:22:58 +00:00
|
|
|
$nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo);
|
2013-09-01 17:47:48 +00:00
|
|
|
$this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
|
|
|
|
$this->exists = false;
|
|
|
|
} else {
|
2016-10-24 09:32:17 +00:00
|
|
|
throw new NotPermittedException('No delete permission for path');
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 14:00:36 +00:00
|
|
|
/**
|
|
|
|
* Add a suffix to the name in case the file exists
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return string
|
|
|
|
* @throws NotPermittedException
|
|
|
|
*/
|
|
|
|
public function getNonExistingName($name) {
|
|
|
|
$uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view);
|
|
|
|
return trim($this->getRelativePath($uniqueName), '/');
|
|
|
|
}
|
2016-07-22 12:37:37 +00:00
|
|
|
|
|
|
|
/**
|
2016-07-22 11:58:53 +00:00
|
|
|
* @param int $limit
|
|
|
|
* @param int $offset
|
2016-07-22 12:37:37 +00:00
|
|
|
* @return \OCP\Files\Node[]
|
|
|
|
*/
|
2016-07-22 11:58:53 +00:00
|
|
|
public function getRecent($limit, $offset = 0) {
|
2016-07-22 12:37:37 +00:00
|
|
|
$mimetypeLoader = \OC::$server->getMimeTypeLoader();
|
|
|
|
$mounts = $this->root->getMountsIn($this->path);
|
|
|
|
$mounts[] = $this->getMountPoint();
|
|
|
|
|
|
|
|
$mounts = array_filter($mounts, function (IMountPoint $mount) {
|
|
|
|
return $mount->getStorage();
|
|
|
|
});
|
|
|
|
$storageIds = array_map(function (IMountPoint $mount) {
|
|
|
|
return $mount->getStorage()->getCache()->getNumericStorageId();
|
|
|
|
}, $mounts);
|
|
|
|
/** @var IMountPoint[] $mountMap */
|
|
|
|
$mountMap = array_combine($storageIds, $mounts);
|
|
|
|
$folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER);
|
|
|
|
|
|
|
|
//todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc)
|
|
|
|
|
|
|
|
$builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
|
|
|
$query = $builder
|
|
|
|
->select('f.*')
|
|
|
|
->from('filecache', 'f')
|
|
|
|
->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY)))
|
|
|
|
->andWhere($builder->expr()->orX(
|
|
|
|
// handle non empty folders separate
|
|
|
|
$builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)),
|
|
|
|
$builder->expr()->eq('f.size', new Literal(0))
|
|
|
|
))
|
2016-07-22 11:58:53 +00:00
|
|
|
->orderBy('f.mtime', 'DESC')
|
|
|
|
->setMaxResults($limit)
|
|
|
|
->setFirstResult($offset);
|
2016-07-22 12:37:37 +00:00
|
|
|
|
|
|
|
$result = $query->execute()->fetchAll();
|
|
|
|
|
2016-07-22 11:58:53 +00:00
|
|
|
$files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) {
|
2016-07-22 12:37:37 +00:00
|
|
|
$mount = $mountMap[$entry['storage']];
|
|
|
|
$entry['internalPath'] = $entry['path'];
|
|
|
|
$entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']);
|
|
|
|
$entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']);
|
|
|
|
$path = $this->getAbsolutePath($mount, $entry['path']);
|
|
|
|
if (is_null($path)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount);
|
|
|
|
return $this->root->createNode($fileInfo->getPath(), $fileInfo);
|
|
|
|
}, $result));
|
|
|
|
|
|
|
|
return array_values(array_filter($files, function (Node $node) {
|
|
|
|
$relative = $this->getRelativePath($node->getPath());
|
|
|
|
return $relative !== null && $relative !== '/';
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAbsolutePath(IMountPoint $mount, $path) {
|
|
|
|
$storage = $mount->getStorage();
|
|
|
|
if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) {
|
|
|
|
/** @var \OC\Files\Storage\Wrapper\Jail $storage */
|
2017-04-12 12:55:47 +00:00
|
|
|
$jailRoot = $storage->getUnjailedPath('');
|
2016-07-22 12:37:37 +00:00
|
|
|
$rootLength = strlen($jailRoot) + 1;
|
|
|
|
if ($path === $jailRoot) {
|
|
|
|
return $mount->getMountPoint();
|
|
|
|
} else if (substr($path, 0, $rootLength) === $jailRoot . '/') {
|
|
|
|
return $mount->getMountPoint() . substr($path, $rootLength);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $mount->getMountPoint() . $path;
|
|
|
|
}
|
|
|
|
}
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|