Return valid fileinfo objects for part files

This commit is contained in:
Robin Appelman 2015-01-13 13:59:28 +01:00
parent 6d73aff9ad
commit 96dff341e2
2 changed files with 45 additions and 0 deletions

View File

@ -896,6 +896,9 @@ class View {
if (!Filesystem::isValidPath($path)) { if (!Filesystem::isValidPath($path)) {
return $data; return $data;
} }
if (Cache\Scanner::isPartialFile($path)) {
return $this->getPartFileInfo($path);
}
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
$mount = Filesystem::getMountManager()->find($path); $mount = Filesystem::getMountManager()->find($path);
@ -1308,4 +1311,32 @@ class View {
return $result; 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
);
}
} }

View File

@ -703,6 +703,20 @@ class View extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getAbsolutePath($relativePath)); $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() { function absolutePathProvider() {
return array( return array(
array('/files/', ''), array('/files/', ''),