diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2018-07-25 11:19:14 +0300 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2018-08-08 11:46:14 +0300 |
commit | be172cc6f25ad7d1da383da06f90b834b62c0855 (patch) | |
tree | 72b8bc4b4f2da2c1fd470f31eb3f04c4bb605179 /lib | |
parent | a5985ad0f4697249f42c95cc5241a69df7acef09 (diff) |
make file cache updates more robust
only update the encrypted version after the write operation is finished and the stream is closed
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Stream/Encryption.php | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/private/Files/Stream/Encryption.php b/lib/private/Files/Stream/Encryption.php index d76ba85aa62..7d6642be104 100644 --- a/lib/private/Files/Stream/Encryption.php +++ b/lib/private/Files/Stream/Encryption.php @@ -102,6 +102,9 @@ class Encryption extends Wrapper { /** @var array */ protected $expectedContextProperties; + /** @var bool */ + protected $fileUpdated; + public function __construct() { $this->expectedContextProperties = array( 'source', @@ -235,6 +238,7 @@ class Encryption extends Wrapper { $this->position = 0; $this->cache = ''; $this->writeFlag = false; + $this->fileUpdated = false; $this->unencryptedBlockSize = $this->encryptionModule->getUnencryptedBlockSize($this->signed); if ( @@ -313,7 +317,6 @@ class Encryption extends Wrapper { } public function stream_write($data) { - $length = 0; // loop over $data to fit it in 6126 sized unencrypted blocks while (isset($data[0])) { @@ -333,6 +336,7 @@ class Encryption extends Wrapper { // switch the writeFlag so flush() will write the block $this->writeFlag = true; + $this->fileUpdated = true; // determine the relative position in the current block $blockPosition = ($this->position % $this->unencryptedBlockSize); @@ -414,7 +418,18 @@ class Encryption extends Wrapper { } $this->encryptionStorage->updateUnencryptedSize($this->fullPath, $this->unencryptedSize); } - return parent::stream_close(); + $result = parent::stream_close(); + + if ($this->fileUpdated) { + $cache = $this->storage->getCache(); + $cacheEntry = $cache->get($this->internalPath); + if ($cacheEntry) { + $version = $cacheEntry['encryptedVersion'] + 1; + $cache->update($cacheEntry->getId(), ['encrypted' => $version, 'encryptedVersion' => $version]); + } + } + + return $result; } /** |