Merge pull request #6916 from owncloud/encryption_update_filecache
[encryption] update file cache after the file was written
This commit is contained in:
commit
1d3da8b0ed
|
@ -37,6 +37,7 @@ namespace OCA\Encryption;
|
||||||
class Proxy extends \OC_FileProxy {
|
class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
private static $blackList = null; //mimetypes blacklisted from encryption
|
private static $blackList = null; //mimetypes blacklisted from encryption
|
||||||
|
private static $unencryptedSizes = array(); // remember unencrypted size
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a file requires encryption
|
* Check if a file requires encryption
|
||||||
|
@ -114,14 +115,12 @@ class Proxy extends \OC_FileProxy {
|
||||||
// get encrypted content
|
// get encrypted content
|
||||||
$data = $view->file_get_contents($tmpPath);
|
$data = $view->file_get_contents($tmpPath);
|
||||||
|
|
||||||
// update file cache for target file
|
// store new unenecrypted size so that it can be updated
|
||||||
|
// in the post proxy
|
||||||
$tmpFileInfo = $view->getFileInfo($tmpPath);
|
$tmpFileInfo = $view->getFileInfo($tmpPath);
|
||||||
$fileInfo = $view->getFileInfo($path);
|
if ( isset($tmpFileInfo['size']) ) {
|
||||||
if (is_array($fileInfo) && is_array($tmpFileInfo)) {
|
self::$unencryptedSizes[\OC_Filesystem::normalizePath($path)] = $tmpFileInfo['size'];
|
||||||
$fileInfo['encrypted'] = true;
|
}
|
||||||
$fileInfo['unencrypted_size'] = $tmpFileInfo['size'];
|
|
||||||
$view->putFileInfo($path, $fileInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove our temp file
|
// remove our temp file
|
||||||
$view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
|
$view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
|
||||||
|
@ -136,6 +135,24 @@ class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief update file cache with the new unencrypted size after file was written
|
||||||
|
* @param string $path
|
||||||
|
* @param mixed $result
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function postFile_put_contents($path, $result) {
|
||||||
|
$normalizedPath = \OC_Filesystem::normalizePath($path);
|
||||||
|
if ( isset(self::$unencryptedSizes[$normalizedPath]) ) {
|
||||||
|
$view = new \OC_FilesystemView('/');
|
||||||
|
$view->putFileInfo($normalizedPath,
|
||||||
|
array('encrypted' => true, 'encrypted_size' => self::$unencryptedSizes[$normalizedPath]));
|
||||||
|
unset(self::$unencryptedSizes[$normalizedPath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path Path of file from which has been read
|
* @param string $path Path of file from which has been read
|
||||||
* @param string $data Data that has been read from file
|
* @param string $data Data that has been read from file
|
||||||
|
|
Loading…
Reference in New Issue