nextcloud / files_lock

GNU Affero General Public License v3.0
24 stars 8 forks source link

Lock file in app scope #45

Closed juliushaertl closed 2 years ago

juliushaertl commented 2 years ago

For collaborative editing with Text, Nextcloud Office or ONLYOFFICE it would be useful if the collaborative editing app could lock a file on behalf of the editing session rather than per-user based. This way sync clients and the web UI could indicate the file lock while the app itself which handles changes can properly write to it.

The basic idea would be that the app can issue a lock/unlock through some kind of exposed API, similar to the user one in https://github.com/nextcloud/files_lock/blob/master/lib/Service/LockService.php#L237

Then when performing write actions the app would need to have a method to exclude further detection of locks for operation, so that any follow up filesystem actions would not trigger the locking in https://github.com/nextcloud/files_lock/blob/master/lib/Storage/LockWrapper.php#L110

From the app perspective I imagine something like this:

public function openFile($fileId) {
    $this->lockService->lockFileForApp($fileId, 'text');
}

public function writeFile($content) {
    $this->lockService->enableAppScope('text');
    $file->putContents($content); // does not throw a LockedException if the lock is owned by the same app id
}

public function closeFile($fileId) {
    $this->lockService->unlockFileForApp($fileId, 'text');
}
juliushaertl commented 2 years ago

Closing in favour of #51