2012-12-16 00:44:46 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Christopher Schäpers <kondou@ts.unde.re>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Michael Gapczynski <GapczynskiM@gmail.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
2015-10-26 12:54:55 +00:00
|
|
|
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2013-01-28 20:25:19 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2013-01-28 20:25:19 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* 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.
|
2013-01-28 20:25:19 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2013-01-28 20:25:19 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 10:44:34 +00:00
|
|
|
* 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-01-28 20:25:19 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2012-12-16 00:44:46 +00:00
|
|
|
namespace OC\Files\Cache;
|
2014-03-28 14:26:15 +00:00
|
|
|
|
2015-10-22 15:04:36 +00:00
|
|
|
use OC\User\NoUserException;
|
2013-09-24 08:37:58 +00:00
|
|
|
use OCP\Share_Backend_Collection;
|
2012-12-16 00:44:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Metadata cache for shared files
|
|
|
|
*
|
|
|
|
* don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
|
|
|
|
*/
|
|
|
|
class Shared_Cache extends Cache {
|
|
|
|
|
2013-02-20 01:42:48 +00:00
|
|
|
private $storage;
|
2012-12-16 00:44:46 +00:00
|
|
|
private $files = array();
|
|
|
|
|
2014-02-06 15:30:58 +00:00
|
|
|
/**
|
|
|
|
* @param \OC\Files\Storage\Shared $storage
|
|
|
|
*/
|
2012-12-28 20:06:12 +00:00
|
|
|
public function __construct($storage) {
|
2015-09-03 18:48:42 +00:00
|
|
|
parent::__construct($storage);
|
2013-02-20 01:42:48 +00:00
|
|
|
$this->storage = $storage;
|
2012-12-28 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-16 00:44:46 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Get the source cache of a shared file or folder
|
2014-08-06 11:38:14 +00:00
|
|
|
*
|
2013-01-28 20:25:19 +00:00
|
|
|
* @param string $target Shared target file path
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return \OC\Files\Cache\Cache|false
|
2013-01-28 20:25:19 +00:00
|
|
|
*/
|
2012-12-16 00:44:46 +00:00
|
|
|
private function getSourceCache($target) {
|
2014-04-08 17:57:07 +00:00
|
|
|
if ($target === false || $target === $this->storage->getMountPoint()) {
|
2014-04-02 10:04:51 +00:00
|
|
|
$target = '';
|
|
|
|
}
|
2015-08-05 13:41:29 +00:00
|
|
|
$source = \OC_Share_Backend_File::getSource($target, $this->storage->getShare());
|
2013-03-08 19:27:30 +00:00
|
|
|
if (isset($source['path']) && isset($source['fileOwner'])) {
|
2015-10-22 15:04:36 +00:00
|
|
|
try {
|
|
|
|
\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
|
|
|
|
} catch(NoUserException $e) {
|
|
|
|
\OC::$server->getLogger()->logException($e, ['app' => 'files_sharing']);
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-15 14:36:05 +00:00
|
|
|
$mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
|
2014-04-21 10:35:52 +00:00
|
|
|
if (is_array($mounts) and !empty($mounts)) {
|
2014-04-15 14:36:05 +00:00
|
|
|
$fullPath = $mounts[0]->getMountPoint() . $source['path'];
|
2013-03-08 19:27:30 +00:00
|
|
|
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
|
|
|
|
if ($storage) {
|
|
|
|
$this->files[$target] = $internalPath;
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
$this->storageId = $storage->getId();
|
|
|
|
$this->numericId = $cache->getNumericStorageId();
|
|
|
|
return $cache;
|
|
|
|
}
|
2012-12-28 20:06:12 +00:00
|
|
|
}
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-02 21:47:11 +00:00
|
|
|
public function getNumericStorageId() {
|
|
|
|
if (isset($this->numericId)) {
|
|
|
|
return $this->numericId;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-16 00:44:46 +00:00
|
|
|
/**
|
|
|
|
* get the stored metadata of a file or folder
|
|
|
|
*
|
2014-05-15 12:19:32 +00:00
|
|
|
* @param string|int $file
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return array|false
|
2012-12-16 00:44:46 +00:00
|
|
|
*/
|
|
|
|
public function get($file) {
|
2015-09-03 18:48:42 +00:00
|
|
|
$mimetypeLoader = \OC::$server->getMimeTypeLoader();
|
2014-04-04 15:45:53 +00:00
|
|
|
if (is_string($file)) {
|
2014-04-30 15:30:22 +00:00
|
|
|
$cache = $this->getSourceCache($file);
|
|
|
|
if ($cache) {
|
2014-04-08 14:37:34 +00:00
|
|
|
$data = $cache->get($this->files[$file]);
|
2014-12-02 14:28:11 +00:00
|
|
|
if ($data) {
|
|
|
|
$data['displayname_owner'] = \OC_User::getDisplayName($this->storage->getSharedFrom());
|
|
|
|
$data['path'] = $file;
|
|
|
|
if ($file === '') {
|
|
|
|
$data['is_share_mount_point'] = true;
|
|
|
|
}
|
|
|
|
$data['uid_owner'] = $this->storage->getOwner($file);
|
|
|
|
if (isset($data['permissions'])) {
|
|
|
|
$data['permissions'] &= $this->storage->getPermissions($file);
|
|
|
|
} else {
|
|
|
|
$data['permissions'] = $this->storage->getPermissions($file);
|
|
|
|
}
|
2014-06-05 11:24:41 +00:00
|
|
|
}
|
2014-04-08 14:37:34 +00:00
|
|
|
return $data;
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-30 15:30:22 +00:00
|
|
|
$sourceId = $file;
|
2014-04-04 16:32:49 +00:00
|
|
|
// if we are at the root of the mount point we want to return the
|
|
|
|
// cache information for the source item
|
2014-04-30 15:30:22 +00:00
|
|
|
if (!is_int($sourceId) || $sourceId === 0) {
|
|
|
|
$sourceId = $this->storage->getSourceId();
|
2014-04-04 16:32:49 +00:00
|
|
|
}
|
2015-04-08 13:21:52 +00:00
|
|
|
$query = \OCP\DB::prepare(
|
2013-02-14 21:37:49 +00:00
|
|
|
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`,'
|
2015-03-30 15:29:05 +00:00
|
|
|
. ' `size`, `mtime`, `encrypted`, `storage_mtime`, `etag`, `permissions`'
|
2014-03-28 14:26:15 +00:00
|
|
|
. ' FROM `*PREFIX*filecache` WHERE `fileid` = ?');
|
2014-04-30 15:30:22 +00:00
|
|
|
$result = $query->execute(array($sourceId));
|
2012-12-16 00:44:46 +00:00
|
|
|
$data = $result->fetchRow();
|
|
|
|
$data['fileid'] = (int)$data['fileid'];
|
|
|
|
$data['mtime'] = (int)$data['mtime'];
|
2013-10-25 10:39:21 +00:00
|
|
|
$data['storage_mtime'] = (int)$data['storage_mtime'];
|
2012-12-16 00:44:46 +00:00
|
|
|
$data['encrypted'] = (bool)$data['encrypted'];
|
2015-09-03 18:48:42 +00:00
|
|
|
$data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']);
|
|
|
|
$data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']);
|
2013-11-04 20:23:10 +00:00
|
|
|
if ($data['storage_mtime'] === 0) {
|
2013-10-25 10:39:21 +00:00
|
|
|
$data['storage_mtime'] = $data['mtime'];
|
|
|
|
}
|
2015-03-30 15:29:05 +00:00
|
|
|
$data['size'] = (int)$data['size'];
|
2014-06-03 15:57:56 +00:00
|
|
|
$data['permissions'] = (int)$data['permissions'];
|
2014-04-25 12:04:22 +00:00
|
|
|
if (!is_int($file) || $file === 0) {
|
|
|
|
$data['path'] = '';
|
2014-04-30 15:30:22 +00:00
|
|
|
$data['name'] = basename($this->storage->getMountPoint());
|
2014-04-17 13:54:45 +00:00
|
|
|
$data['is_share_mount_point'] = true;
|
2014-04-04 16:32:49 +00:00
|
|
|
}
|
2014-06-09 10:47:00 +00:00
|
|
|
$data['permissions'] &= $this->storage->getPermissions('');
|
2012-12-16 00:44:46 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the metadata of all files stored in $folder
|
|
|
|
*
|
2014-10-16 13:17:12 +00:00
|
|
|
* @param string $folderId
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return array|false
|
2012-12-16 00:44:46 +00:00
|
|
|
*/
|
2014-10-16 13:17:12 +00:00
|
|
|
public function getFolderContentsById($folderId) {
|
|
|
|
$cache = $this->getSourceCache('');
|
2014-04-02 10:04:51 +00:00
|
|
|
if ($cache) {
|
2014-10-16 13:17:12 +00:00
|
|
|
$owner = $this->storage->getSharedFrom();
|
|
|
|
$parentPath = $this->getPathById($folderId);
|
|
|
|
if ($parentPath !== '') {
|
|
|
|
$parentPath .= '/';
|
|
|
|
}
|
|
|
|
$sourceFolderContent = $cache->getFolderContentsById($folderId);
|
|
|
|
foreach ($sourceFolderContent as &$c) {
|
|
|
|
$c['path'] = ltrim($parentPath . $c['name'], '/');
|
|
|
|
$c['uid_owner'] = $owner;
|
|
|
|
$c['displayname_owner'] = \OC_User::getDisplayName($owner);
|
|
|
|
$c['permissions'] = $c['permissions'] & $this->storage->getPermissions(false);
|
2012-12-28 20:06:12 +00:00
|
|
|
}
|
2014-04-02 10:04:51 +00:00
|
|
|
|
|
|
|
return $sourceFolderContent;
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
2014-04-02 10:04:51 +00:00
|
|
|
|
2012-12-28 20:06:12 +00:00
|
|
|
return false;
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store meta data for a file or folder
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param array $data
|
|
|
|
*
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return int|false file id
|
2012-12-16 00:44:46 +00:00
|
|
|
*/
|
|
|
|
public function put($file, array $data) {
|
2014-04-11 09:18:50 +00:00
|
|
|
$file = ($file === false) ? '' : $file;
|
|
|
|
if ($cache = $this->getSourceCache($file)) {
|
2013-01-01 17:10:38 +00:00
|
|
|
return $cache->put($this->files[$file], $data);
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the file id for a file
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId($file) {
|
2014-04-08 17:57:07 +00:00
|
|
|
if ($file === false) {
|
|
|
|
return $this->storage->getSourceId();
|
|
|
|
}
|
|
|
|
$cache = $this->getSourceCache($file);
|
|
|
|
if ($cache) {
|
2012-12-16 00:44:46 +00:00
|
|
|
return $cache->getId($this->files[$file]);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-08 01:52:51 +00:00
|
|
|
/**
|
|
|
|
* check if a file is available in the cache
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function inCache($file) {
|
|
|
|
if ($file == '') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parent::inCache($file);
|
|
|
|
}
|
|
|
|
|
2012-12-16 00:44:46 +00:00
|
|
|
/**
|
|
|
|
* remove a file or folder from the cache
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
*/
|
|
|
|
public function remove($file) {
|
2014-04-11 09:54:14 +00:00
|
|
|
$file = ($file === false) ? '' : $file;
|
2012-12-16 00:44:46 +00:00
|
|
|
if ($cache = $this->getSourceCache($file)) {
|
|
|
|
$cache->remove($this->files[$file]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-04-13 15:09:18 +00:00
|
|
|
* Get the storage id and path needed for a move
|
2012-12-16 00:44:46 +00:00
|
|
|
*
|
2015-04-13 15:09:18 +00:00
|
|
|
* @param string $path
|
|
|
|
* @return array [$storageId, $internalPath]
|
2012-12-16 00:44:46 +00:00
|
|
|
*/
|
2015-04-13 15:09:18 +00:00
|
|
|
protected function getMoveInfo($path) {
|
|
|
|
$cache = $this->getSourceCache($path);
|
2015-08-05 13:41:29 +00:00
|
|
|
$file = \OC_Share_Backend_File::getSource($path, $this->storage->getShare());
|
2015-04-13 15:09:18 +00:00
|
|
|
return [$cache->getNumericStorageId(), $file['path']];
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove all entries for files that are stored on the storage from the cache
|
|
|
|
*/
|
|
|
|
public function clear() {
|
|
|
|
// Not a valid action for Shared Cache
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file
|
|
|
|
*
|
|
|
|
* @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
|
|
|
|
*/
|
|
|
|
public function getStatus($file) {
|
2013-01-01 16:19:33 +00:00
|
|
|
if ($file == '') {
|
|
|
|
return self::COMPLETE;
|
|
|
|
}
|
2012-12-16 00:44:46 +00:00
|
|
|
if ($cache = $this->getSourceCache($file)) {
|
|
|
|
return $cache->getStatus($this->files[$file]);
|
|
|
|
}
|
2013-01-11 03:29:47 +00:00
|
|
|
return self::NOT_FOUND;
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files matching $pattern
|
|
|
|
*
|
|
|
|
* @param string $pattern
|
|
|
|
* @return array of file data
|
|
|
|
*/
|
|
|
|
public function search($pattern) {
|
2013-07-26 12:11:59 +00:00
|
|
|
|
2014-08-06 11:38:14 +00:00
|
|
|
$pattern = trim($pattern, '%');
|
2013-10-30 14:48:38 +00:00
|
|
|
|
2014-07-30 11:46:02 +00:00
|
|
|
$normalizedPattern = $this->normalize($pattern);
|
2013-07-26 12:11:59 +00:00
|
|
|
|
2014-07-30 11:46:02 +00:00
|
|
|
$result = array();
|
|
|
|
$exploreDirs = array('');
|
|
|
|
while (count($exploreDirs) > 0) {
|
|
|
|
$dir = array_pop($exploreDirs);
|
|
|
|
$files = $this->getFolderContents($dir);
|
|
|
|
// no results?
|
|
|
|
if (!$files) {
|
|
|
|
// maybe it's a single shared file
|
|
|
|
$file = $this->get('');
|
|
|
|
if ($normalizedPattern === '' || stristr($file['name'], $normalizedPattern) !== false) {
|
|
|
|
$result[] = $file;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($normalizedPattern === '' || stristr($file['name'], $normalizedPattern) !== false) {
|
|
|
|
$result[] = $file;
|
|
|
|
}
|
|
|
|
if ($file['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$exploreDirs[] = ltrim($dir . '/' . $file['name'], '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
2013-07-31 13:13:00 +00:00
|
|
|
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files by mimetype
|
|
|
|
*
|
2013-10-30 14:48:38 +00:00
|
|
|
* @param string $mimetype
|
2012-12-16 00:44:46 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function searchByMime($mimetype) {
|
2014-02-05 11:00:08 +00:00
|
|
|
$mimepart = null;
|
|
|
|
if (strpos($mimetype, '/') === false) {
|
|
|
|
$mimepart = $mimetype;
|
|
|
|
$mimetype = null;
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
2013-10-30 14:48:38 +00:00
|
|
|
|
2014-02-05 11:00:08 +00:00
|
|
|
$result = array();
|
|
|
|
$exploreDirs = array('');
|
|
|
|
while (count($exploreDirs) > 0) {
|
|
|
|
$dir = array_pop($exploreDirs);
|
|
|
|
$files = $this->getFolderContents($dir);
|
|
|
|
// no results?
|
|
|
|
if (!$files) {
|
2014-04-25 10:28:10 +00:00
|
|
|
// maybe it's a single shared file
|
|
|
|
$file = $this->get('');
|
|
|
|
if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) {
|
|
|
|
$result[] = $file;
|
|
|
|
}
|
2014-02-05 11:00:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$exploreDirs[] = ltrim($dir . '/' . $file['name'], '/');
|
2014-03-28 14:26:15 +00:00
|
|
|
} else if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) {
|
2014-02-05 11:00:08 +00:00
|
|
|
$result[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
2013-10-30 14:48:38 +00:00
|
|
|
}
|
2014-01-22 15:54:17 +00:00
|
|
|
|
2014-12-18 16:27:56 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given file has the given tag.
|
|
|
|
*
|
|
|
|
* @param \OCP\ITags $tagger
|
|
|
|
* @param array $fileData file data
|
|
|
|
* @param string $tag tag to check for
|
|
|
|
* @return boolean true if the given file has the expected tag,
|
|
|
|
* false otherwise
|
|
|
|
*/
|
|
|
|
private function hasTag($tagger, $fileData, $tag) {
|
|
|
|
$tags = $tagger->getTagsForObjects(array((int)$fileData['fileid']));
|
|
|
|
return (!empty($tags) && in_array($tag, current($tags)));
|
|
|
|
}
|
|
|
|
|
2014-12-04 13:01:15 +00:00
|
|
|
/**
|
|
|
|
* search for files by tag
|
|
|
|
*
|
|
|
|
* @param string|int $tag tag to search for
|
|
|
|
* @param string $userId owner of the tags
|
|
|
|
* @return array file data
|
|
|
|
*/
|
2014-12-12 10:18:35 +00:00
|
|
|
public function searchByTag($tag, $userId) {
|
2014-12-04 13:01:15 +00:00
|
|
|
// TODO: inject this
|
|
|
|
$tagger = \OC::$server->getTagManager()->load('files', null, null, $userId);
|
|
|
|
$result = array();
|
|
|
|
$exploreDirs = array('');
|
2014-12-18 16:27:56 +00:00
|
|
|
// check if root is tagged
|
|
|
|
$file = $this->get('');
|
|
|
|
if ($this->hasTag($tagger, $file, $tag)) {
|
|
|
|
$result[] = $file;
|
|
|
|
}
|
2014-12-04 13:01:15 +00:00
|
|
|
// FIXME: this is so wrong and unefficient, need to replace with actual DB queries
|
|
|
|
while (count($exploreDirs) > 0) {
|
|
|
|
$dir = array_pop($exploreDirs);
|
|
|
|
$files = $this->getFolderContents($dir);
|
|
|
|
if (!$files) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($files as $file) {
|
2014-12-18 16:27:56 +00:00
|
|
|
if ($this->hasTag($tagger, $file, $tag)) {
|
|
|
|
$result[] = $file;
|
|
|
|
}
|
2014-12-04 13:01:15 +00:00
|
|
|
if ($file['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$exploreDirs[] = ltrim($dir . '/' . $file['name'], '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2015-03-05 21:23:47 +00:00
|
|
|
/**
|
|
|
|
* update the folder size and the size of all parent folders
|
|
|
|
*
|
|
|
|
* @param string|boolean $path
|
|
|
|
* @param array $data (optional) meta data of the folder
|
|
|
|
*/
|
|
|
|
public function correctFolderSize($path, $data = null) {
|
|
|
|
$this->calculateFolderSize($path, $data);
|
|
|
|
if ($path !== '') {
|
|
|
|
$parent = dirname($path);
|
|
|
|
if ($parent === '.' or $parent === '/') {
|
|
|
|
$parent = '';
|
|
|
|
}
|
|
|
|
$this->correctFolderSize($parent);
|
|
|
|
} else {
|
|
|
|
// bubble up to source cache
|
|
|
|
$sourceCache = $this->getSourceCache($path);
|
2015-04-07 14:02:37 +00:00
|
|
|
if (isset($this->files[$path])) {
|
|
|
|
$parent = dirname($this->files[$path]);
|
|
|
|
if ($sourceCache) {
|
|
|
|
$sourceCache->correctFolderSize($parent);
|
|
|
|
}
|
2015-04-01 14:12:01 +00:00
|
|
|
}
|
2015-03-05 21:23:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-16 00:44:46 +00:00
|
|
|
/**
|
|
|
|
* get the size of a folder and set it in the cache
|
|
|
|
*
|
|
|
|
* @param string $path
|
2014-02-28 13:23:07 +00:00
|
|
|
* @param array $entry (optional) meta data of the folder
|
2012-12-16 00:44:46 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-02-28 13:23:07 +00:00
|
|
|
public function calculateFolderSize($path, $entry = null) {
|
2014-04-11 09:18:50 +00:00
|
|
|
$path = ($path === false) ? '' : $path;
|
2012-12-16 00:44:46 +00:00
|
|
|
if ($cache = $this->getSourceCache($path)) {
|
|
|
|
return $cache->calculateFolderSize($this->files[$path]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get all file ids on the files on the storage
|
|
|
|
*
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
public function getAll() {
|
2013-08-28 10:39:43 +00:00
|
|
|
$ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL);
|
|
|
|
$folderBackend = \OCP\Share::getBackend('folder');
|
2013-09-24 08:37:58 +00:00
|
|
|
if ($folderBackend instanceof Share_Backend_Collection) {
|
|
|
|
foreach ($ids as $file) {
|
|
|
|
/** @var $folderBackend Share_Backend_Collection */
|
|
|
|
$children = $folderBackend->getChildren($file);
|
|
|
|
foreach ($children as $child) {
|
|
|
|
$ids[] = (int)$child['source'];
|
|
|
|
}
|
|
|
|
|
2013-08-28 10:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-24 08:37:58 +00:00
|
|
|
|
2013-08-28 10:39:43 +00:00
|
|
|
return $ids;
|
2012-12-16 00:44:46 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 21:47:11 +00:00
|
|
|
/**
|
|
|
|
* find a folder in the cache which has not been fully scanned
|
|
|
|
*
|
|
|
|
* If multiply incomplete folders are in the cache, the one with the highest id will be returned,
|
|
|
|
* use the one with the highest id gives the best result with the background scanner, since that is most
|
|
|
|
* likely the folder where we stopped scanning previously
|
|
|
|
*
|
2014-02-19 08:31:54 +00:00
|
|
|
* @return boolean the path of the folder or false when no folder matched
|
2013-05-02 21:47:11 +00:00
|
|
|
*/
|
|
|
|
public function getIncomplete() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-31 12:29:55 +00:00
|
|
|
/**
|
2014-04-15 09:19:31 +00:00
|
|
|
* get the path of a file on this storage relative to the mount point by it's id
|
2014-03-31 12:29:55 +00:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @param string $pathEnd (optional) used internally for recursive calls
|
2014-05-15 20:47:28 +00:00
|
|
|
* @return string|null
|
2014-03-31 12:29:55 +00:00
|
|
|
*/
|
2014-03-28 14:26:15 +00:00
|
|
|
public function getPathById($id, $pathEnd = '') {
|
|
|
|
// direct shares are easy
|
2014-08-06 11:38:14 +00:00
|
|
|
if ($id === $this->storage->getSourceId()) {
|
2014-08-06 12:57:54 +00:00
|
|
|
return ltrim($pathEnd, '/');
|
2014-03-28 14:26:15 +00:00
|
|
|
} else {
|
|
|
|
// if the item is a direct share we try and get the path of the parent and append the name of the item to it
|
|
|
|
list($parent, $name) = $this->getParentInfo($id);
|
|
|
|
if ($parent > 0) {
|
|
|
|
return $this->getPathById($parent, '/' . $name . $pathEnd);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 15:49:27 +00:00
|
|
|
/**
|
|
|
|
* @param integer $id
|
2014-08-06 11:38:14 +00:00
|
|
|
* @return array
|
2014-04-14 15:49:27 +00:00
|
|
|
*/
|
2014-03-28 14:26:15 +00:00
|
|
|
private function getParentInfo($id) {
|
|
|
|
$sql = 'SELECT `parent`, `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
|
2015-04-08 13:21:52 +00:00
|
|
|
$query = \OCP\DB::prepare($sql);
|
2014-03-28 14:26:15 +00:00
|
|
|
$result = $query->execute(array($id));
|
|
|
|
if ($row = $result->fetchRow()) {
|
2014-08-06 11:38:14 +00:00
|
|
|
return array((int)$row['parent'], $row['name']);
|
2014-03-28 14:26:15 +00:00
|
|
|
} else {
|
|
|
|
return array(-1, '');
|
|
|
|
}
|
|
|
|
}
|
2013-08-18 09:02:08 +00:00
|
|
|
}
|