diff options
author | Björn Schießle <bjoern@schiessle.org> | 2018-08-08 18:27:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-08 18:27:18 +0200 |
commit | 11e99859ef3a28d0124241a43a934f70b7c3ff3a (patch) | |
tree | a3d3f5c785157762815c09402c5bc1f9f94975dc /lib | |
parent | 6b1ba9cdaf3ce5d63e6e46bcbc677cf7933f5fb3 (diff) | |
parent | a9e22c5f1ccdc148d8ea8a1e2f5e8baac6f19e90 (diff) | |
download | nextcloud-server-11e99859ef3a28d0124241a43a934f70b7c3ff3a.tar.gz nextcloud-server-11e99859ef3a28d0124241a43a934f70b7c3ff3a.zip |
Merge pull request #10397 from nextcloud/encryption-s3-fix
make file cache updates more robust
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 65d379c0289..3c884a99ae7 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; } /** |