Skip to content
Snippets Groups Projects
Commit baa6fd63 authored by Florin Peter's avatar Florin Peter
Browse files

improved file size handling

parent 8ab9433f
Branches
No related tags found
No related merge requests found
......@@ -166,6 +166,7 @@ class Proxy extends \OC_FileProxy {
}
}
return true;
}
/**
......@@ -300,7 +301,6 @@ class Proxy extends \OC_FileProxy {
$oldRelPath = implode('/', $oldSliced);
$oldKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $oldRelPath;
$newTrimmed = ltrim($newPath, '/');
$newSplit = explode('/', $newTrimmed);
$newSliced = array_slice($newSplit, 2);
......@@ -418,6 +418,25 @@ class Proxy extends \OC_FileProxy {
}
public function postGetFileInfo( $path, $data ) {
// if path is a folder do nothing
if(is_array($data) && array_key_exists('size', $data)) {
// Disable encryption proxy to prevent recursive calls
\OC_FileProxy::$enabled = false;
// get file size
$data['size'] = self::postFileSize($path, $data['size']);
// Re-enable the proxy
\OC_FileProxy::$enabled = true;
trigger_error('postGetFileInfo '.$path.' size: '.$data['size']);
}
return $data;
}
public function postStat( $path, $data ) {
if ( Crypt::isCatfileContent( $path ) ) {
......@@ -433,29 +452,38 @@ class Proxy extends \OC_FileProxy {
public function postFileSize( $path, $size ) {
$view = new \OC_FilesystemView( '/' );
// if path is a folder do nothing
if($view->is_dir($path)) {
return $size;
}
// Reformat path for use with OC_FSV
$path_split = explode('/', $path);
$path_f = implode('/', array_slice($path_split, 3));
$view = new \OC_FilesystemView( '/' );
$userId = \OCP\User::getUser();
$util = new Util( $view, $userId );
if ($util->isEncryptedPath($path)) {
// FIXME: is there a better solution to check if file belongs to files path?
// only get file size if file is in 'files' path
if (count($path_split) >= 2 && $path_split[2] == 'files' && $util->isEncryptedPath($path)) {
// Disable encryption proxy to prevent recursive calls
\OC_FileProxy::$enabled = false;
// get file info
$cached = \OC\Files\Filesystem::getFileInfo($path_f, '');
// calculate last chunk nr
$lastChunckNr = floor($size / 8192);
// open stream
$result = fopen('crypt://' . $path_f, "r");
if(is_resource($result)) {
// don't trust the given size, allways get the size from filesystem
$size = $view->filesize($path);
// calculate last chunk nr
$lastChunckNr = floor($size / 8192);
// calculate last chunk position
$lastChunckPos = ($lastChunckNr * 8192);
......@@ -469,13 +497,13 @@ class Proxy extends \OC_FileProxy {
$realSize = (($lastChunckNr * 6126) + strlen($lastChunkContent));
// set the size
$cached['size'] = $realSize;
$size = $realSize;
}
// enable proxy
\OC_FileProxy::$enabled = true;
return $cached['size'];
return $size;
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment