[Pkg-owncloud-commits] [owncloud] 135/205: Correctly check if the real file exists, otherwise try the part file

David Prévot taffit at moszumanska.debian.org
Thu Jul 2 17:37:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 9b336765b69bf7b7e2cd67a824862411b249aa4d
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Fri Jun 26 11:26:40 2015 +0200

    Correctly check if the real file exists, otherwise try the part file
---
 lib/private/files/storage/wrapper/encryption.php |  8 ++++++--
 tests/lib/files/storage/wrapper/encryption.php   | 26 ++++++++++++++++--------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index 8d1f80c..675978d 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -350,7 +350,7 @@ class Encryption extends Wrapper {
 
 			$size = $unencryptedSize = 0;
 			$realFile = $this->util->stripPartialFileExtension($path);
-			$targetExists = $this->file_exists($realFile);
+			$targetExists = $this->file_exists($realFile) || $this->file_exists($path);
 			$targetIsEncrypted = false;
 			if ($targetExists) {
 				// in case the file exists we require the explicit module as
@@ -608,7 +608,11 @@ class Encryption extends Wrapper {
 		$header = '';
 		$realFile = $this->util->stripPartialFileExtension($path);
 		if ($this->storage->file_exists($realFile)) {
-			$handle = $this->storage->fopen($realFile, 'r');
+			$path = $realFile;
+		}
+
+		if ($this->storage->file_exists($path)) {
+			$handle = $this->storage->fopen($path, 'r');
 			$firstBlock = fread($handle, $this->util->getHeaderSize());
 			fclose($handle);
 			if (substr($firstBlock, 0, strlen(Util::HEADER_START)) === Util::HEADER_START) {
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index 175713d..a10e95a 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -381,10 +381,12 @@ class Encryption extends \Test\Files\Storage\Storage {
 
 	/**
 	 * @dataProvider dataTestGetHeader
-	 * @param $path
-	 * @param $strippedPath
+	 *
+	 * @param string $path
+	 * @param bool $strippedPathExists
+	 * @param string $strippedPath
 	 */
-	public function testGetHeader($path, $strippedPath) {
+	public function testGetHeader($path, $strippedPathExists, $strippedPath) {
 
 		$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
 			->disableOriginalConstructor()->getMock();
@@ -409,17 +411,25 @@ class Encryption extends \Test\Files\Storage\Storage {
 
 		$util->expects($this->once())->method('stripPartialFileExtension')
 			->with($path)->willReturn($strippedPath);
-		$sourceStorage->expects($this->once())->method('file_exists')
-			->with($strippedPath)->willReturn(false);
+		$sourceStorage->expects($this->at(0))
+			->method('file_exists')
+			->with($strippedPath)
+			->willReturn($strippedPathExists);
+		$sourceStorage->expects($this->at(1))
+			->method('file_exists')
+			->with($strippedPathExists ? $strippedPath : $path)
+			->willReturn(false);
 
 		$this->invokePrivate($instance, 'getHeader', [$path]);
 	}
 
 	public function dataTestGetHeader() {
 		return array(
-			array('/foo/bar.txt', '/foo/bar.txt'),
-			array('/foo/bar.txt.part', '/foo/bar.txt'),
-			array('/foo/bar.txt.ocTransferId7437493.part', '/foo/bar.txt'),
+			array('/foo/bar.txt', false, '/foo/bar.txt'),
+			array('/foo/bar.txt.part', false, '/foo/bar.txt'),
+			array('/foo/bar.txt.ocTransferId7437493.part', false, '/foo/bar.txt'),
+			array('/foo/bar.txt.part', true, '/foo/bar.txt'),
+			array('/foo/bar.txt.ocTransferId7437493.part', true, '/foo/bar.txt'),
 		);
 	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list