[Pkg-owncloud-commits] [owncloud] 45/90: Return valid fileinfo objects for part files

David Prévot taffit at moszumanska.debian.org
Fri Feb 6 21:10:49 UTC 2015


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

taffit pushed a commit to branch master
in repository owncloud.

commit 0f04bfc31964066ddd211b50f3db40be9b9b9aae
Author: Robin Appelman <icewind at owncloud.com>
Date:   Tue Jan 13 13:59:28 2015 +0100

    Return valid fileinfo objects for part files
---
 lib/private/files/view.php | 31 +++++++++++++++++++++++++++++++
 tests/lib/files/view.php   | 14 ++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 8c123b8..430e9e6 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -873,6 +873,9 @@ class View {
 		if (!Filesystem::isValidPath($path)) {
 			return $data;
 		}
+		if (Cache\Scanner::isPartialFile($path)) {
+			return $this->getPartFileInfo($path);
+		}
 		$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
 
 		$mount = Filesystem::getMountManager()->find($path);
@@ -1259,4 +1262,32 @@ class View {
 
 		return $result;
 	}
+
+	/**
+	 * Get a fileinfo object for files that are ignored in the cache (part files)
+	 *
+	 * @param string $path
+	 * @return \OCP\Files\FileInfo
+	 */
+	private function getPartFileInfo($path) {
+		$mount  = $this->getMount($path);
+		$storage = $mount->getStorage();
+		$internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
+		return new FileInfo(
+			$this->getAbsolutePath($path),
+			$storage,
+			$internalPath,
+			[
+				'fileid' => null,
+				'mimetype' => $storage->getMimeType($internalPath),
+				'name' => basename($path),
+				'etag' => null,
+				'size' => $storage->filesize($internalPath),
+				'mtime' => $storage->filemtime($internalPath),
+				'encrypted' => false,
+				'permissions' => \OCP\Constants::PERMISSION_ALL
+			],
+			$mount
+		);
+	}
 }
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index aa50318..a30d6df 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -668,6 +668,20 @@ class View extends \PHPUnit_Framework_TestCase {
 		$this->assertEquals($expectedPath, $view->getAbsolutePath($relativePath));
 	}
 
+	public function testPartFileInfo() {
+		$storage = new Temporary(array());
+		$scanner = $storage->getScanner();
+		\OC\Files\Filesystem::mount($storage, array(), '/test/');
+		$storage->file_put_contents('test.part', 'foobar');
+		$scanner->scan('');
+		$view = new \OC\Files\View('/test');
+		$info = $view->getFileInfo('test.part');
+
+		$this->assertInstanceOf('\OCP\Files\FileInfo', $info);
+		$this->assertNull($info->getId());
+		$this->assertEquals(6, $info->getSize());
+	}
+
 	function absolutePathProvider() {
 		return array(
 			array('/files/', ''),

-- 
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