Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] Object store move fixes and more #48201

Closed
wants to merge 12 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;

use OC\AllConfig;
use OCP\IConfig;

/**
Expand All @@ -31,7 +32,7 @@ protected function setUp(): void {
return $config->getSystemValue($key, $default);
}
});
$this->overwriteService('AllConfig', $mockConfig);
$this->overwriteService(AllConfig::class, $mockConfig);
parent::setUp();
}

Expand Down
42 changes: 41 additions & 1 deletion apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ public function dataGetShare() {

$parentFolder = $this->getMockBuilder(Folder::class)->getMock();
$parentFolder->method('getId')->willReturn(3);
$mountPoint = $this->createMock(IMountPoint::class);
$mountPoint->method('getMountType')->willReturn('');

$file = $this->getMockBuilder('OCP\Files\File')->getMock();
$file->method('getId')->willReturn(1);
Expand All @@ -543,6 +545,7 @@ public function dataGetShare() {
$file->method('getSize')->willReturn(123465);
$file->method('getMTime')->willReturn(1234567890);
$file->method('getMimeType')->willReturn('myMimeType');
$file->method('getMountPoint')->willReturn($mountPoint);

$folder = $this->getMockBuilder(Folder::class)->getMock();
$folder->method('getId')->willReturn(2);
Expand All @@ -552,6 +555,7 @@ public function dataGetShare() {
$folder->method('getSize')->willReturn(123465);
$folder->method('getMTime')->willReturn(1234567890);
$folder->method('getMimeType')->willReturn('myFolderMimeType');
$folder->method('getMountPoint')->willReturn($mountPoint);

[$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();

Expand Down Expand Up @@ -607,6 +611,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
'item_permissions' => 4,
'is-mount-root' => false,
'mount-type' => '',
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -661,6 +668,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
'item_permissions' => 4,
'is-mount-root' => false,
'mount-type' => '',
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -721,6 +731,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
'item_permissions' => 4,
'is-mount-root' => false,
'mount-type' => '',
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -3740,6 +3753,12 @@ public function dataFormatShare() {
$folder->method('getMimeType')->willReturn('myFolderMimeType');
$fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview');

$mountPoint = $this->createMock(IMountPoint::class);
$mountPoint->method('getMountType')->willReturn('');
$file->method('getMountPoint')->willReturn($mountPoint);
$folder->method('getMountPoint')->willReturn($mountPoint);
$fileWithPreview->method('getMountPoint')->willReturn($mountPoint);

$file->method('getPath')->willReturn('file');
$folder->method('getPath')->willReturn('folder');
$fileWithPreview->method('getPath')->willReturn('fileWithPreview');
Expand Down Expand Up @@ -3839,6 +3858,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
'item_permissions' => 1,
], $share, [], false
];
// User backend up
Expand Down Expand Up @@ -3880,6 +3900,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
'item_permissions' => 1,
], $share, [
['owner', $owner],
['initiator', $initiator],
Expand Down Expand Up @@ -3937,6 +3958,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -3990,6 +4012,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 11,
], $share, [], false
];

Expand Down Expand Up @@ -4044,6 +4067,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4095,6 +4119,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4153,6 +4178,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4211,6 +4237,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4263,6 +4290,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4315,6 +4343,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4370,6 +4399,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4422,6 +4452,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4474,6 +4505,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4543,6 +4575,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4598,6 +4631,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4651,6 +4685,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 11,
], $share, [], false
];

Expand Down Expand Up @@ -4815,6 +4850,7 @@ public function dataFormatRoomShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, false, []
];

Expand Down Expand Up @@ -4866,6 +4902,7 @@ public function dataFormatRoomShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 9,
], $share, true, [
'share_with_displayname' => 'recipientRoomName'
]
Expand Down Expand Up @@ -4905,11 +4942,14 @@ public function testFormatRoomShare(array $expects, \OCP\Share\IShare $share, bo
->willReturn(true);

$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
->setMethods(['formatShare'])
->setMethods(['formatShare', 'canAccessShare'])
->getMock();
$helper->method('formatShare')
->with($share)
->willReturn($formatShareByHelper);
$helper->method('canAccessShare')
->with($share)
->willReturn(true);

$this->serverContainer->method('get')
->with('\OCA\Talk\Share\Helper\ShareAPIController')
Expand Down
25 changes: 4 additions & 21 deletions apps/files_sharing/tests/Controller/ShareControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,27 +333,10 @@ public function testShowShare() {
'mimetype' => 'text/plain',
'dirToken' => 'token',
'sharingToken' => 'token',
'server2serversharing' => true,
'protected' => 'true',
'dir' => '',
'downloadURL' => 'downloadURL',
'fileSize' => '33 B',
'nonHumanFileSize' => 33,
'maxSizeAnimateGif' => 10,
'previewSupported' => true,
'previewEnabled' => true,
'previewMaxX' => 1024,
'previewMaxY' => 1024,
'hideFileList' => false,
'shareOwner' => 'ownerDisplay',
'disclaimer' => 'My disclaimer text',
'shareUrl' => 'shareUrl',
'previewImage' => 'previewImage',
'previewURL' => 'downloadURL',
'note' => $note,
'hideDownload' => false,
'showgridview' => false,
'label' => ''
'sharePermissions' => (Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE),
'filename' => $filename,
'view' => $view,
'fileId' => 111,
];

$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/tests/External/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\Contacts\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Cache\ICacheEntry;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
use OCP\IUserManager;
Expand Down Expand Up @@ -74,6 +75,7 @@ protected function setUp(): void {
$this->storage,
$this->cloudIdManager->getCloudId($this->remoteUser, 'http://example.com/owncloud')
);
$this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$this->cache->put(
'test.txt',
[
Expand Down
1 change: 1 addition & 0 deletions apps/files_trashbin/tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab
$event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash);

$userFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
$rootFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
$rootFolder->expects($this->any())->method('getUserFolder')->willReturn($userFolder);

$storage = $this->getMockBuilder(Storage::class)
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ public function insert($file, array $data) {
if (!isset($data['parent'])) {
$data['parent'] = $this->getParentId($file);
}
if ($data['parent'] === -1 && $file !== '') {
throw new \Exception('Parent folder not in filecache for ' . $file);
}
$data['name'] = basename($file);

[$values, $extensionValues] = $this->normalizeData($data);
Expand Down
22 changes: 14 additions & 8 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,10 @@ public function needsPartFile() {
}

public function file_put_contents($path, $data) {
$handle = $this->fopen($path, 'w+');
if (!$handle) {
return false;
}
$result = fwrite($handle, $data);
fclose($handle);
return $result;
$fh = fopen('php://temp', 'w+');
fwrite($fh, $data);
rewind($fh);
return $this->writeStream($path, $fh, strlen($data));
}

public function writeStream(string $path, $stream, ?int $size = null): int {
Expand Down Expand Up @@ -498,6 +495,10 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
if ($exists) {
$fileId = $stat['fileid'];
} else {
$parent = $this->normalizePath(dirname($path));
if (!$this->is_dir($parent)) {
throw new \InvalidArgumentException("trying to upload a file ($path) inside a non-directory ($parent)");
}
$fileId = $this->getCache()->put($uploadPath, $stat);
}

Expand Down Expand Up @@ -600,15 +601,20 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
$sourceCacheEntry = $sourceCache->get($sourceInternalPath);
}
if ($sourceCacheEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
$this->mkdir($targetInternalPath);
foreach ($sourceCache->getFolderContents($sourceInternalPath) as $child) {
$this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName());
}
$sourceStorage->rmdir($sourceInternalPath);
} else {
$sourceStream = $sourceStorage->fopen($sourceInternalPath, 'r');
if (!$sourceStream) {
return false;
}
// move the cache entry before the contents so that we have the correct fileid/urn for the target
$this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);
try {
$this->writeStream($targetInternalPath, $sourceStorage->fopen($sourceInternalPath, 'r'), $sourceCacheEntry->getSize());
$this->writeStream($targetInternalPath, $sourceStream, $sourceCacheEntry->getSize());
} catch (\Exception $e) {
// restore the cache entry
$sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/ObjectStore/StorageObjectStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function __construct(IStorage $storage) {
* @return string the container or bucket name where objects are stored
* @since 7.0.0
*/
public function getStorageId() {
$this->storage->getId();
public function getStorageId(): string {
return $this->storage->getId();
}

/**
Expand Down
Loading
Loading