Skip to content

Commit 57df4d8

Browse files
leftybournesbackportbot[bot]
authored andcommitted
fix(files): preserve encryptedVersion when copying cache entries
Cache::copyFromCache() rebuilt the target's cache row via cacheEntryToArray(), which only carried over a boolean `encrypted` flag and dropped the real `encryptedVersion` count. Since View::copy() unconditionally calls copyFromCache() after the storage copy completes, this silently overwrote the correct encryptedVersion that Encryption::updateEncryptedVersion() had just set, collapsing it back to 0/1 on every copy of a file whose encryptedVersion was above 1. cacheEntryToArray() now includes the source entry's encryptedVersion when it is encrypted. The existing encrypted-to-non-encrypted-storage override in copyFromCache() also clears encryptedVersion alongside `encrypted`, since normalizeData() prefers encryptedVersion over `encrypted` when both are present in the update data. Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-sonnet-5
1 parent 2077c1e commit 57df4d8

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎lib/private/Files/Cache/Cache.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,9 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str
11661166
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
11671167
if ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
11681168
$data['encrypted'] = 0;
1169+
// normalizeData() prefers 'encryptedVersion' over 'encrypted' when both are
1170+
// set, so it has to be cleared too or the mark above gets ignored
1171+
unset($data['encryptedVersion']);
11691172
}
11701173

11711174
$fileId = $this->put($targetPath, $data);
@@ -1199,6 +1202,11 @@ private function cacheEntryToArray(ICacheEntry $entry): array {
11991202
if ($entry instanceof CacheEntry && isset($entry['scan_permissions'])) {
12001203
$data['permissions'] = $entry['scan_permissions'];
12011204
}
1205+
1206+
if ($entry->isEncrypted() && isset($entry['encryptedVersion'])) {
1207+
$data['encryptedVersion'] = $entry['encryptedVersion'];
1208+
}
1209+
12021210
return $data;
12031211
}
12041212

0 commit comments

Comments
 (0)