Skip to content

Commit 97fbc66

Browse files
fix: catch ManuallyLockedException and use app context
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 <[email protected]>
1 parent f133f0e commit 97fbc66

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

apps/files_versions/lib/Storage.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,26 @@ private static function copyFileContents($view, $path1, $path2) {
436436
$view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
437437
$view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
438438

439-
// TODO add a proper way of overwriting a file while maintaining file ids
440-
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {
441-
$source = $storage1->fopen($internalPath1, 'r');
442-
$target = $storage2->fopen($internalPath2, 'w');
443-
[, $result] = \OC_Helper::streamCopy($source, $target);
444-
fclose($source);
445-
fclose($target);
446-
447-
if ($result !== false) {
448-
$storage1->unlink($internalPath1);
439+
try {
440+
// TODO add a proper way of overwriting a file while maintaining file ids
441+
if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {
442+
$source = $storage1->fopen($internalPath1, 'r');
443+
$target = $storage2->fopen($internalPath2, 'w');
444+
[, $result] = \OC_Helper::streamCopy($source, $target);
445+
fclose($source);
446+
fclose($target);
447+
448+
if ($result !== false) {
449+
$storage1->unlink($internalPath1);
450+
}
451+
} else {
452+
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
449453
}
450-
} else {
451-
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
454+
} finally {
455+
$view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
456+
$view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
452457
}
453458

454-
$view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
455-
$view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
456-
457459
return ($result !== false);
458460
}
459461

apps/files_versions/lib/Versions/VersionManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@
2727

2828
use OCP\Files\File;
2929
use OCP\Files\FileInfo;
30+
use OCP\Files\IRootFolder;
31+
use OCP\Files\Lock\ILock;
32+
use OCP\Files\Lock\ILockManager;
33+
use OCP\Files\Lock\LockContext;
3034
use OCP\Files\Storage\IStorage;
3135
use OCP\IUser;
36+
use OCP\Lock\ManuallyLockedException;
3237

3338
class VersionManager implements IVersionManager {
3439
/** @var (IVersionBackend[])[] */

0 commit comments

Comments
 (0)