Skip to content

Commit d6f6f5d

Browse files
committed
fix: prevent error when try to create a folder two times
The LibreSign folder is created by every event that need to fetch files from this folder. When we try to create a folder or a file, before to finish the creation proccess, the folder is locked by Nextcloud. To prevent this, I made first a get, if is not found, I try to create. Signed-off-by: Vitor Mattos <[email protected]>
1 parent 27b48f8 commit d6f6f5d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Service/FolderService.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\IGroupManager;
2222
use OCP\IL10N;
2323
use OCP\IUser;
24+
use OCP\Lock\LockedException;
2425

2526
class FolderService {
2627
protected IAppData $appData;
@@ -50,11 +51,19 @@ public function getUserId(): ?string {
5051
* @psalm-suppress MixedReturnStatement
5152
* @throws NotFoundException
5253
* @throws NotPermittedException
54+
* @throws LockedException
5355
*/
5456
public function getFolder(): Folder {
5557
$path = $this->getLibreSignDefaultPath();
5658
$containerFolder = $this->getContainerFolder();
57-
return $containerFolder->newFolder($path);
59+
try {
60+
/** @var Folder $folder */
61+
$folder = $containerFolder->get($path);
62+
} catch (NotFoundException) {
63+
/** @var Folder $folder */
64+
$folder = $containerFolder->newFolder($path);
65+
}
66+
return $folder;
5867
}
5968

6069
/**

0 commit comments

Comments
 (0)