diff options
author | Lukas Reschke <lukas@owncloud.com> | 2016-02-09 22:27:23 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2016-02-09 23:43:27 +0100 |
commit | 6724f765733fa67f6f3e3fd0fb6a6a23eaaa127b (patch) | |
tree | 7fee7e5b28f5ba74b8884c57bc832a4e2d78c420 /apps/encryption/lib | |
parent | 377d7fb8a817f337552e444c5aea9eb82bcfada4 (diff) | |
download | nextcloud-server-6724f765733fa67f6f3e3fd0fb6a6a23eaaa127b.tar.gz nextcloud-server-6724f765733fa67f6f3e3fd0fb6a6a23eaaa127b.zip |
Use cache and add tests
Diffstat (limited to 'apps/encryption/lib')
-rw-r--r-- | apps/encryption/lib/crypto/encryption.php | 9 | ||||
-rw-r--r-- | apps/encryption/lib/keymanager.php | 18 |
2 files changed, 12 insertions, 15 deletions
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index 645d17f8184..a637f52a869 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -29,6 +29,7 @@ namespace OCA\Encryption\Crypto; use OC\Encryption\Exceptions\DecryptionFailedException; +use OC\Files\View; use OCA\Encryption\Exceptions\PublicKeyMissingException; use OCA\Encryption\Session; use OCA\Encryption\Util; @@ -186,7 +187,7 @@ class Encryption implements IEncryptionModule { $this->fileKey = $this->keyManager->getFileKey($this->path, $this->user); } - $this->version = (int)$this->keyManager->getVersion($this->realPath); + $this->version = (int)$this->keyManager->getVersion($this->realPath, new View()); if ( $mode === 'w' @@ -235,7 +236,7 @@ class Encryption implements IEncryptionModule { } else { $version = $this->version + 1; } - $this->keyManager->setVersion($this->path, $this->version+1); + $this->keyManager->setVersion($this->path, $this->version+1, new View()); if (!empty($this->writeCache)) { $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $version, $position); $this->writeCache = ''; @@ -371,7 +372,7 @@ class Encryption implements IEncryptionModule { if(empty($this->realPath)) { $this->realPath = $path; } - $version = $this->keyManager->getVersion($this->realPath); + $version = $this->keyManager->getVersion($this->realPath, new View()); if (!empty($fileKey)) { @@ -392,7 +393,7 @@ class Encryption implements IEncryptionModule { $this->keyManager->setAllFileKeys($path, $encryptedFileKey); - $this->keyManager->setVersion($path, $version); + $this->keyManager->setVersion($path, $version, new View()); } else { $this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted', diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index 7d8bd8485e6..57a8155e7b9 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -418,10 +418,10 @@ class KeyManager { * Get the current version of a file * * @param string $path + * @param View $view * @return int */ - public function getVersion($path) { - $view = new \OC\Files\View(); + public function getVersion($path, View $view) { $fileInfo = $view->getFileInfo($path); if($fileInfo === false) { return 0; @@ -433,19 +433,15 @@ class KeyManager { * Set the current version of a file * * @param string $path - * @param string $version + * @param int $version + * @param View $view */ - public function setVersion($path, $version) { - $view = new \OC\Files\View(); + public function setVersion($path, $version, View $view) { $fileInfo= $view->getFileInfo($path); if($fileInfo !== false) { - $fileId = $fileInfo->getId(); - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); - $qb->update('filecache') - ->set('encrypted', $qb->createNamedParameter($version)) - ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($fileId))) - ->execute(); + $cache = $fileInfo->getStorage()->getCache(); + $cache->put($path, ['fileid' => $fileInfo->getId(), 'encrypted' => $version, 'encryptedVersion' => $version]); } } |