]> source.dussan.org Git - nextcloud-server.git/commitdiff
clear encrypted flag when moving away from encrypted storage
authorRobin Appelman <robin@icewind.nl>
Wed, 28 Dec 2022 16:17:45 +0000 (17:17 +0100)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Sat, 1 Apr 2023 16:49:37 +0000 (16:49 +0000)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Cache/Cache.php
lib/private/Files/Cache/Wrapper/CacheWrapper.php

index 6440bf05a1dc1ccc4f6af76a2be33673a4774b4c..67faed7b31bb6c4daddae7a1e2c219f284ee0409 100644 (file)
@@ -43,6 +43,7 @@ namespace OC\Files\Cache;
 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;
@@ -641,6 +642,10 @@ class Cache implements ICache {
                return [$this->getNumericStorageId(), $path];
        }
 
+       protected function hasEncryptionWrapper(): bool {
+               return $this->storage->instanceOfStorage(Encryption::class);
+       }
+
        /**
         * Move a file or folder in the cache
         *
@@ -692,6 +697,11 @@ class Cache implements ICache {
                                        ->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) {
@@ -708,6 +718,12 @@ class Cache implements ICache {
                                ->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();
@@ -1067,6 +1083,12 @@ class Cache implements ICache {
                        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) . " ");
index 66ae83fd14476b3cc1963f970c5e8549ba163b4e..2cd378ad23cd5be88ff614b1e36a969fee8f542c 100644 (file)
@@ -56,6 +56,15 @@ class CacheWrapper extends Cache {
                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
         *