Skip to content

fix moving files from external storage to object store trashbin - #21628

Merged
MorrisJobke merged 4 commits into
masterfrom
external-to-s3-trashbin-fix
Jul 23, 2020
Merged

fix moving files from external storage to object store trashbin#21628
MorrisJobke merged 4 commits into
masterfrom
external-to-s3-trashbin-fix

Conversation

@icewind1991

Copy link
Copy Markdown
Member

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

@icewind1991icewind1991 added the 2. developing Work in progress label Jun 29, 2020
@kesselb

Copy link
Copy Markdown
Contributor

cc @dragon988

@SimplyCorbett

Copy link
Copy Markdown

I'm not using S3 anymore but the code looks good to me.

Comment threadlib/private/Files/Storage/Common.php Outdated
@icewind1991icewind1991 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 1, 2020
return (int)file_put_contents($this->getSourcePath($path), $stream);
$result = file_put_contents($this->getSourcePath($path), $stream);
if ($result === false) {
throw new GenericFileException("Failed write steam to $path");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

Comment threadlib/private/Files/Storage/Common.php
@icewind1991
icewind1991force-pushed the external-to-s3-trashbin-fix branch 2 times, most recently from 9fe6afe to 63efe79CompareJuly 3, 2020 12:41

@rullzerrullzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment threadlib/private/Files/Storage/Common.php

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good 👍 I refined one exception message to also include the path so that looking at the logs makes more sense later on.

@MorrisJobkeMorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish feature: external storage feature: object storage feature: trashbin and removed 3. to review Waiting for reviews labels Jul 6, 2020
@MorrisJobkeMorrisJobke added this to the Nextcloud 20 milestone Jul 6, 2020
@MorrisJobkeMorrisJobke added 2. developing Work in progress and removed 4. to release Ready to be released and/or waiting for tests to finish labels Jul 6, 2020
@MorrisJobke

Copy link
Copy Markdown
Member

PHPUnit fails

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>
Signed-off-by: Robin Appelman <robin@icewind.nl>
this remove the ambiguity when writing zero length files
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991
icewind1991force-pushed the external-to-s3-trashbin-fix branch from b5170c2 to ad7798fCompareJuly 23, 2020 13:25
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991

Copy link
Copy Markdown
MemberAuthor

ci fixed

@nextcloudnextcloud deleted a comment from faily-botBotJul 23, 2020
@MorrisJobke
MorrisJobke merged commit 173f8ab into masterJul 23, 2020
@MorrisJobke
MorrisJobke deleted the external-to-s3-trashbin-fix branch July 23, 2020 19:35
@icewind1991

Copy link
Copy Markdown
MemberAuthor

/backport to stable19

@icewind1991

Copy link
Copy Markdown
MemberAuthor

/backport to stable18

@MorrisJobke

Copy link
Copy Markdown
Member

So this breaks deleting files in an object store setup :/

@MorrisJobke

Copy link
Copy Markdown
Member
{
"reqId": "8eOJATfs8cPyjKQ5j2DI",
"level": 4,
"time": "2020-07-30T12:30:26+00:00",
"remoteAddr": "127.0.0.1",
"user": "admin",
"app": "webdav",
"method": "DELETE",
"url": "/remote.php/dav/files/admin/Bildschirmfoto%202020-07-29%20um%2017.50.40.png",
"message": {
"Exception": "TypeError",
"Message": "Argument 1 passed to OC\\Files\\Cache\\CacheQueryBuilder::whereFileId() must be of the type int, null given, called in /Users/morris/Projects/nextcloud/server/lib/private/Files/Cache/Cache.php on line 661",
"Code": 0,
"Trace": [
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Cache/Cache.php",
"line": 661,
"function": "whereFileId",
"class": "OC\\Files\\Cache\\CacheQueryBuilder",
"type": "->",
"args": [
null
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Cache/Cache.php",
"line": 585,
"function": "moveFromCache",
"class": "OC\\Files\\Cache\\Cache",
"type": "->",
"args": [
{
"__class__": "OC\\Files\\Cache\\Cache"
},
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/ObjectStore/ObjectStoreStorage.php",
"line": 347,
"function": "move",
"class": "OC\\Files\\Cache\\Cache",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Storage/Wrapper/Wrapper.php",
"line": 278,
"function": "rename",
"class": "OC\\Files\\ObjectStore\\ObjectStoreStorage",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Storage/Wrapper/Availability.php",
"line": 295,
"function": "rename",
"class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Storage/Wrapper/Wrapper.php",
"line": 278,
"function": "rename",
"class": "OC\\Files\\Storage\\Wrapper\\Availability",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Storage/Wrapper/Wrapper.php",
"line": 572,
"function": "rename",
"class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/files_trashbin/lib/Trashbin.php",
"line": 288,
"function": "moveFromStorage",
"class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
"type": "->",
"args": [
{
"cache": {
"__class__": "OC\\Files\\Cache\\Cache"
},
"scanner": null,
"watcher": null,
"propagator": {
"__class__": "OC\\Files\\Cache\\Propagator"
},
"updater": {
"__class__": "OC\\Files\\Cache\\Updater"
},
"__class__": "OCA\\Files_Trashbin\\Storage"
},
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"files_trashbin/files/Bildschirmfoto 2020-07-29 um 17.50.40.png.d1596112226"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php",
"line": 108,
"function": "move2trash",
"class": "OCA\\Files_Trashbin\\Trashbin",
"type": "::",
"args": [
"Bildschirmfoto 2020-07-29 um 17.50.40.png"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/files_trashbin/lib/Trash/TrashManager.php",
"line": 103,
"function": "moveToTrash",
"class": "OCA\\Files_Trashbin\\Trash\\LegacyTrashBackend",
"type": "->",
"args": [
{
"cache": {
"__class__": "OC\\Files\\Cache\\Cache"
},
"scanner": null,
"watcher": null,
"propagator": {
"__class__": "OC\\Files\\Cache\\Propagator"
},
"updater": {
"__class__": "OC\\Files\\Cache\\Updater"
},
"__class__": "OCA\\Files_Trashbin\\Storage"
},
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/files_trashbin/lib/Storage.php",
"line": 192,
"function": "moveToTrash",
"class": "OCA\\Files_Trashbin\\Trash\\TrashManager",
"type": "->",
"args": [
{
"cache": {
"__class__": "OC\\Files\\Cache\\Cache"
},
"scanner": null,
"watcher": null,
"propagator": {
"__class__": "OC\\Files\\Cache\\Propagator"
},
"updater": {
"__class__": "OC\\Files\\Cache\\Updater"
},
"__class__": "OCA\\Files_Trashbin\\Storage"
},
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/files_trashbin/lib/Storage.php",
"line": 99,
"function": "doDelete",
"class": "OCA\\Files_Trashbin\\Storage",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png",
"unlink"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/View.php",
"line": 1161,
"function": "unlink",
"class": "OCA\\Files_Trashbin\\Storage",
"type": "->",
"args": [
"files/Bildschirmfoto 2020-07-29 um 17.50.40.png"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/lib/private/Files/View.php",
"line": 718,
"function": "basicOperation",
"class": "OC\\Files\\View",
"type": "->",
"args": [
"unlink",
"/Bildschirmfoto 2020-07-29 um 17.50.40.png",
[
"delete"
]
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/dav/lib/Connector/Sabre/File.php",
"line": 455,
"function": "unlink",
"class": "OC\\Files\\View",
"type": "->",
"args": [
"/Bildschirmfoto 2020-07-29 um 17.50.40.png"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/3rdparty/sabre/dav/lib/DAV/Tree.php",
"line": 183,
"function": "delete",
"class": "OCA\\DAV\\Connector\\Sabre\\File",
"type": "->",
"args": []
},
{
"file": "/Users/morris/Projects/nextcloud/server/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
"line": 295,
"function": "delete",
"class": "Sabre\\DAV\\Tree",
"type": "->",
"args": [
"files/admin/Bildschirmfoto 2020-07-29 um 17.50.40.png"
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",
"line": 89,
"function": "httpDelete",
"class": "Sabre\\DAV\\CorePlugin",
"type": "->",
"args": [
{
"__class__": "Sabre\\HTTP\\Request"
},
{
"__class__": "Sabre\\HTTP\\Response"
}
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/3rdparty/sabre/dav/lib/DAV/Server.php",
"line": 474,
"function": "emit",
"class": "Sabre\\DAV\\Server",
"type": "->",
"args": [
"method:DELETE",
[
{
"__class__": "Sabre\\HTTP\\Request"
},
{
"__class__": "Sabre\\HTTP\\Response"
}
]
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/3rdparty/sabre/dav/lib/DAV/Server.php",
"line": 251,
"function": "invokeMethod",
"class": "Sabre\\DAV\\Server",
"type": "->",
"args": [
{
"__class__": "Sabre\\HTTP\\Request"
},
{
"__class__": "Sabre\\HTTP\\Response"
}
]
},
{
"file": "/Users/morris/Projects/nextcloud/server/3rdparty/sabre/dav/lib/DAV/Server.php",
"line": 319,
"function": "start",
"class": "Sabre\\DAV\\Server",
"type": "->",
"args": []
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/dav/lib/Server.php",
"line": 325,
"function": "exec",
"class": "Sabre\\DAV\\Server",
"type": "->",
"args": []
},
{
"file": "/Users/morris/Projects/nextcloud/server/apps/dav/appinfo/v2/remote.php",
"line": 35,
"function": "exec",
"class": "OCA\\DAV\\Server",
"type": "->",
"args": []
},
{
"file": "/Users/morris/Projects/nextcloud/server/remote.php",
"line": 167,
"args": [
"/Users/morris/Projects/nextcloud/server/apps/dav/appinfo/v2/remote.php"
],
"function": "require_once"
}
],
"File": "/Users/morris/Projects/nextcloud/server/lib/private/Files/Cache/CacheQueryBuilder.php",
"Line": 66,
"CustomMessage": "--"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15",
"version": "20.0.0.0"
}

The get() method of the cache returns false:

$sourceData = $sourceCache->get($sourcePath);

Bildschirmfoto 2020-07-30 um 14 41 34

@solracsf

solracsf commented Aug 1, 2020

Copy link
Copy Markdown
Member

Fix #19171 and #18132

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@icewind1991@kesselb@SimplyCorbett@MorrisJobke@solracsf@rullzer