Skip to content

Commit

Permalink
Do not check counter if metadata do not exists yet
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Jun 22, 2023
1 parent 3ac81df commit 72f2a48
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/LockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ public function lockFile(int $id, string $token = '', int $e2eCounter, string $o
$lock = $this->lockMapper->getByFileId($id);
return $lock->getToken() === $token ? $token : null;
} catch (DoesNotExistException $ex) {
$metaData = $this->metaDataStorage->getMetaData($ownerId, $id);
$decodedMetadata = json_decode($metaData, true);
// TODO, unsure counter is the proper property name.
if ($decodedMetadata['counter'] >= $e2eCounter) {
throw new NotPermittedException('Received counter is not greater than the stored one');
try {
$metaData = $this->metaDataStorage->getMetaData($ownerId, $id);
$decodedMetadata = json_decode($metaData, true);
// TODO: unsure counter is the proper property name.
if ($decodedMetadata['counter'] >= $e2eCounter) {
throw new NotPermittedException('Received counter is not greater than the stored one');
}
} catch (NotFoundException $e) {
// Do not check counter if the metadata do not exists yet.
}

$newToken = $this->getToken();
Expand Down

0 comments on commit 72f2a48

Please sign in to comment.