diff --git a/apps/dav/lib/Connector/Sabre/Server.php b/apps/dav/lib/Connector/Sabre/Server.php
index 6cf6fa954c8db..0831a47b49198 100644
--- a/apps/dav/lib/Connector/Sabre/Server.php
+++ b/apps/dav/lib/Connector/Sabre/Server.php
@@ -43,4 +43,27 @@ public function __construct($treeOrNode = null) {
self::$exposeVersion = false;
$this->enablePropfindDepthInfinity = true;
}
+
+ // Copied from 3rdparty/sabre/dav/lib/DAV/Server.php
+ // Should be them exact same without the exception output.
+ public function start(): void {
+ try {
+ // If nginx (pre-1.2) is used as a proxy server, and SabreDAV as an
+ // origin, we must make sure we send back HTTP/1.0 if this was
+ // requested.
+ // This is mainly because nginx doesn't support Chunked Transfer
+ // Encoding, and this forces the webserver SabreDAV is running on,
+ // to buffer entire responses to calculate Content-Length.
+ $this->httpResponse->setHTTPVersion($this->httpRequest->getHTTPVersion());
+
+ // Setting the base url
+ $this->httpRequest->setBaseUrl($this->getBaseUri());
+ $this->invokeMethod($this->httpRequest, $this->httpResponse);
+ } catch (\Throwable $e) {
+ try {
+ $this->emit('exception', [$e]);
+ } catch (\Exception $ignore) {
+ }
+ }
+ }
}
diff --git a/apps/dav/lib/Files/ErrorPagePlugin.php b/apps/dav/lib/Files/ErrorPagePlugin.php
index d918da4fab381..9f834cfbcb542 100644
--- a/apps/dav/lib/Files/ErrorPagePlugin.php
+++ b/apps/dav/lib/Files/ErrorPagePlugin.php
@@ -109,7 +109,6 @@ public function generateBody(\Throwable $ex, int $httpCode): mixed {
*/
public function sendResponse() {
$this->server->sapi->sendResponse($this->server->httpResponse);
- exit();
}
private function acceptHtml(): bool {
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php
index 88ec848ad8955..d86525f16c41a 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php
@@ -25,6 +25,7 @@
*/
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
+use OC\AllConfig;
use OCP\IConfig;
/**
@@ -49,7 +50,7 @@ protected function setUp(): void {
return $config->getSystemValue($key, $default);
}
});
- $this->overwriteService('AllConfig', $mockConfig);
+ $this->overwriteService(AllConfig::class, $mockConfig);
parent::setUp();
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 139c8996ae011..1c7937ea01fb6 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -550,6 +550,8 @@ public function dataGetShare() {
$parentFolder = $this->getMockBuilder('OCP\Files\Folder')->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);
@@ -559,6 +561,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('OCP\Files\Folder')->getMock();
$folder->method('getId')->willReturn(2);
@@ -568,6 +571,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();
@@ -623,6 +627,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
+ 'item_permissions' => 4,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
];
$data[] = [$share, $expected];
@@ -677,6 +684,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
+ 'item_permissions' => 4,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
];
$data[] = [$share, $expected];
@@ -737,6 +747,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
+ 'item_permissions' => 4,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
];
$data[] = [$share, $expected];
@@ -3727,6 +3740,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');
@@ -3824,6 +3843,9 @@ public function dataFormatShare() {
'item_size' => 123456,
'item_mtime' => 1234567890,
'attributes' => '[{"scope":"permissions","key":"download","enabled":true}]',
+ 'item_permissions' => 1,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
], $share, [], false
];
// User backend up
@@ -3863,6 +3885,9 @@ public function dataFormatShare() {
'item_size' => 123456,
'item_mtime' => 1234567890,
'attributes' => '[{"scope":"permissions","key":"download","enabled":true}]',
+ 'item_permissions' => 1,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
], $share, [
['owner', $owner],
['initiator', $initiator],
@@ -3920,6 +3945,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -3973,6 +3999,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 11,
], $share, [], false
];
@@ -4027,6 +4054,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4078,6 +4106,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4136,6 +4165,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4194,6 +4224,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4246,6 +4277,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4298,6 +4330,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4353,6 +4386,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4405,6 +4439,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4457,6 +4492,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4526,6 +4562,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4581,6 +4618,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, [], false
];
@@ -4634,6 +4672,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 11,
], $share, [], false
];
@@ -4798,6 +4837,7 @@ public function dataFormatRoomShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 1,
], $share, false, []
];
@@ -4849,6 +4889,7 @@ public function dataFormatRoomShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
+ 'item_permissions' => 9,
], $share, true, [
'share_with_displayname' => 'recipientRoomName'
]
@@ -4888,11 +4929,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')
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index 3a73862bf77d5..4825f1988ac3b 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -375,7 +375,8 @@ public function testShowShare() {
'previewURL' => 'downloadURL',
'note' => $note,
'hideDownload' => false,
- 'showgridview' => false
+ 'showgridview' => false,
+ 'filename' => $filename,
];
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index c77012c3e44a4..50edd1fb67058 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -32,6 +32,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;
@@ -95,6 +96,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',
[
diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php
index 8e69c5a0f659e..0b6c34b9fe4bb 100644
--- a/apps/files_sharing/tests/SharedStorageTest.php
+++ b/apps/files_sharing/tests/SharedStorageTest.php
@@ -479,6 +479,7 @@ public function testMoveFromStorage() {
$sourceStorage = new \OC\Files\Storage\Temporary([]);
$sourceStorage->file_put_contents('foo.txt', 'asd');
+ $sourceStorage->getScanner()->scan('');
$sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
$this->assertTrue($sharedStorage->file_exists('bar.txt'));
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index 442abc13670c6..d19ef5cc02bc5 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -53,7 +53,6 @@
use OC\Files\Node\Folder;
use OC\Files\Node\NonExistingFile;
use OC\Files\Node\NonExistingFolder;
-use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\View;
use OC_User;
use OCA\Files_Trashbin\AppInfo\Application;
@@ -67,6 +66,8 @@
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
+use OCP\Files\Storage\ILockingStorage;
+use OCP\Files\Storage\IStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\Lock\ILockingProvider;
@@ -290,11 +291,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
$gotLock = false;
- while (!$gotLock) {
+ do {
+ /** @var ILockingStorage & IStorage $trashStorage */
+ [$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
try {
- /** @var \OC\Files\Storage\Storage $trashStorage */
- [$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
-
$trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
$gotLock = true;
} catch (LockedException $e) {
@@ -305,7 +305,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
}
- }
+ } while (!$gotLock);
$sourceStorage = $sourceInfo->getStorage();
$sourceInternalPath = $sourceInfo->getInternalPath();
@@ -319,14 +319,15 @@ public static function move2trash($file_path, $ownerOnly = false) {
return false;
}
- $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
-
try {
$moveSuccessful = true;
- // when moving within the same object store, the cache update done above is enough to move the file
- if (!($trashStorage->instanceOfStorage(ObjectStoreStorage::class) && $trashStorage->getId() === $sourceStorage->getId())) {
- $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
+ $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
+ if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
+ $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
+ }
+ if ($trashStorage->getCache()->inCache($sourceInternalPath)) {
+ $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
}
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
$moveSuccessful = false;
diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php
index 59bd7e0f5ef53..bcd4124b8be16 100644
--- a/apps/files_trashbin/tests/StorageTest.php
+++ b/apps/files_trashbin/tests/StorageTest.php
@@ -33,7 +33,6 @@
use OC\Files\Filesystem;
use OC\Files\Storage\Common;
-use OC\Files\Storage\Local;
use OC\Files\Storage\Temporary;
use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
@@ -616,6 +615,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)
@@ -696,10 +696,7 @@ public function testTrashbinCollision() {
$this->assertEquals('bar', $this->rootView->file_get_contents($this->user . '/files_trashbin/files/test.txt.d1001'));
}
- public function testMoveFromStoragePreserveFileId() {
- if (!$this->userView->getMount('')->getStorage()->instanceOfStorage(Local::class)) {
- $this->markTestSkipped("Skipping on non-local users storage");
- }
+ public function testMoveFromStoragePreserveFileId(): void {
$this->userView->file_put_contents('test.txt', 'foo');
$fileId = $this->userView->getFileInfo('test.txt')->getId();
diff --git a/core/templates/exception.php b/core/templates/exception.php
index d26e9ff4f94ed..324724e67ace2 100644
--- a/core/templates/exception.php
+++ b/core/templates/exception.php
@@ -4,20 +4,7 @@
style('core', ['styles', 'header']);
-function print_exception(Throwable $e, \OCP\IL10N $l): void {
- print_unescaped('
');
- p($e->getTraceAsString());
- print_unescaped('
');
-
- if ($e->getPrevious() !== null) {
- print_unescaped('
');
- print_unescaped('');
- p($l->t('Previous'));
- print_unescaped('
');
-
- print_exception($e->getPrevious(), $l);
- }
-}
+require_once __DIR__ . '/print_exception.php';
?>
diff --git a/core/templates/print_exception.php b/core/templates/print_exception.php
new file mode 100644
index 0000000000000..2def6d4e9d904
--- /dev/null
+++ b/core/templates/print_exception.php
@@ -0,0 +1,21 @@
+');
+ p($e->getTraceAsString());
+ print_unescaped('');
+
+ if ($e->getPrevious() !== null) {
+ print_unescaped('
');
+ print_unescaped('
');
+ p($l->t('Previous'));
+ print_unescaped('
');
+
+ print_exception($e->getPrevious(), $l);
+ }
+}
diff --git a/core/templates/print_xml_exception.php b/core/templates/print_xml_exception.php
new file mode 100644
index 0000000000000..94452d8ae9d3f
--- /dev/null
+++ b/core/templates/print_xml_exception.php
@@ -0,0 +1,16 @@
+getTraceAsString());
+
+ if ($e->getPrevious() !== null) {
+ print_unescaped('');
+ print_exception($e->getPrevious(), $l);
+ print_unescaped('');
+ }
+}
diff --git a/core/templates/xml_exception.php b/core/templates/xml_exception.php
index 342238d824bb7..ba808c88595c2 100644
--- a/core/templates/xml_exception.php
+++ b/core/templates/xml_exception.php
@@ -5,15 +5,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-function print_exception(Throwable $e, \OCP\IL10N $l): void {
- p($e->getTraceAsString());
-
- if ($e->getPrevious() !== null) {
- print_unescaped('');
- print_exception($e->getPrevious(), $l);
- print_unescaped('');
- }
-}
+require_once __DIR__ . '/print_xml_exception.php';
print_unescaped('' . "\n");
?>
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index 5fd5732cbe462..0eed55df0ba52 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -306,6 +306,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);
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index eb8aaffe1e03e..5436b553d1d29 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -69,6 +69,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
private $logger;
private bool $handleCopiesAsOwned;
+ private bool $preserveCacheItemsOnDelete = false;
/** @var bool */
protected $validateWrites = true;
@@ -204,7 +205,9 @@ private function rmObjects(ICacheEntry $entry): bool {
}
}
- $this->getCache()->remove($entry->getPath());
+ if (!$this->preserveCacheItemsOnDelete) {
+ $this->getCache()->remove($entry->getPath());
+ }
return true;
}
@@ -236,7 +239,9 @@ public function rmObject(ICacheEntry $entry): bool {
}
//removing from cache is ok as it does not exist in the objectstore anyway
}
- $this->getCache()->remove($entry->getPath());
+ if (!$this->preserveCacheItemsOnDelete) {
+ $this->getCache()->remove($entry->getPath());
+ }
return true;
}
@@ -481,13 +486,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 {
@@ -517,6 +519,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);
}
@@ -607,6 +613,73 @@ public function copyFromStorage(
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
+ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool {
+ $sourceCache = $sourceStorage->getCache();
+ if (!$sourceCacheEntry) {
+ $sourceCacheEntry = $sourceCache->get($sourceInternalPath);
+ }
+
+ $this->copyObjects($sourceStorage, $sourceCache, $sourceCacheEntry);
+ if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
+ /** @var ObjectStoreStorage $sourceStorage */
+ $sourceStorage->setPreserveCacheOnDelete(true);
+ }
+ if ($sourceCacheEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
+ $sourceStorage->rmdir($sourceInternalPath);
+ } else {
+ $sourceStorage->unlink($sourceInternalPath);
+ }
+ if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
+ /** @var ObjectStoreStorage $sourceStorage */
+ $sourceStorage->setPreserveCacheOnDelete(false);
+ }
+ $this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);
+
+ return true;
+ }
+
+ /**
+ * Copy the object(s) of a file or folder into this storage, without touching the cache
+ */
+ private function copyObjects(IStorage $sourceStorage, ICache $sourceCache, ICacheEntry $sourceCacheEntry) {
+ $copiedFiles = [];
+ try {
+ foreach ($this->getAllChildObjects($sourceCache, $sourceCacheEntry) as $file) {
+ $sourceStream = $sourceStorage->fopen($file->getPath(), 'r');
+ if (!$sourceStream) {
+ throw new \Exception("Failed to open source file {$file->getPath()} ({$file->getId()})");
+ }
+ $this->objectStore->writeObject($this->getURN($file->getId()), $sourceStream, $file->getMimeType());
+ if (is_resource($sourceStream)) {
+ fclose($sourceStream);
+ }
+ $copiedFiles[] = $file->getId();
+ }
+ } catch (\Exception $e) {
+ foreach ($copiedFiles as $fileId) {
+ try {
+ $this->objectStore->deleteObject($this->getURN($fileId));
+ } catch (\Exception $e) {
+ // ignore
+ }
+ }
+ throw $e;
+ }
+ }
+
+ /**
+ * @return \Iterator
+ */
+ private function getAllChildObjects(ICache $cache, ICacheEntry $entry): \Iterator {
+ if ($entry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
+ foreach ($cache->getFolderContentsById($entry->getId()) as $child) {
+ yield from $this->getAllChildObjects($cache, $child);
+ }
+ } else {
+ yield $entry;
+ }
+ }
+
public function copy($source, $target) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
@@ -738,4 +811,8 @@ public function cancelChunkedWrite(string $targetPath, string $writeToken): void
$urn = $this->getURN($cacheEntry->getId());
$this->objectStore->abortMultipartUpload($urn, $writeToken);
}
+
+ public function setPreserveCacheOnDelete(bool $preserve) {
+ $this->preserveCacheItemsOnDelete = $preserve;
+ }
}
diff --git a/lib/private/Files/ObjectStore/StorageObjectStore.php b/lib/private/Files/ObjectStore/StorageObjectStore.php
index 85926be897e1c..9f607fb7c25d1 100644
--- a/lib/private/Files/ObjectStore/StorageObjectStore.php
+++ b/lib/private/Files/ObjectStore/StorageObjectStore.php
@@ -45,8 +45,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();
}
/**
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php
index 87a4a810c0e51..2e6fcd9509991 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -48,6 +48,7 @@
use OC\Files\Cache\Updater;
use OC\Files\Cache\Watcher;
use OC\Files\Filesystem;
+use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\EmptyFileNameException;
@@ -698,10 +699,21 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
$result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true);
if ($result) {
- if ($sourceStorage->is_dir($sourceInternalPath)) {
- $result = $sourceStorage->rmdir($sourceInternalPath);
- } else {
- $result = $sourceStorage->unlink($sourceInternalPath);
+ if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
+ /** @var ObjectStoreStorage $sourceStorage */
+ $sourceStorage->setPreserveCacheOnDelete(true);
+ }
+ try {
+ if ($sourceStorage->is_dir($sourceInternalPath)) {
+ $result = $sourceStorage->rmdir($sourceInternalPath);
+ } else {
+ $result = $sourceStorage->unlink($sourceInternalPath);
+ }
+ } finally {
+ if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
+ /** @var ObjectStoreStorage $sourceStorage */
+ $sourceStorage->setPreserveCacheOnDelete(false);
+ }
}
}
return $result;
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php
index 1b5c8e6e5ffcd..29ba83d5cf902 100644
--- a/tests/lib/Files/Cache/CacheTest.php
+++ b/tests/lib/Files/Cache/CacheTest.php
@@ -13,6 +13,7 @@
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Search\ISearchComparison;
use OCP\IUser;
@@ -149,7 +150,7 @@ public function testFolder($folder) {
}
$file2 = $folder . '/bar';
$file3 = $folder . '/foo';
- $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$fileData = [];
$fileData['bar'] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'];
$fileData['foo'] = ['size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file'];
@@ -189,7 +190,7 @@ public function testFolder($folder) {
}
public function testRemoveRecursive() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$fileData = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'text/plain'];
$folders = ['folder', 'folder/subfolder', 'folder/sub2', 'folder/sub2/sub3'];
$files = ['folder/foo.txt', 'folder/bar.txt', 'folder/subfolder/asd.txt', 'folder/sub2/qwerty.txt', 'folder/sub2/sub3/foo.txt'];
@@ -225,7 +226,7 @@ public function testEncryptedFolder() {
$file1 = 'folder';
$file2 = 'folder/bar';
$file3 = 'folder/foo';
- $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$fileData = [];
$fileData['bar'] = ['size' => 1000, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file'];
$fileData['foo'] = ['size' => 20, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file'];
@@ -268,11 +269,10 @@ public function testRootFolderSizeForNonHomeStorage() {
$dir1 = 'knownsize';
$dir2 = 'unknownsize';
$fileData = [];
- $fileData[''] = ['size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData[$dir2] = ['size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory'];
+ $fileData[''] = ['size' => -1, 'mtime' => 20, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
+ $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
+ $fileData[$dir2] = ['size' => -1, 'mtime' => 25, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
- $this->cache->put('', $fileData['']);
$this->cache->put($dir1, $fileData[$dir1]);
$this->cache->put($dir2, $fileData[$dir2]);
@@ -339,7 +339,6 @@ public function testSearch() {
$this->assertEquals(1, count($this->cache->search('foo')));
$this->assertEquals(1, count($this->cache->search('%folder%')));
$this->assertEquals(1, count($this->cache->search('folder%')));
- $this->assertEquals(3, count($this->cache->search('%')));
// case insensitive search should match the same files
$this->assertEquals(2, count($this->cache->search('%Foo%')));
@@ -451,7 +450,7 @@ public function movePathProvider() {
*/
public function testMove($sourceFolder, $targetFolder, $children) {
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar'];
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
// create folders
foreach ([$sourceFolder, $targetFolder] as $current) {
@@ -538,6 +537,7 @@ public function testStorageMTime() {
public function testLongId() {
$storage = new LongId([]);
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$storageId = $storage->getId();
$data = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'];
$id = $cache->put('foo', $data);
@@ -566,7 +566,7 @@ public function testWithoutNormalizer() {
->method('normalize')
->willReturnArgument(0);
- $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
// put root folder
$this->assertFalse($cacheMock->get('folder'));
@@ -605,7 +605,7 @@ public function testWithNormalizer() {
// folder name "Schön" with U+0308 (un-normalized)
$folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
- $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
// put root folder
$this->assertFalse($this->cache->get('folder'));
@@ -644,12 +644,8 @@ public function bogusPathNamesProvider() {
* @dataProvider bogusPathNamesProvider
*/
public function testBogusPaths($bogusPath, $fixedBogusPath) {
- $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
-
- // put root folder
- $this->assertFalse($this->cache->get(''));
- $parentId = $this->cache->put('', $data);
- $this->assertGreaterThan(0, $parentId);
+ $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
+ $parentId = $this->cache->getId('');
$this->assertGreaterThan(0, $this->cache->put($bogusPath, $data));
@@ -703,7 +699,7 @@ public function testEscaping($name) {
$this->assertTrue($this->cache->inCache($name . 'asd'));
$this->cache->remove($name . 'asd');
$this->assertFalse($this->cache->inCache($name . 'asd'));
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->cache->put($name, $folderData);
$this->cache->put('other', $folderData);
$childs = ['asd', 'bar', 'foo', 'sub/folder'];
@@ -727,8 +723,7 @@ public function testEscaping($name) {
}
public function testExtended() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
- $this->cache->put("", $folderData);
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'creation_time' => 20];
$id1 = $this->cache->put("foo1", $data);
@@ -811,5 +806,7 @@ protected function setUp(): void {
$this->storage2 = new \OC\Files\Storage\Temporary([]);
$this->cache = new \OC\Files\Cache\Cache($this->storage);
$this->cache2 = new \OC\Files\Cache\Cache($this->storage2);
+ $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
}
}
diff --git a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php
index 6e1430d146bdc..644a458b2ea7d 100644
--- a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php
+++ b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php
@@ -9,6 +9,7 @@
namespace Test\Files\Cache;
use OC\Files\Cache\MoveFromCacheTrait;
+use OCP\Files\Cache\ICacheEntry;
class FallBackCrossCacheMoveCache extends \OC\Files\Cache\Cache {
use MoveFromCacheTrait;
@@ -27,5 +28,8 @@ protected function setUp(): void {
$this->storage2 = new \OC\Files\Storage\Temporary([]);
$this->cache = new FallBackCrossCacheMoveCache($this->storage);
$this->cache2 = new FallBackCrossCacheMoveCache($this->storage2);
+
+ $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
}
}
diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
index 8c96e7f84e5e9..4f8bd8945c69a 100644
--- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
@@ -14,6 +14,7 @@
use OC\Files\Storage\Wrapper\Jail;
use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Search\ISearchComparison;
use Test\Files\Cache\CacheTest;
@@ -32,17 +33,19 @@ class CacheJailTest extends CacheTest {
protected function setUp(): void {
parent::setUp();
- $this->storage->mkdir('foo');
+ $this->storage->mkdir('jail');
$this->sourceCache = $this->cache;
- $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'foo');
+ $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'jail');
+ $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
}
public function testSearchOutsideJail() {
$this->storage->getScanner()->scan('');
- $file1 = 'foo/foobar';
+ $file1 = 'jail/foobar';
$file2 = 'folder/foobar';
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
+ $this->sourceCache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$this->sourceCache->put($file1, $data1);
$this->sourceCache->put($file2, $data1);
@@ -53,20 +56,20 @@ public function testSearchOutsideJail() {
$this->assertEquals('foobar', $result[0]['path']);
$result = $this->cache->search('%foo%');
- $this->assertCount(2, $result);
+ $this->assertCount(1, $result);
usort($result, function ($a, $b) {
return $a['path'] <=> $b['path'];
});
- $this->assertEquals('', $result[0]['path']);
- $this->assertEquals('foobar', $result[1]['path']);
+ $this->assertEquals('foobar', $result[0]['path']);
}
public function testSearchMimeOutsideJail() {
$this->storage->getScanner()->scan('');
- $file1 = 'foo/foobar';
+ $file1 = 'jail/foobar';
$file2 = 'folder/foobar';
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
+ $this->sourceCache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$this->sourceCache->put($file1, $data1);
$this->sourceCache->put($file2, $data1);
@@ -79,10 +82,12 @@ public function testSearchMimeOutsideJail() {
public function testSearchQueryOutsideJail() {
$this->storage->getScanner()->scan('');
- $file1 = 'foo/foobar';
+ $file1 = 'jail/foobar';
$file2 = 'folder/foobar';
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
+
+ $this->sourceCache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$this->sourceCache->put($file1, $data1);
$this->sourceCache->put($file2, $data1);
@@ -93,19 +98,19 @@ public function testSearchQueryOutsideJail() {
$this->assertCount(1, $result);
$this->assertEquals('foobar', $result[0]['path']);
- $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo'), 10, 0, [], $user);
+ $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'jail'), 10, 0, [], $user);
$result = $this->cache->searchQuery($query);
$this->assertCount(1, $result);
$this->assertEquals('', $result[0]['path']);
}
public function testClearKeepEntriesOutsideJail() {
- $file1 = 'foo/foobar';
- $file2 = 'foo/foobar/asd';
+ $file1 = 'jail/foobar';
+ $file2 = 'jail/foobar/asd';
$file3 = 'folder/foobar';
- $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
- $this->sourceCache->put('foo', $data1);
+ $this->sourceCache->put('folder', $data1);
$this->sourceCache->put($file1, $data1);
$this->sourceCache->put($file2, $data1);
$this->sourceCache->put($file3, $data1);
@@ -117,8 +122,8 @@ public function testClearKeepEntriesOutsideJail() {
}
public function testGetById() {
- $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
- $id = $this->sourceCache->put('foo/bar', $data1);
+ $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
+ $id = $this->sourceCache->put('jail/bar', $data1);
// path from jailed foo of foo/bar is bar
$path = $this->cache->getPathById($id);
@@ -127,7 +132,7 @@ public function testGetById() {
// path from jailed '' of foo/bar is foo/bar
$this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
$path = $this->cache->getPathById($id);
- $this->assertEquals('foo/bar', $path);
+ $this->assertEquals('jail/bar', $path);
}
public function testGetIncomplete() {
@@ -136,7 +141,7 @@ public function testGetIncomplete() {
}
public function testMoveFromJail() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
@@ -152,7 +157,7 @@ public function testMoveFromJail() {
}
public function testMoveToJail() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
@@ -168,7 +173,7 @@ public function testMoveToJail() {
}
public function testMoveBetweenJail() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
@@ -186,9 +191,9 @@ public function testMoveBetweenJail() {
public function testSearchNested() {
$this->storage->getScanner()->scan('');
- $file1 = 'foo';
- $file2 = 'foo/bar';
- $file3 = 'foo/bar/asd';
+ $file1 = 'jail';
+ $file2 = 'jail/bar';
+ $file3 = 'jail/bar/asd';
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
$this->sourceCache->put($file1, $data1);
@@ -204,9 +209,9 @@ public function testSearchNested() {
public function testRootJail() {
$this->storage->getScanner()->scan('');
- $file1 = 'foo';
- $file2 = 'foo/bar';
- $file3 = 'foo/bar/asd';
+ $file1 = 'jail';
+ $file2 = 'jail/bar';
+ $file3 = 'jail/bar/asd';
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
$this->sourceCache->put($file1, $data1);
@@ -217,13 +222,13 @@ public function testRootJail() {
$result = $nested->search('%asd%');
$this->assertCount(1, $result);
- $this->assertEquals('foo/bar/asd', $result[0]['path']);
+ $this->assertEquals('jail/bar/asd', $result[0]['path']);
}
public function testWatcher() {
$storage = new Jail([
'storage' => $this->storage,
- 'root' => 'foo'
+ 'root' => 'jail'
]);
$storage->getScanner()->scan('');
$storage->file_put_contents('bar', 'asd');
@@ -236,7 +241,7 @@ public function testWatcher() {
public function testWatcherAfterInnerWatcher() {
$storage = new Jail([
'storage' => $this->storage,
- 'root' => 'foo'
+ 'root' => 'jail'
]);
$storage->getScanner()->scan('');
$storage->file_put_contents('bar', 'asd');
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index c6c3761ebe398..b798839b751dd 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -18,6 +18,7 @@
use OC\Files\Node\Folder;
use OC\Files\Node\Node;
use OC\Files\Node\Root;
+use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchOrder;
use OC\Files\Search\SearchQuery;
@@ -27,6 +28,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
+use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOrder;
use OCP\Files\Storage;
@@ -313,6 +315,7 @@ public function testSearch() {
->method('getInternalPath')
->willReturn('foo');
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
@@ -354,7 +357,10 @@ public function testSearchInRoot() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('files', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('files/foo', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
@@ -392,7 +398,10 @@ public function testSearchInStorageRoot() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
@@ -443,13 +452,19 @@ public function testSearchSubStorages() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$subStorage->method('getCache')
->willReturn($subCache);
+ $subStorage->method('getOwner')
+ ->willReturn('owner');
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
+ $subCache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$subCache->insert('asd', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$subCache->insert('asd/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
@@ -497,6 +512,8 @@ public function testGetById() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -544,6 +561,8 @@ public function testGetByIdMountRoot() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -587,6 +606,8 @@ public function testGetByIdOutsideFolder() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -630,6 +651,8 @@ public function testGetByIdMultipleStorages() {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->method('getMountsForFileId')
->with(1)
@@ -645,9 +668,6 @@ public function testGetByIdMultipleStorages() {
),
]);
- $storage->method('getCache')
- ->willReturn($cache);
-
$cache->method('get')
->with(1)
->willReturn($fileInfo);
@@ -725,6 +745,10 @@ public function testRecent(): void {
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar/foo', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar/asd', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$id1 = $cache->put('bar/foo/inside.txt', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
@@ -791,6 +815,9 @@ public function testRecentFolder() {
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar/foo', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$id1 = $cache->put('bar/foo/folder', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
@@ -858,6 +885,8 @@ public function testRecentJail() {
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$id1 = $cache->put('folder/inside.txt', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
@@ -865,6 +894,7 @@ public function testRecentJail() {
'size' => 3,
'permissions' => \OCP\Constants::PERMISSION_ALL,
]);
+
$cache->put('outside.txt', [
'storage_mtime' => $baseTime - 100,
'mtime' => $baseTime - 100,
@@ -949,9 +979,13 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$subStorage1->method('getCache')
->willReturn($subCache1);
+ $subStorage1->method('getOwner')
+ ->willReturn('owner');
$subMount2->method('getStorage')
->willReturn($subStorage2);
@@ -961,15 +995,22 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array
$subStorage2->method('getCache')
->willReturn($subCache2);
+ $subStorage2->method('getOwner')
+ ->willReturn('owner');
+
+ $cache->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$cache->insert('foo/foo1', ['size' => 200, 'mtime' => 10, 'mimetype' => 'text/plain']);
$cache->insert('foo/foo2', ['size' => 200, 'mtime' => 20, 'mimetype' => 'text/plain']);
$cache->insert('foo/foo3', ['size' => 200, 'mtime' => 30, 'mimetype' => 'text/plain']);
$cache->insert('foo/foo4', ['size' => 200, 'mtime' => 40, 'mimetype' => 'text/plain']);
+ $subCache1->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$subCache1->insert('foo5', ['size' => 300, 'mtime' => 15, 'mimetype' => 'text/plain']);
$subCache1->insert('foo6', ['size' => 300, 'mtime' => 50, 'mimetype' => 'text/plain']);
+ $subCache2->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$subCache2->insert('foo7', ['size' => 200, 'mtime' => 5, 'mimetype' => 'text/plain']);
$subCache2->insert('foo8', ['size' => 200, 'mtime' => 60, 'mimetype' => 'text/plain']);
@@ -983,7 +1024,11 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array
$node = new Folder($root, $view, '/bar/foo');
$comparison = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%foo%');
- $query = new SearchQuery($comparison, $limit, $offset, $ordering);
+ $operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
+ $comparison,
+ new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE)]),
+ ]);
+ $query = new SearchQuery($operator, $limit, $offset, $ordering);
$result = $node->search($query);
$cache->clear();
$subCache1->clear();
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
index 2f83574707716..a07104a590d64 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
@@ -89,7 +89,7 @@ public function testCheckUpdate() {
*/
public function testMove($source, $target) {
$this->initSourceAndTarget($source);
- $sourceId = $this->instance->getCache()->getId(ltrim('/', $source));
+ $sourceId = $this->instance->getCache()->getId(ltrim($source, '/'));
$this->assertNotEquals(-1, $sourceId);
$this->instance->rename($source, $target);
@@ -98,7 +98,7 @@ public function testMove($source, $target) {
$this->assertFalse($this->instance->file_exists($source), $source.' still exists');
$this->assertSameAsLorem($target);
- $targetId = $this->instance->getCache()->getId(ltrim('/', $target));
+ $targetId = $this->instance->getCache()->getId(ltrim($target, '/'));
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php
index a5f0c7f5dd33d..deaec64f04c66 100644
--- a/tests/lib/Repair/RepairMimeTypesTest.php
+++ b/tests/lib/Repair/RepairMimeTypesTest.php
@@ -49,6 +49,7 @@ protected function setUp(): void {
->willReturn('11.0.0.0');
$this->storage = new \OC\Files\Storage\Temporary([]);
+ $this->storage->getScanner()->scan('');
$this->repair = new \OC\Repair\RepairMimeTypes($config, \OC::$server->getDatabaseConnection());
}
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index 8aeb11faa022f..63d010644997b 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -96,7 +96,7 @@ public function testUserExistsSingleBackendNotExists() {
}
public function testUserExistsNoBackends() {
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher);
+ $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$this->assertFalse($manager->userExists('foo'));
}
@@ -430,7 +430,7 @@ public function testCreateUserSingleBackendNotSupported() {
}
public function testCreateUserNoBackends() {
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher);
+ $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$this->assertFalse($manager->createUser('foo', 'bar'));
}
@@ -498,7 +498,7 @@ public function testCreateUserTwoBackendExists() {
}
public function testCountUsersNoBackend() {
- $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher);
+ $manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
$result = $manager->countUsers();
$this->assertTrue(is_array($result));