mirror of
https://github.com/nextcloud/server.git
synced 2026-07-16 13:23:11 -04:00
fix: preserve fileid when moving from objectstore to non-objectstore
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
9fd7dfd1c2
commit
e85d5df5f0
3 changed files with 28 additions and 11 deletions
|
|
@ -8,7 +8,6 @@ namespace OCA\Files_Trashbin\Tests;
|
|||
|
||||
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;
|
||||
|
|
@ -672,10 +671,7 @@ class StorageTest extends \Test\TestCase {
|
|||
$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();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
|
|||
|
||||
private bool $handleCopiesAsOwned;
|
||||
protected bool $validateWrites = true;
|
||||
private bool $preserveCacheItemsOnDelete = false;
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
|
|
@ -173,7 +174,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
|
|||
}
|
||||
}
|
||||
|
||||
$this->getCache()->remove($entry->getPath());
|
||||
if (!$this->preserveCacheItemsOnDelete) {
|
||||
$this->getCache()->remove($entry->getPath());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -208,7 +211,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
|
|||
}
|
||||
//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;
|
||||
}
|
||||
|
||||
|
|
@ -765,4 +770,8 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
|
|||
$urn = $this->getURN($cacheEntry->getId());
|
||||
$this->objectStore->abortMultipartUpload($urn, $writeToken);
|
||||
}
|
||||
|
||||
public function setPreserveCacheOnDelete(bool $preserve) {
|
||||
$this->preserveCacheItemsOnDelete = $preserve;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use OC\Files\Cache\Updater;
|
|||
use OC\Files\Cache\Watcher;
|
||||
use OC\Files\FilenameValidator;
|
||||
use OC\Files\Filesystem;
|
||||
use OC\Files\ObjectStore\ObjectStoreStorage;
|
||||
use OC\Files\Storage\Wrapper\Jail;
|
||||
use OC\Files\Storage\Wrapper\Wrapper;
|
||||
use OCP\Files\ForbiddenException;
|
||||
|
|
@ -630,10 +631,21 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
|
|||
|
||||
$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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue