Merge pull request #15748 from owncloud/fixing-enc-filesize-once-more
Introduce Storage::getData() to allow storage implementations more contr...
This commit is contained in:
commit
a13088818a
|
@ -77,7 +77,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
* @return mixed directory contents if $list is true, file metadata if $list is
|
* @return mixed directory contents if $list is true, file metadata if $list is
|
||||||
* false, null if the file doesn't exist or "false" if the operation failed
|
* false, null if the file doesn't exist or "false" if the operation failed
|
||||||
*/
|
*/
|
||||||
private function getMetaData($path, $list = false) {
|
private function getDropBoxMetaData($path, $list = false) {
|
||||||
$path = $this->root.$path;
|
$path = $this->root.$path;
|
||||||
if ( ! $list && isset($this->metaData[$path])) {
|
if ( ! $list && isset($this->metaData[$path])) {
|
||||||
return $this->metaData[$path];
|
return $this->metaData[$path];
|
||||||
|
@ -150,7 +150,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function opendir($path) {
|
public function opendir($path) {
|
||||||
$contents = $this->getMetaData($path, true);
|
$contents = $this->getDropBoxMetaData($path, true);
|
||||||
if ($contents !== false) {
|
if ($contents !== false) {
|
||||||
$files = array();
|
$files = array();
|
||||||
foreach ($contents as $file) {
|
foreach ($contents as $file) {
|
||||||
|
@ -163,7 +163,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stat($path) {
|
public function stat($path) {
|
||||||
$metaData = $this->getMetaData($path);
|
$metaData = $this->getDropBoxMetaData($path);
|
||||||
if ($metaData) {
|
if ($metaData) {
|
||||||
$stat['size'] = $metaData['bytes'];
|
$stat['size'] = $metaData['bytes'];
|
||||||
$stat['atime'] = time();
|
$stat['atime'] = time();
|
||||||
|
@ -177,7 +177,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
if ($path == '' || $path == '/') {
|
if ($path == '' || $path == '/') {
|
||||||
return 'dir';
|
return 'dir';
|
||||||
} else {
|
} else {
|
||||||
$metaData = $this->getMetaData($path);
|
$metaData = $this->getDropBoxMetaData($path);
|
||||||
if ($metaData) {
|
if ($metaData) {
|
||||||
if ($metaData['is_dir'] == 'true') {
|
if ($metaData['is_dir'] == 'true') {
|
||||||
return 'dir';
|
return 'dir';
|
||||||
|
@ -193,7 +193,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
if ($path == '' || $path == '/') {
|
if ($path == '' || $path == '/') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($this->getMetaData($path)) {
|
if ($this->getDropBoxMetaData($path)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -213,7 +213,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
public function rename($path1, $path2) {
|
public function rename($path1, $path2) {
|
||||||
try {
|
try {
|
||||||
// overwrite if target file exists and is not a directory
|
// overwrite if target file exists and is not a directory
|
||||||
$destMetaData = $this->getMetaData($path2);
|
$destMetaData = $this->getDropBoxMetaData($path2);
|
||||||
if (isset($destMetaData) && $destMetaData !== false && !$destMetaData['is_dir']) {
|
if (isset($destMetaData) && $destMetaData !== false && !$destMetaData['is_dir']) {
|
||||||
$this->unlink($path2);
|
$this->unlink($path2);
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
if ($this->filetype($path) == 'dir') {
|
if ($this->filetype($path) == 'dir') {
|
||||||
return 'httpd/unix-directory';
|
return 'httpd/unix-directory';
|
||||||
} else {
|
} else {
|
||||||
$metaData = $this->getMetaData($path);
|
$metaData = $this->getDropBoxMetaData($path);
|
||||||
if ($metaData) {
|
if ($metaData) {
|
||||||
return $metaData['mime_type'];
|
return $metaData['mime_type'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,23 +103,10 @@ class Scanner extends BasicEmitter {
|
||||||
* @return array an array of metadata of the file
|
* @return array an array of metadata of the file
|
||||||
*/
|
*/
|
||||||
public function getData($path) {
|
public function getData($path) {
|
||||||
$permissions = $this->storage->getPermissions($path);
|
$data = $this->storage->getMetaData($path);
|
||||||
if (!$permissions & \OCP\PERMISSION_READ) {
|
if (is_null($data)) {
|
||||||
//cant read, nothing we can do
|
|
||||||
\OCP\Util::writeLog('OC\Files\Cache\Scanner', "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('OC\Files\Cache\Scanner', "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
$data = array();
|
|
||||||
$data['mimetype'] = $this->storage->getMimeType($path);
|
|
||||||
$data['mtime'] = $this->storage->filemtime($path);
|
|
||||||
if ($data['mimetype'] == 'httpd/unix-directory') {
|
|
||||||
$data['size'] = -1; //unknown
|
|
||||||
} else {
|
|
||||||
$data['size'] = $this->storage->filesize($path);
|
|
||||||
}
|
|
||||||
$data['etag'] = $this->storage->getETag($path);
|
|
||||||
$data['storage_mtime'] = $data['mtime'];
|
|
||||||
$data['permissions'] = $permissions;
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -580,4 +580,29 @@ abstract class Common implements Storage {
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function getMetaData($path) {
|
||||||
|
$permissions = $this->getPermissions($path);
|
||||||
|
if (!$permissions & \OCP\Constants::PERMISSION_READ) {
|
||||||
|
//cant read, nothing we can do
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data['mimetype'] = $this->getMimeType($path);
|
||||||
|
$data['mtime'] = $this->filemtime($path);
|
||||||
|
if ($data['mimetype'] == 'httpd/unix-directory') {
|
||||||
|
$data['size'] = -1; //unknown
|
||||||
|
} else {
|
||||||
|
$data['size'] = $this->filesize($path);
|
||||||
|
}
|
||||||
|
$data['etag'] = $this->getETag($path);
|
||||||
|
$data['storage_mtime'] = $data['mtime'];
|
||||||
|
$data['permissions'] = $this->getPermissions($path);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,4 +70,10 @@ interface Storage extends \OCP\Files\Storage {
|
||||||
*/
|
*/
|
||||||
public function getStorageCache();
|
public function getStorageCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getMetaData($path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
namespace OC\Files\Storage\Wrapper;
|
namespace OC\Files\Storage\Wrapper;
|
||||||
|
|
||||||
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
||||||
|
use OC\Encryption\File;
|
||||||
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\Storage\LocalTempFileTrait;
|
use OC\Files\Storage\LocalTempFileTrait;
|
||||||
use OCP\Files\Mount\IMountPoint;
|
use OCP\Files\Mount\IMountPoint;
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ class Encryption extends Wrapper {
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $unencryptedSize;
|
private $unencryptedSize;
|
||||||
|
|
||||||
/** @var \OC\Encryption\File */
|
/** @var File */
|
||||||
private $fileHelper;
|
private $fileHelper;
|
||||||
|
|
||||||
/** @var IMountPoint */
|
/** @var IMountPoint */
|
||||||
|
@ -59,7 +61,7 @@ class Encryption extends Wrapper {
|
||||||
* @param \OC\Encryption\Manager $encryptionManager
|
* @param \OC\Encryption\Manager $encryptionManager
|
||||||
* @param \OC\Encryption\Util $util
|
* @param \OC\Encryption\Util $util
|
||||||
* @param \OC\Log $logger
|
* @param \OC\Log $logger
|
||||||
* @param \OC\Encryption\File $fileHelper
|
* @param File $fileHelper
|
||||||
* @param string $uid user who perform the read/write operation (null for public access)
|
* @param string $uid user who perform the read/write operation (null for public access)
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -67,7 +69,7 @@ class Encryption extends Wrapper {
|
||||||
\OC\Encryption\Manager $encryptionManager = null,
|
\OC\Encryption\Manager $encryptionManager = null,
|
||||||
\OC\Encryption\Util $util = null,
|
\OC\Encryption\Util $util = null,
|
||||||
\OC\Log $logger = null,
|
\OC\Log $logger = null,
|
||||||
\OC\Encryption\File $fileHelper = null,
|
File $fileHelper = null,
|
||||||
$uid = null
|
$uid = null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -110,6 +112,30 @@ class Encryption extends Wrapper {
|
||||||
return $this->storage->filesize($path);
|
return $this->storage->filesize($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getMetaData($path) {
|
||||||
|
$data = $this->storage->getMetaData($path);
|
||||||
|
if (is_null($data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$fullPath = $this->getFullPath($path);
|
||||||
|
|
||||||
|
if (isset($this->unencryptedSize[$fullPath])) {
|
||||||
|
$data['encrypted'] = true;
|
||||||
|
$data['size'] = $this->unencryptedSize[$fullPath];
|
||||||
|
} else {
|
||||||
|
$info = $this->getCache()->get($path);
|
||||||
|
if (isset($info['fileid']) && $info['encrypted']) {
|
||||||
|
$data['encrypted'] = true;
|
||||||
|
$data['size'] = $info['size'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* see http://php.net/manual/en/function.file_get_contents.php
|
* see http://php.net/manual/en/function.file_get_contents.php
|
||||||
*
|
*
|
||||||
|
@ -360,7 +386,7 @@ class Encryption extends Wrapper {
|
||||||
* @return string full path including mount point
|
* @return string full path including mount point
|
||||||
*/
|
*/
|
||||||
protected function getFullPath($path) {
|
protected function getFullPath($path) {
|
||||||
return \OC\Files\Filesystem::normalizePath($this->mountPoint . '/' . $path);
|
return Filesystem::normalizePath($this->mountPoint . '/' . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -525,4 +525,12 @@ class Wrapper implements \OC\Files\Storage\Storage {
|
||||||
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
||||||
return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getMetaData($path) {
|
||||||
|
return $this->storage->getMetaData($path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue