Skip to content

Commit

Permalink
Merge pull request #40381 from nextcloud/backport/38808/stable25
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Sep 15, 2023
2 parents cb9a724 + 8ddcebe commit f077b26
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function __clone() {
}

public function getUnencryptedSize(): int {
if (isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
return $this->data['unencrypted_size'];
} else {
return $this->data['size'] ?? 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function getSize($includeMounts = true) {
if ($includeMounts) {
$this->updateEntryfromSubMounts();

if (isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
if ($this->isEncrypted() && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
return $this->data['unencrypted_size'];
} else {
return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
Expand All @@ -232,7 +232,7 @@ public function getMTime() {
* @return bool
*/
public function isEncrypted() {
return $this->data['encrypted'];
return $this->data['encrypted'] ?? false;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ public function writeStream(string $path, $stream, int $size = null): int {
}

if ($exists) {
// Always update the unencrypted size, for encryption the Encryption wrapper will update this afterwards anyways
$stat['unencrypted_size'] = $stat['size'];
$this->getCache()->update($fileId, $stat);
} else {
if ($this->objectStore->objectExists($urn)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ public function writeStream(string $path, $stream, int $size = null): int {

// object store, stores the size after write and doesn't update this during scan
// manually store the unencrypted size
if ($result && $this->getWrapperStorage()->instanceOfStorage(ObjectStoreStorage::class)) {
if ($result && $this->getWrapperStorage()->instanceOfStorage(ObjectStoreStorage::class) && $this->shouldEncrypt($path)) {
$this->getCache()->put($path, ['unencrypted_size' => $count]);
}

Expand Down

0 comments on commit f077b26

Please sign in to comment.