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

Fixup preview issues with trashbin/versions #34283

Merged
merged 8 commits into from
Feb 18, 2019
Merged

Fixup preview issues with trashbin/versions #34283

merged 8 commits into from
Feb 18, 2019

Conversation

VicDeo
Copy link
Member

@VicDeo VicDeo commented Jan 28, 2019

Description

  • uid is always known - pass it within the version_delete hook info
  • pass original_path that contains a path to the versioned file
    and deleted_revision - versionId for the deleted version
  • pass an optional versionId to deleteAllPreviews when we need to remove previous for the specific version only
  • bonus 1: fix preview generation for files in deleted directories
  • bonus 2: cover some parts of files_versions with tests

Related Issue

Motivation and Context

  • Version previews are not deleted properly
  • Previews don't show for files in deleted directories
  • Versions and trash expiration is flooding the log file with exceptions related to the previews

How Has This Been Tested?

Case 1

  1. Create a text file "test.txt"
  2. Edit the file three times in the text editor and save each time, will create three versions
  3. Open the versions panel to have it generate previews
  4. Run cron.php and observe the logs

Expected result

version previews for cleaned up versions are deleted
No errors

Actual result

version previews for cleaned up versions are NOT deleted

{"reqId":"viyF6aTvAF41QBIxIu9B","level":3,"time":"2018-10-15T19:37:42+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"--","url":"--","message":"Exception: {\"Exception\":\"OCP\\\\Files\\\\NotFoundException\",\"Message\":\"\\\/test.txt.v1539632201 not found while trying to get owner\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Filesystem.php(961): OC\\\\Files\\\\View->getOwner('\\\/test.txt.v1539...')\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Preview.php(1241): OC\\\\Files\\\\Filesystem::getOwner('\\\/test.txt.v1539...')\\n#2 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/legacy\\\/hook.php(105): OC\\\\Preview::prepare_delete(Array)\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_versions\\\/lib\\\/Storage.php(765): OC_Hook::emit('\\\\\\\\OCP\\\\\\\\Versions', 'preDelete', Array)\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_versions\\\/lib\\\/Command\\\/Expire.php(60): OCA\\\\Files_Versions\\\\Storage::expire('\\\/test.txt', 'admin')\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Command\\\/CommandJob.php(34): OCA\\\\Files_Versions\\\\Command\\\\Expire->handle()\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/BackgroundJob\\\/Job.php(57): OC\\\\Command\\\\CommandJob->run('O:33:\\\"OCA\\\\\\\\Files...')\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/BackgroundJob\\\/QueuedJob.php(42): OC\\\\BackgroundJob\\\\Job->execute(Object(OC\\\\BackgroundJob\\\\JobList), Object(OC\\\\Log))\\n#8 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/cron.php(120): OC\\\\BackgroundJob\\\\QueuedJob->execute(Object(OC\\\\BackgroundJob\\\\JobList), Object(OC\\\\Log))\\n#9 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php\",\"Line\":1717}"}
{"reqId":"viyF6aTvAF41QBIxIu9B","level":3,"time":"2018-10-15T19:37:42+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"--","url":"--","message":"Exception: {\"Exception\":\"OCP\\\\Files\\\\NotFoundException\",\"Message\":\"\\\/test.txt.v1539632201 not found while trying to get owner\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Filesystem.php(961): OC\\\\Files\\\\View->getOwner('\\\/test.txt.v1539...')\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Preview.php(1311): OC\\\\Files\\\\Filesystem::getOwner('\\\/test.txt.v1539...')\\n#2 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Preview.php(1299): OC\\\\Preview::post_delete(Array, 'files\\\/')\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/legacy\\\/hook.php(105): OC\\\\Preview::post_delete_versions(Array)\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_versions\\\/lib\\\/Storage.php(767): OC_Hook::emit('\\\\\\\\OCP\\\\\\\\Versions', 'delete', Array)\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files_versions\\\/lib\\\/Command\\\/Expire.php(60): OCA\\\\Files_Versions\\\\Storage::expire('\\\/test.txt', 'admin')\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Command\\\/CommandJob.php(34): OCA\\\\Files_Versions\\\\Command\\\\Expire->handle()\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/BackgroundJob\\\/Job.php(57): OC\\\\Command\\\\CommandJob->run('O:33:\\\"OCA\\\\\\\\Files...')\\n#8 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/BackgroundJob\\\/QueuedJob.php(42): OC\\\\BackgroundJob\\\\Job->execute(Object(OC\\\\BackgroundJob\\\\JobList), Object(OC\\\\Log))\\n#9 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/cron.php(120): OC\\\\BackgroundJob\\\\QueuedJob->execute(Object(OC\\\\BackgroundJob\\\\JobList), Object(OC\\\\Log))\\n#10 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php\",\"Line\":1717}"}

Case 2

  1. create a text files, edit it several times
  2. open versions to create a previews for versions
  3. edit file one more time

Expected result

Only file previews are deleted

Actual result

File previews and all versions previews are deleted

Case 3

delete a directory with a file and browse to the file in the trashbin

Expected result

File in deleted directory has a prievew

Actual result

No file preview

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

@VicDeo VicDeo added this to the development milestone Jan 28, 2019
@VicDeo VicDeo self-assigned this Jan 28, 2019
@codecov
Copy link

codecov bot commented Jan 28, 2019

Codecov Report

Merging #34283 into master will increase coverage by 0.04%.
The diff coverage is 63.37%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #34283      +/-   ##
============================================
+ Coverage     65.11%   65.15%   +0.04%     
- Complexity    18338    18352      +14     
============================================
  Files          1199     1200       +1     
  Lines         69634    69698      +64     
  Branches       1283     1283              
============================================
+ Hits          45340    45413      +73     
+ Misses        23920    23911       -9     
  Partials        374      374
Flag Coverage Δ Complexity Δ
#javascript 53.1% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 66.55% <63.37%> (+0.04%) 18352 <44> (+14) ⬆️
Impacted Files Coverage Δ Complexity Δ
apps/files_trashbin/ajax/preview.php 0% <0%> (ø) 0 <0> (ø) ⬇️
apps/files_versions/lib/AppInfo/Application.php 100% <100%> (ø) 3 <1> (+1) ⬆️
apps/files_versions/lib/Storage.php 72.67% <24.39%> (+1.28%) 95 <10> (-9) ⬇️
lib/private/Preview.php 80.12% <58.49%> (+1.38%) 178 <17> (+8) ⬆️
apps/files_trashbin/lib/Trashbin.php 77.7% <85.71%> (+0.29%) 146 <2> (ø) ⬇️
apps/files_versions/lib/FileHelper.php 92.72% <92.72%> (ø) 14 <14> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b875f06...fca5873. Read the comment docs.

@owncloud owncloud deleted a comment from codecov bot Jan 30, 2019
@VicDeo VicDeo force-pushed the fix-32346 branch 5 times, most recently from b7228de to 4cd2eda Compare January 31, 2019 21:49
@VicDeo VicDeo force-pushed the fix-32346 branch 3 times, most recently from 1bc87b2 to eb05df4 Compare January 31, 2019 23:05
Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

See comments.

I wonder if this is enough as there might be other code paths related to trashbin: try having version previews for files that were deleted in trashbin, the trigger trashbin expiration. This will like trigger https://github.com/owncloud/enterprise/issues/3067 and might trigger some other hook methods.

@PVince81
Copy link
Contributor

PVince81 commented Feb 1, 2019

I like how you refactored the static methods to be able to write tests!

@PVince81
Copy link
Contributor

PVince81 commented Feb 1, 2019

codecov however seems less enthusiastic... and fails to load 😡

@VicDeo
Copy link
Member Author

VicDeo commented Feb 1, 2019

codecov however seems less enthusiastic... and fails to load

@PVince81
it annoys me the most because I need to see what else can be covered there instead of using 🔮 and reading the stars for that purpose

@VicDeo
Copy link
Member Author

VicDeo commented Feb 1, 2019

I wonder if this is enough as there might be other code paths related to trashbin: try having version previews for files that were deleted in trashbin, the trigger trashbin expiration. This will like trigger owncloud/enterprise#3067 and might trigger some other hook methods.

@PVince81
I tried to delete the test file after steps 1-3 from the PR description
Results:

  • directory data/D/thumbnails/2147496457/ was deleted so no preview of any kind exists anymore.
  • after browsing to trashbin previews for the file data/D/thumbnails/2147496457/ were recreated
    previews for versions were NOT recreated after viewing the file in trashbin.

here is log (nothing fishy)

{"reqId":"952b0382-c5d9-4f17-904e-ebb3647cb83d","level":1,"time":"2019-02-01T16:34:35+00:00","remoteAddr":"127.0.0.1","user":"D","app":"admin_audit","method":"GET","url":"\/~deo\/oc-tmp\/remote.php\/dav\/files\/D\/bebe.txt","message":"Read \"\/D\/files\/bebe.txt\" by user <D>, displayName <Dryndyndyn>, owner: D [CLIENT_IP: 127.0.0.1] [USER_AGENT: Mozilla\/5.0 (Linux) mirall\/2.5.2 (build 268)]"}
{"reqId":"uZHeLxVvFDf2HZX1gS4U","level":0,"time":"2019-02-01T16:35:04+00:00","remoteAddr":"127.0.0.1","user":"D","app":"core","method":"GET","url":"\/~deo\/oc-tmp\/remote.php\/dav\/meta\/2147496457\/v\/1549038093?preview","message":"Generating preview for \"\/meta\/2147496457\/v\/1549038093\" with \"OC\\Preview\\TXT\""}
{"reqId":"S6IUMO4v2hUmT44uHYvy","level":0,"time":"2019-02-01T16:35:04+00:00","remoteAddr":"127.0.0.1","user":"D","app":"core","method":"GET","url":"\/~deo\/oc-tmp\/remote.php\/dav\/meta\/2147496457\/v\/1549038077?preview","message":"Generating preview for \"\/meta\/2147496457\/v\/1549038077\" with \"OC\\Preview\\TXT\""}
{"reqId":"qxEPyFCMFNDb25iyDUsk","level":0,"time":"2019-02-01T16:35:05+00:00","remoteAddr":"127.0.0.1","user":"D","app":"core","method":"GET","url":"\/~deo\/oc-tmp\/remote.php\/dav\/meta\/2147496457\/v\/1549038084?preview","message":"Generating preview for \"\/meta\/2147496457\/v\/1549038084\" with \"OC\\Preview\\TXT\""}
{"reqId":"VxXof4wusgbt9efZIhKO","level":1,"time":"2019-02-01T16:35:18+00:00","remoteAddr":"127.0.0.1","user":"D","app":"admin_audit","method":"DELETE","url":"\/~deo\/oc-tmp\/remote.php\/dav\/files\/D\/bebe.txt","message":"Delete \"\/D\/files\/bebe.txt\" by user <D>, displayName <Dryndyndyn>, owner: D [CLIENT_IP: 127.0.0.1] [USER_AGENT: Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/72.0.3626.81 Safari\/537.36]"}
{"reqId":"6RtK4Es9C3bSFanQm7sF","level":0,"time":"2019-02-01T16:40:48+00:00","remoteAddr":"127.0.0.1","user":"D","app":"core","method":"GET","url":"\/~deo\/oc-tmp\/index.php\/apps\/files_trashbin\/ajax\/preview.php?file=%2Fbebe.txt.d1549038918&c=1549038918000","message":"Generating preview for \"\/D\/files_trashbin\/files\/bebe.txt.d1549038918\" with \"OC\\Preview\\TXT\""}

So there is nothing to fix for the trashbin IMO unless such agressive deletion of preview is unexpected

@VicDeo
Copy link
Member Author

VicDeo commented Feb 1, 2019

The fix is incomplete, preDelete hook should also have the same changes.
The same applies to trashbin as for trashbin '/files' is added after userid producing weird path like
/D/files/files_trashbin/files/bebe.txt.d1549039401 as a result

@VicDeo VicDeo force-pushed the fix-32346 branch 4 times, most recently from 80a8195 to 806866d Compare February 1, 2019 20:46
@PVince81
Copy link
Contributor

PVince81 commented Feb 4, 2019

So there is nothing to fix for the trashbin IMO unless such agressive deletion of preview is unexpected

I seem to remember that the code was deleting more than just the expected previews, which is a bit brutal. Can you recheck the exact path that is getting deleted from the code ?

@VicDeo
Copy link
Member Author

VicDeo commented Feb 7, 2019

@PVince81

the code was deleting more than just the expected previews, which is a bit brutal.

it's due \OC\Preview::post_write hands off the job to \OC\Preview::post_delete which removes all previews (including version previews) by default.

@VicDeo VicDeo force-pushed the fix-32346 branch 2 times, most recently from 8749a66 to 47c0735 Compare February 15, 2019 15:05
@VicDeo VicDeo changed the title Remove all previews for the version on deletion Fixup preview issues Feb 15, 2019
@VicDeo VicDeo changed the title Fixup preview issues Fixup preview issues with trashbin/versions Feb 15, 2019
@VicDeo
Copy link
Member Author

VicDeo commented Feb 15, 2019

@PVince81 description updated to describe 3 bugs that are already fixed in this PR.
Only trashbin expiration is left to fix.

@VicDeo
Copy link
Member Author

VicDeo commented Feb 15, 2019

I'll list my expectations here. This is how the things work within this PR:

  1. file preview is created when the file is opened in a file list as /user/thumbnails/fileId/x-y.png
  2. version preview is created when the version is listed in the versions tab as /user/thumbnails/fileId/versionId/x-y.png
  3. All file previews are deleted when file is updated: all /user/thumbnails/fileId/*.png are deleted
  4. All version previews are kept when file is updated /user/thumbnails/fileId/versionId/ still exists
  5. File preview is deleted when the file is moved to trashbin: entire /user/thumbnails/fileId/ directory is deleted
  6. Versions previews are deleted when the file is moved to trashbin: entire /user/thumbnails/fileId/ directory is deleted
  7. After browsing to the file in the trashbin preview is recreated in /user/thumbnails/fileId/
  8. After browsing to the file in the version previews are not recreated in /user/thumbnails/fileId/
  9. After a file with a preview is deleted from trashbin - preview is deleted: entire /user/thumbnails/fileId/ directory is deleted
  10. After a file with a preview is restored from trashbin - previews are kept

@VicDeo
Copy link
Member Author

VicDeo commented Feb 18, 2019

@PVince81 please rereview

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

some minor questions

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍

@PVince81 PVince81 merged commit 2ec2839 into master Feb 18, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix-32346 branch February 18, 2019 14:18
@PVince81
Copy link
Contributor

@VicDeo please backport

@VicDeo
Copy link
Member Author

VicDeo commented Feb 18, 2019

stable10: #34533

@lock lock bot locked as resolved and limited conversation to collaborators Feb 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[10.0.9]Trying to get owner from an erased file
2 participants