2011-10-21 19:02:11 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2013-05-20 03:24:36 +04:00
|
|
|
* ownCloud
|
|
|
|
*
|
2014-03-27 16:49:48 +04:00
|
|
|
* @author Bjoern Schiessle, Sam Tuke, Robin Appelman
|
|
|
|
* @copyright 2012 Sam Tuke <samtuke@owncloud.com>
|
|
|
|
* 2012 Robin Appelman <icewind1991@gmail.com>
|
|
|
|
* 2014 Bjoern Schiessle <schiessle@owncloud.com>
|
2013-05-20 03:24:36 +04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2011-10-21 19:02:11 +04:00
|
|
|
|
2013-01-30 22:52:02 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* Encryption proxy which handles filesystem operations before and after
|
2013-05-20 03:24:36 +04:00
|
|
|
* execution and encrypts, and handles keyfiles accordingly. Used for
|
|
|
|
* webui.
|
|
|
|
*/
|
2013-01-30 22:52:02 +04:00
|
|
|
|
2012-10-17 19:35:19 +04:00
|
|
|
namespace OCA\Encryption;
|
2012-07-25 21:28:56 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
/**
|
|
|
|
* Class Proxy
|
|
|
|
* @package OCA\Encryption
|
|
|
|
*/
|
2013-05-27 19:26:58 +04:00
|
|
|
class Proxy extends \OC_FileProxy {
|
2012-07-25 19:25:24 +04:00
|
|
|
|
2014-01-23 18:45:34 +04:00
|
|
|
private static $unencryptedSizes = array(); // remember unencrypted size
|
2014-02-27 16:58:51 +04:00
|
|
|
private static $fopenMode = array(); // remember the fopen mode
|
2014-03-27 16:49:48 +04:00
|
|
|
private static $enableEncryption = false; // Enable encryption for the given path
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-05-21 13:39:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* check if path is excluded from encryption
|
|
|
|
*
|
|
|
|
* @param string $path relative to data/
|
|
|
|
* @param string $uid user
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2014-10-02 14:55:46 +04:00
|
|
|
protected function isExcludedPath($path, $uid) {
|
2014-05-21 13:39:37 +04:00
|
|
|
|
2014-06-10 14:26:43 +04:00
|
|
|
$view = new \OC\Files\View();
|
|
|
|
|
2014-10-02 14:55:46 +04:00
|
|
|
$path = \OC\Files\Filesystem::normalizePath($path);
|
|
|
|
|
|
|
|
// we only encrypt/decrypt files in the files and files_versions folder
|
|
|
|
if(
|
|
|
|
strpos($path, '/' . $uid . '/files/') !== 0 &&
|
|
|
|
strpos($path, '/' . $uid . '/files_versions/') !== 0) {
|
|
|
|
|
2014-05-21 13:39:37 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-10 14:26:43 +04:00
|
|
|
if (!$view->file_exists($path)) {
|
|
|
|
$path = dirname($path);
|
|
|
|
}
|
|
|
|
|
2014-05-21 13:39:37 +04:00
|
|
|
// we don't encrypt server-to-server shares
|
|
|
|
list($storage, ) = \OC\Files\Filesystem::resolvePath($path);
|
2014-06-10 14:38:19 +04:00
|
|
|
/**
|
|
|
|
* @var \OCP\Files\Storage $storage
|
|
|
|
*/
|
|
|
|
if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
|
2014-05-21 13:39:37 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-24 04:44:54 +04:00
|
|
|
/**
|
2012-07-11 20:51:27 +04:00
|
|
|
* Check if a file requires encryption
|
2011-11-24 04:44:54 +04:00
|
|
|
* @param string $path
|
2014-03-27 16:49:48 +04:00
|
|
|
* @param string $mode type of access
|
2011-11-24 04:44:54 +04:00
|
|
|
* @return bool
|
2012-07-11 20:51:27 +04:00
|
|
|
*
|
2014-03-27 16:49:48 +04:00
|
|
|
* Tests if server side encryption is enabled, and if we should call the
|
|
|
|
* crypt stream wrapper for the given file
|
2011-11-24 04:44:54 +04:00
|
|
|
*/
|
2014-05-21 13:39:37 +04:00
|
|
|
private function shouldEncrypt($path, $mode = 'w') {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-11-21 03:23:38 +04:00
|
|
|
$userId = Helper::getUser($path);
|
2014-04-28 16:40:10 +04:00
|
|
|
$session = new Session(new \OC\Files\View());
|
2013-11-21 03:23:38 +04:00
|
|
|
|
2014-03-27 16:49:48 +04:00
|
|
|
// don't call the crypt stream wrapper, if...
|
|
|
|
if (
|
2014-11-04 19:16:36 +03:00
|
|
|
Crypt::mode() !== 'server' // we are not in server-side-encryption mode
|
2014-05-21 13:39:37 +04:00
|
|
|
|| $this->isExcludedPath($path, $userId) // if path is excluded from encryption
|
2014-03-27 16:49:48 +04:00
|
|
|
|| substr($path, 0, 8) === 'crypt://' // we are already in crypt mode
|
|
|
|
) {
|
2012-04-18 18:02:35 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-05-12 18:30:39 +04:00
|
|
|
$view = new \OC\Files\View('');
|
2014-03-27 16:49:48 +04:00
|
|
|
$util = new Util($view, $userId);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-03-27 16:49:48 +04:00
|
|
|
// for write operation we always encrypt the files, for read operations
|
|
|
|
// we check if the existing file is encrypted or not decide if it needs to
|
|
|
|
// decrypt it.
|
|
|
|
if (($mode !== 'r' && $mode !== 'rb') || $util->isEncryptedPath($path)) {
|
2011-11-24 04:44:54 +04:00
|
|
|
return true;
|
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-07-11 20:51:27 +04:00
|
|
|
return false;
|
2011-11-24 04:44:54 +04:00
|
|
|
}
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
/**
|
2014-05-13 15:29:25 +04:00
|
|
|
* @param string $path
|
|
|
|
* @param string $data
|
2013-05-20 03:24:36 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
2013-05-27 19:26:58 +04:00
|
|
|
public function preFile_put_contents($path, &$data) {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-05-21 13:39:37 +04:00
|
|
|
if ($this->shouldEncrypt($path)) {
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-27 19:26:58 +04:00
|
|
|
if (!is_resource($data)) {
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// get root view
|
2014-05-12 18:30:39 +04:00
|
|
|
$view = new \OC\Files\View('/');
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// get relative path
|
|
|
|
$relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
if (!isset($relativePath)) {
|
|
|
|
return true;
|
2013-05-16 02:31:17 +04:00
|
|
|
}
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-11-14 20:32:21 +04:00
|
|
|
// create random cache folder
|
|
|
|
$cacheFolder = rand();
|
2014-05-12 18:20:07 +04:00
|
|
|
$path_slices = explode('/', \OC\Files\Filesystem::normalizePath($path));
|
2013-11-14 20:32:21 +04:00
|
|
|
$path_slices[2] = "cache/".$cacheFolder;
|
|
|
|
$tmpPath = implode('/', $path_slices);
|
|
|
|
|
|
|
|
$handle = fopen('crypt://' . $tmpPath, 'w');
|
2013-05-30 03:13:22 +04:00
|
|
|
if (is_resource($handle)) {
|
2013-04-25 17:20:06 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// write data to stream
|
|
|
|
fwrite($handle, $data);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// close stream
|
|
|
|
fclose($handle);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// get encrypted content
|
2013-11-14 20:32:21 +04:00
|
|
|
$data = $view->file_get_contents($tmpPath);
|
2013-04-18 17:42:28 +04:00
|
|
|
|
2014-01-23 18:45:34 +04:00
|
|
|
// store new unenecrypted size so that it can be updated
|
|
|
|
// in the post proxy
|
2013-12-16 18:24:11 +04:00
|
|
|
$tmpFileInfo = $view->getFileInfo($tmpPath);
|
2014-07-04 18:44:50 +04:00
|
|
|
if ( isset($tmpFileInfo['unencrypted_size']) ) {
|
|
|
|
self::$unencryptedSizes[\OC\Files\Filesystem::normalizePath($path)] = $tmpFileInfo['unencrypted_size'];
|
2014-01-23 18:45:34 +04:00
|
|
|
}
|
2013-12-16 18:24:11 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// remove our temp file
|
2013-11-14 20:32:21 +04:00
|
|
|
$view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
2014-03-28 15:02:49 +04:00
|
|
|
} else {
|
|
|
|
return false;
|
2013-05-30 03:13:22 +04:00
|
|
|
}
|
2011-10-21 19:02:11 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-09 20:09:20 +04:00
|
|
|
return true;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-09 20:09:20 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-01-23 18:45:34 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* update file cache with the new unencrypted size after file was written
|
2014-01-23 18:45:34 +04:00
|
|
|
* @param string $path
|
|
|
|
* @param mixed $result
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function postFile_put_contents($path, $result) {
|
2014-05-12 18:20:07 +04:00
|
|
|
$normalizedPath = \OC\Files\Filesystem::normalizePath($path);
|
2014-01-23 18:45:34 +04:00
|
|
|
if ( isset(self::$unencryptedSizes[$normalizedPath]) ) {
|
2014-05-12 18:30:39 +04:00
|
|
|
$view = new \OC\Files\View('/');
|
2014-01-23 18:45:34 +04:00
|
|
|
$view->putFileInfo($normalizedPath,
|
2014-02-27 22:50:16 +04:00
|
|
|
array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath]));
|
2014-01-23 18:45:34 +04:00
|
|
|
unset(self::$unencryptedSizes[$normalizedPath]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2012-12-11 19:10:56 +04:00
|
|
|
/**
|
|
|
|
* @param string $path Path of file from which has been read
|
|
|
|
* @param string $data Data that has been read from file
|
|
|
|
*/
|
2013-05-27 19:26:58 +04:00
|
|
|
public function postFile_get_contents($path, $data) {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
$plainData = null;
|
2014-05-12 18:30:39 +04:00
|
|
|
$view = new \OC\Files\View('/');
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
// If data is a catfile
|
|
|
|
if (
|
2013-05-27 22:44:38 +04:00
|
|
|
Crypt::mode() === 'server'
|
2013-05-27 19:26:58 +04:00
|
|
|
&& Crypt::isCatfileContent($data)
|
2012-11-28 22:39:19 +04:00
|
|
|
) {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-07-30 12:14:17 +04:00
|
|
|
$handle = fopen('crypt://' . $path, 'r');
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
if (is_resource($handle)) {
|
|
|
|
while (($plainDataChunk = fgets($handle, 8192)) !== false) {
|
|
|
|
$plainData .= $plainDataChunk;
|
|
|
|
}
|
|
|
|
}
|
2012-12-11 19:10:56 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-27 19:26:58 +04:00
|
|
|
if (!isset($plainData)) {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-02-11 14:21:23 +04:00
|
|
|
$plainData = $data;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-12-11 19:10:56 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-02-11 14:21:23 +04:00
|
|
|
return $plainData;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2011-10-21 19:02:11 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-02-27 16:58:51 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* remember initial fopen mode because sometimes it gets changed during the request
|
2014-02-27 16:58:51 +04:00
|
|
|
* @param string $path path
|
|
|
|
* @param string $mode type of access
|
|
|
|
*/
|
|
|
|
public function preFopen($path, $mode) {
|
2014-03-27 16:49:48 +04:00
|
|
|
|
2014-02-27 16:58:51 +04:00
|
|
|
self::$fopenMode[$path] = $mode;
|
2014-05-21 13:39:37 +04:00
|
|
|
self::$enableEncryption = $this->shouldEncrypt($path, $mode);
|
2014-03-27 16:49:48 +04:00
|
|
|
|
2014-02-27 16:58:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
/**
|
2014-05-13 15:29:25 +04:00
|
|
|
* @param string $path
|
2014-05-15 16:19:32 +04:00
|
|
|
* @param resource $result
|
2013-05-20 03:24:36 +04:00
|
|
|
* @return resource
|
|
|
|
*/
|
2014-09-12 21:51:47 +04:00
|
|
|
public function postFopen($path, $result) {
|
2013-04-26 00:49:47 +04:00
|
|
|
|
2013-05-31 03:57:32 +04:00
|
|
|
$path = \OC\Files\Filesystem::normalizePath($path);
|
|
|
|
|
2014-03-27 16:49:48 +04:00
|
|
|
if (!$result || self::$enableEncryption === false) {
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2011-11-24 04:44:54 +04:00
|
|
|
return $result;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2011-11-24 04:44:54 +04:00
|
|
|
}
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2014-02-27 16:58:51 +04:00
|
|
|
// if we remember the mode from the pre proxy we re-use it
|
2014-03-27 16:49:48 +04:00
|
|
|
// otherwise we fall back to stream_get_meta_data()
|
2014-02-27 16:58:51 +04:00
|
|
|
if (isset(self::$fopenMode[$path])) {
|
|
|
|
$mode = self::$fopenMode[$path];
|
|
|
|
unset(self::$fopenMode[$path]);
|
|
|
|
} else {
|
|
|
|
$meta = stream_get_meta_data($result);
|
|
|
|
$mode = $meta['mode'];
|
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-03-27 16:49:48 +04:00
|
|
|
// Close the original encrypted file
|
|
|
|
fclose($result);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-03-27 16:49:48 +04:00
|
|
|
// Open the file using the crypto stream wrapper
|
|
|
|
// protocol and let it do the decryption work instead
|
|
|
|
$result = fopen('crypt://' . $path, $mode);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2011-11-24 04:44:54 +04:00
|
|
|
return $result;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2011-10-21 19:02:11 +04:00
|
|
|
}
|
2012-02-16 00:44:58 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
/**
|
2014-05-13 15:29:25 +04:00
|
|
|
* @param string $path
|
|
|
|
* @param array $data
|
2013-05-20 03:24:36 +04:00
|
|
|
* @return array
|
|
|
|
*/
|
2013-05-27 19:26:58 +04:00
|
|
|
public function postGetFileInfo($path, $data) {
|
2013-04-26 00:49:47 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// if path is a folder do nothing
|
2014-01-17 17:38:14 +04:00
|
|
|
if (\OCP\App::isEnabled('files_encryption') && $data !== false && array_key_exists('size', $data)) {
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// get file size
|
2014-06-02 14:04:46 +04:00
|
|
|
$data['size'] = self::postFileSize($path, $data['size'], $data);
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Re-enable the proxy
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
|
|
|
}
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
return $data;
|
|
|
|
}
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
/**
|
2014-05-13 15:29:25 +04:00
|
|
|
* @param string $path
|
|
|
|
* @param int $size
|
|
|
|
* @return int|bool
|
2013-05-20 03:24:36 +04:00
|
|
|
*/
|
2014-06-02 14:04:46 +04:00
|
|
|
public function postFileSize($path, $size, $fileInfo = null) {
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2014-05-12 18:30:39 +04:00
|
|
|
$view = new \OC\Files\View('/');
|
2013-04-23 21:08:52 +04:00
|
|
|
|
2013-11-20 21:10:56 +04:00
|
|
|
$userId = Helper::getUser($path);
|
2013-10-14 18:34:14 +04:00
|
|
|
$util = new Util($view, $userId);
|
|
|
|
|
|
|
|
// if encryption is no longer enabled or if the files aren't migrated yet
|
|
|
|
// we return the default file size
|
|
|
|
if(!\OCP\App::isEnabled('files_encryption') ||
|
|
|
|
$util->getMigrationStatus() !== Util::MIGRATION_COMPLETED) {
|
|
|
|
return $size;
|
|
|
|
}
|
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// if path is a folder do nothing
|
2013-05-27 19:26:58 +04:00
|
|
|
if ($view->is_dir($path)) {
|
2014-03-07 14:25:29 +04:00
|
|
|
$proxyState = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
$fileInfo = $view->getFileInfo($path);
|
|
|
|
\OC_FileProxy::$enabled = $proxyState;
|
2014-03-10 20:25:16 +04:00
|
|
|
if (isset($fileInfo['unencrypted_size']) && $fileInfo['unencrypted_size'] > 0) {
|
2014-03-07 14:25:29 +04:00
|
|
|
return $fileInfo['unencrypted_size'];
|
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
return $size;
|
|
|
|
}
|
2013-04-22 06:40:49 +04:00
|
|
|
|
2013-05-30 03:13:22 +04:00
|
|
|
// get relative path
|
|
|
|
$relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
|
2013-05-07 15:42:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// if path is empty we cannot resolve anything
|
2013-05-30 03:13:22 +04:00
|
|
|
if (empty($relativePath)) {
|
2013-05-20 03:24:36 +04:00
|
|
|
return $size;
|
|
|
|
}
|
2013-04-22 06:40:49 +04:00
|
|
|
|
2013-05-21 23:09:25 +04:00
|
|
|
// get file info from database/cache if not .part file
|
2014-06-02 14:04:46 +04:00
|
|
|
if (empty($fileInfo) && !Helper::isPartialFilePath($path)) {
|
2013-11-20 19:20:21 +04:00
|
|
|
$proxyState = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
2013-05-27 19:26:58 +04:00
|
|
|
$fileInfo = $view->getFileInfo($path);
|
2013-11-20 19:20:21 +04:00
|
|
|
\OC_FileProxy::$enabled = $proxyState;
|
2013-05-21 23:09:25 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
// if file is encrypted return real file size
|
2014-06-02 14:04:46 +04:00
|
|
|
if (isset($fileInfo['encrypted']) && $fileInfo['encrypted'] === true) {
|
2013-10-14 18:34:14 +04:00
|
|
|
// try to fix unencrypted file size if it doesn't look plausible
|
2013-10-16 13:24:56 +04:00
|
|
|
if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0 ) {
|
2013-10-14 18:34:14 +04:00
|
|
|
$fixSize = $util->getFileSize($path);
|
|
|
|
$fileInfo['unencrypted_size'] = $fixSize;
|
|
|
|
// put file info if not .part file
|
2013-11-12 13:24:10 +04:00
|
|
|
if (!Helper::isPartialFilePath($relativePath)) {
|
2014-04-30 14:48:16 +04:00
|
|
|
$view->putFileInfo($path, array('unencrypted_size' => $fixSize));
|
2013-10-14 18:34:14 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
$size = $fileInfo['unencrypted_size'];
|
|
|
|
} else {
|
2014-04-30 14:48:16 +04:00
|
|
|
|
|
|
|
$fileInfoUpdates = array();
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-27 19:26:58 +04:00
|
|
|
$fixSize = $util->getFileSize($path);
|
|
|
|
if ($fixSize > 0) {
|
2013-05-21 23:09:25 +04:00
|
|
|
$size = $fixSize;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-04-30 14:48:16 +04:00
|
|
|
$fileInfoUpdates['encrypted'] = true;
|
|
|
|
$fileInfoUpdates['unencrypted_size'] = $size;
|
2013-05-21 23:09:25 +04:00
|
|
|
|
|
|
|
// put file info if not .part file
|
2013-11-12 13:24:10 +04:00
|
|
|
if (!Helper::isPartialFilePath($relativePath)) {
|
2014-04-30 14:48:16 +04:00
|
|
|
$view->putFileInfo($path, $fileInfoUpdates);
|
2013-05-20 03:24:36 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-21 23:09:25 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
}
|
|
|
|
return $size;
|
|
|
|
}
|
2013-04-30 22:44:42 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
}
|