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
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/cache.php')
-rw-r--r--apps/files_sharing/lib/cache.php74
1 files changed, 54 insertions, 20 deletions
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index 425d51113b1..10f2182655f 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -32,6 +32,9 @@ class Shared_Cache extends Cache {
private $storage;
private $files = array();
+ /**
+ * @param \OC\Files\Storage\Shared $storage
+ */
public function __construct($storage) {
$this->storage = $storage;
}
@@ -92,12 +95,11 @@ class Shared_Cache extends Cache {
} else {
$query = \OC_DB::prepare(
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`,'
- .' `size`, `mtime`, `encrypted`'
+ .' `size`, `mtime`, `encrypted`, `unencrypted_size`'
.' FROM `*PREFIX*filecache` WHERE `fileid` = ?');
$result = $query->execute(array($file));
$data = $result->fetchRow();
$data['fileid'] = (int)$data['fileid'];
- $data['size'] = (int)$data['size'];
$data['mtime'] = (int)$data['mtime'];
$data['storage_mtime'] = (int)$data['storage_mtime'];
$data['encrypted'] = (bool)$data['encrypted'];
@@ -106,6 +108,12 @@ class Shared_Cache extends Cache {
if ($data['storage_mtime'] === 0) {
$data['storage_mtime'] = $data['mtime'];
}
+ if ($data['encrypted'] or ($data['unencrypted_size'] > 0 and $data['mimetype'] === 'httpd/unix-directory')) {
+ $data['encrypted_size'] = (int)$data['size'];
+ $data['size'] = (int)$data['unencrypted_size'];
+ } else {
+ $data['size'] = (int)$data['size'];
+ }
return $data;
}
return false;
@@ -123,19 +131,18 @@ class Shared_Cache extends Cache {
foreach ($files as &$file) {
$file['mimetype'] = $this->getMimetype($file['mimetype']);
$file['mimepart'] = $this->getMimetype($file['mimepart']);
+ $file['usersPath'] = 'files/Shared/' . ltrim($file['path'], '/');
}
return $files;
} else {
- if ($cache = $this->getSourceCache($folder)) {
+ $cache = $this->getSourceCache($folder);
+ if ($cache) {
+ $parent = $this->storage->getFile($folder);
$sourceFolderContent = $cache->getFolderContents($this->files[$folder]);
foreach ($sourceFolderContent as $key => $c) {
- $ownerPathParts = explode('/', \OC_Filesystem::normalizePath($c['path']));
- $userPathParts = explode('/', \OC_Filesystem::normalizePath($folder));
- $usersPath = 'files/Shared/'.$userPathParts[1];
- foreach (array_slice($ownerPathParts, 3) as $part) {
- $usersPath .= '/'.$part;
- }
- $sourceFolderContent[$key]['usersPath'] = $usersPath;
+ $sourceFolderContent[$key]['usersPath'] = 'files/Shared/' . $folder . '/' . $c['name'];
+ $sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner'];
+ $sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner'];
}
return $sourceFolderContent;
@@ -259,17 +266,38 @@ class Shared_Cache extends Cache {
* @return array
*/
public function searchByMime($mimetype) {
-
- if (strpos($mimetype, '/')) {
- $where = '`mimetype` = ? AND ';
- } else {
- $where = '`mimepart` = ? AND ';
+ $mimepart = null;
+ if (strpos($mimetype, '/') === false) {
+ $mimepart = $mimetype;
+ $mimetype = null;
}
- $value = $this->getMimetypeId($mimetype);
-
- return $this->searchWithWhere($where, $value);
-
+ // note: searchWithWhere is currently broken as it doesn't
+ // recurse into subdirs nor returns the correct
+ // file paths, so using getFolderContents() for now
+
+ $result = array();
+ $exploreDirs = array('');
+ while (count($exploreDirs) > 0) {
+ $dir = array_pop($exploreDirs);
+ $files = $this->getFolderContents($dir);
+ // no results?
+ if (!$files) {
+ continue;
+ }
+ foreach ($files as $file) {
+ if ($file['mimetype'] === 'httpd/unix-directory') {
+ $exploreDirs[] = ltrim($dir . '/' . $file['name'], '/');
+ }
+ else if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) {
+ // usersPath not reliable
+ //$file['path'] = $file['usersPath'];
+ $file['path'] = ltrim($dir . '/' . $file['name'], '/');
+ $result[] = $file;
+ }
+ }
+ }
+ return $result;
}
/**
@@ -313,6 +341,12 @@ class Shared_Cache extends Cache {
}
$row['mimetype'] = $this->getMimetype($row['mimetype']);
$row['mimepart'] = $this->getMimetype($row['mimepart']);
+ if ($row['encrypted'] or ($row['unencrypted_size'] > 0 and $row['mimetype'] === 'httpd/unix-directory')) {
+ $row['encrypted_size'] = $row['size'];
+ $row['size'] = $row['unencrypted_size'];
+ } else {
+ $row['size'] = $row['size'];
+ }
$files[] = $row;
}
}
@@ -361,7 +395,7 @@ class Shared_Cache extends Cache {
* 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
*
- * @return string|bool the path of the folder or false when no folder matched
+ * @return boolean the path of the folder or false when no folder matched
*/
public function getIncomplete() {
return false;