Skip to content

fix: catch ManuallyLockedException and use app context - #37787

Merged
juliusknorr merged 1 commit into
masterfrom
fix/rollback-files-locked-by-apps
May 3, 2023
Merged

fix: catch ManuallyLockedException and use app context#37787
juliusknorr merged 1 commit into
masterfrom
fix/rollback-files-locked-by-apps

Conversation

@max-nextcloud

@max-nextcloudmax-nextcloud commented Apr 18, 2023

Copy link
Copy Markdown
Contributor

Summary

The files_lock app may throw ManuallyLockedExceptions when attempting to revert a file that is currently opened. This would prevent the user from rolling back a opened file.

Text and Richdocuments handle changes of the file while editing. Allow reverting files even when they are locked by these apps and let the apps handle the conflict.

Alternatives considered

I tried to tackle this in lower levels first:

  • Inside the Storage\LockWrapper in files_lock - but it turns out we use different functions (rename and fopen) to rollback to an old version depending on the storage type. The fopen happens separatedly for the source and the target and therefore it's impossible to detect that it was triggered by a version rollback.
  • Inside the Storage of files_version - it's possible to get a hold of the actual node there. But it would only fix the issue in the normal version storage. Separate fixes would still be required for collectives and group_folders and any other versioning implementation.

So i think this is the easiest way to go.

TODO

  • checked if this could be moved into the files_lock app - looks like it cannot due to load order issues. Once the files_lock app is loaded other apps might already have dependency injected the VersionsManager. So we cannot change it from within the files_lock app.

Checklist

Comment threadapps/files_versions/lib/Versions/VersionManager.php Fixed
Comment threadapps/files_versions/lib/Versions/VersionManager.php Fixed
Comment threadapps/files_versions/lib/Versions/VersionManager.php Fixed
Comment threadapps/files_versions/lib/Versions/VersionManager.php Fixed
@max-nextcloud
max-nextcloudforce-pushed the fix/rollback-files-locked-by-apps branch 2 times, most recently from 249f13b to 2e84a3fCompareApril 18, 2023 08:46
@solracsfsolracsf added this to the Nextcloud 27 milestone Apr 18, 2023
@solracsfsolracsf added the 3. to review Waiting for reviews label Apr 18, 2023
@max-nextcloud
max-nextcloudforce-pushed the fix/rollback-files-locked-by-apps branch from 2e84a3f to 254c039CompareApril 18, 2023 08:47
Comment threadapps/files_versions/lib/Versions/VersionManager.php Fixed
Comment threadapps/files_versions/lib/Versions/VersionManager.php Fixed
Comment threadapps/files_versions/lib/Versions/VersionManager.php Outdated
Comment threadapps/files_versions/lib/Versions/VersionManager.php Outdated
@max-nextcloud
max-nextcloudforce-pushed the fix/rollback-files-locked-by-apps branch 2 times, most recently from eba9a67 to f45f75fCompareApril 18, 2023 11:44

@artongeartonge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Typo, else nice 👍

Comment threadapps/files_versions/lib/Versions/VersionManager.php Outdated
@max-nextcloud

Copy link
Copy Markdown
ContributorAuthor

/backport to stable26

@max-nextcloud

Copy link
Copy Markdown
ContributorAuthor

/backport to stable25

@max-nextcloud

Copy link
Copy Markdown
ContributorAuthor

/backport to stable24

@max-nextcloud
max-nextcloudforce-pushed the fix/rollback-files-locked-by-apps branch 2 times, most recently from 71cb044 to 5378aa5CompareApril 20, 2023 11:29
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {
$source = $storage1->fopen($internalPath1, 'r');
$target = $storage2->fopen($internalPath2, 'w');
[, $result] = \OC_Helper::streamCopy($source, $target);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 2 of OC_Helper::streamCopy expects resource, but possibly different type bool|resource provided
$source = $storage1->fopen($internalPath1, 'r');
$target = $storage2->fopen($internalPath2, 'w');
[, $result] = \OC_Helper::streamCopy($source, $target);
fclose($source);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 1 of fclose expects resource, but possibly different type bool|mixed|resource provided
$target = $storage2->fopen($internalPath2, 'w');
[, $result] = \OC_Helper::streamCopy($source, $target);
fclose($source);
fclose($target);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 1 of fclose expects resource, but possibly different type bool|resource provided
$storage1->unlink($internalPath1);
try {
// TODO add a proper way of overwriting a file while maintaining file ids
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {

Check notice

Code scanning / Psalm

ArgumentTypeCoercion

Argument 1 of OC\Files\Storage\Storage::instanceOfStorage expects class-string<OCP\Files\Storage\IStorage>, but parent type "\\OC\\Files\\ObjectStore\\ObjectStoreStorage" provided
$storage1->unlink($internalPath1);
try {
// TODO add a proper way of overwriting a file while maintaining file ids
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {

Check notice

Code scanning / Psalm

ArgumentTypeCoercion

Argument 1 of OC\Files\Storage\Storage::instanceOfStorage expects class-string<OCP\Files\Storage\IStorage>, but parent type "\\OC\\Files\\ObjectStore\\ObjectStoreStorage" provided
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {
$source = $storage1->fopen($internalPath1, 'r');
$target = $storage2->fopen($internalPath2, 'w');
[, $result] = \OC_Helper::streamCopy($source, $target);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 1 of OC_Helper::streamCopy expects resource, but possibly different type bool|mixed|resource provided
@juliusknorrjuliusknorr added bug 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels May 3, 2023
The files_lock app may throw ManuallyLockedExceptions
when attempting to revert a file that is currently opened.
This would prevent the user from rolling back a opened file.
Text and Richdocuments handle changes of the file while editing.
Allow reverting files even when they are locked by these apps
and let the apps handle the conflict.
Signed-off-by: Max <max@nextcloud.com>
@max-nextcloud
max-nextcloudforce-pushed the fix/rollback-files-locked-by-apps branch from 5378aa5 to 337fc11CompareMay 3, 2023 07:53
$storage1->unlink($internalPath1);
try {
// TODO add a proper way of overwriting a file while maintaining file ids
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {

Check notice

Code scanning / Psalm

RedundantCondition

Type OC\Files\Storage\Storage for OC\Files\Storage\Storage is always OCP\Files\Storage\IStorage
@skjnldsvskjnldsv mentioned this pull request May 3, 2023
@juliusknorr

Copy link
Copy Markdown
Member

Failure unrelated

@backportbot-nextcloud

Copy link
Copy Markdown

The backport to stable24 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable24
git pull origin/stable24
# Create the new backport branch
git checkout -b fix/foo-stable24
# Cherry pick the change from the commit sha1 of the change against the default branch# This might cause conflicts. Resolve them.
git cherry-pick abc123
# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable24

More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport

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

Labels

4. to releaseReady to be released and/or waiting for tests to finishbug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old versions can not be restored from the sidebar because file is locked

6 participants

@max-nextcloud@juliusknorr@artonge@github-advanced-security@solracsf@skjnldsv