fix moving files from external storage to object store trashbin

having the "cache rename" after the "storage move" caused the target
to get the fileid from the source file, without taking care that the object
is stored under the original file id.

By doing the "cache rename" first, we trigger the "update existing file"
logic while moving the file to the object store and the object gets stored for the
correct file id

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2020-06-29 18:14:47 +02:00
parent ba39d7adde
commit 5949849322
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 8 additions and 11 deletions

View File

@ -278,6 +278,8 @@ class Trashbin {
/** @var \OC\Files\Storage\Storage $sourceStorage */ /** @var \OC\Files\Storage\Storage $sourceStorage */
[$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath); [$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath);
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
try { try {
$moveSuccessful = true; $moveSuccessful = true;
if ($trashStorage->file_exists($trashInternalPath)) { if ($trashStorage->file_exists($trashInternalPath)) {
@ -301,8 +303,6 @@ class Trashbin {
return false; return false;
} }
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
if ($moveSuccessful) { if ($moveSuccessful) {
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)"); $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
$result = $query->execute([$filename, $timestamp, $location, $owner]); $result = $query->execute([$filename, $timestamp, $location, $owner]);

View File

@ -620,18 +620,15 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
} }
} else { } else {
$source = $sourceStorage->fopen($sourceInternalPath, 'r'); $source = $sourceStorage->fopen($sourceInternalPath, 'r');
// TODO: call fopen in a way that we execute again all storage wrappers if ($source) {
// to avoid that we bypass storage wrappers which perform important actions $result = $this->writeStream($targetInternalPath, $source) > 0;
// for this operation. Same is true for all other operations which } else {
// are not the same as the original one.Once this is fixed we also $result = false;
// need to adjust the encryption wrapper. }
$target = $this->fopen($targetInternalPath, 'w');
[, $result] = \OC_Helper::streamCopy($source, $target);
if ($result and $preserveMtime) { if ($result and $preserveMtime) {
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath)); $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
} }
fclose($source);
fclose($target);
if (!$result) { if (!$result) {
// delete partially written target file // delete partially written target file