Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
clear encrypted flag when moving away from encrypted storage
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and backportbot-nextcloud[bot] committed Apr 1, 2023
commit 40748731f130fd79d609bf80016fefe30f9b06c8
22 changes: 22 additions & 0 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Wrapper\Encryption;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheEntryInsertedEvent;
Expand Down Expand Up @@ -641,6 +642,10 @@ protected function getMoveInfo($path) {
return [$this->getNumericStorageId(), $path];
}

protected function hasEncryptionWrapper(): bool {
return $this->storage->instanceOfStorage(Encryption::class);
}

/**
* Move a file or folder in the cache
*
Expand Down Expand Up @@ -692,6 +697,11 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));

// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
$query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT));
}

try {
$query->execute();
} catch (\OC\DatabaseException $e) {
Expand All @@ -708,6 +718,12 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
->set('name', $query->createNamedParameter(basename($targetPath)))
->set('parent', $query->createNamedParameter($newParentId, IQueryBuilder::PARAM_INT))
->whereFileId($sourceId);

// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
$query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT));
}

$query->execute();

$this->connection->commit();
Expand Down Expand Up @@ -1067,6 +1083,12 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str
throw new \RuntimeException("Invalid source cache entry on copyFromCache");
}
$data = $this->cacheEntryToArray($sourceEntry);

// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
if ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
$data['encrypted'] = 0;
}

$fileId = $this->put($targetPath, $data);
if ($fileId <= 0) {
throw new \RuntimeException("Failed to copy to " . $targetPath . " from cache with source data " . json_encode($data) . " ");
Expand Down
9 changes: 9 additions & 0 deletions lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ protected function getCache() {
return $this->cache;
}

protected function hasEncryptionWrapper(): bool {
$cache = $this->getCache();
if ($cache instanceof Cache) {
return $cache->hasEncryptionWrapper();
} else {
return false;
}
}

/**
* Make it easy for wrappers to modify every returned cache entry
*
Expand Down