Skip to content

Commit 3ee6aa1

Browse files
moodyjmzclaude
andcommitted
fix: return null for infinite lock timeout in DAV properties
When the lock timeout is configured as infinite (-1 minutes), getTimeout() returns -60 which clients incorrectly interpret as a past expiry timestamp. Use ETA_INFINITE sentinel check to return null instead, so nc:lock-timeout is omitted from PROPFIND/LOCK/UNLOCK responses for infinite locks. Adds regression test verifying that LOCK_TIMEOUT = -1 (the default) produces ETA_INFINITE rather than a negative timeout value. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
1 parent ee018db commit 3ee6aa1

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/DAV/LockPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function customProperties(PropFind $propFind, INode $node) {
139139
return null;
140140
}
141141

142-
return $lock->getTimeout();
142+
return $lock->getETA() === FileLock::ETA_INFINITE ? null : $lock->getTimeout();
143143
});
144144

145145
$propFind->handle(Application::DAV_PROPERTY_LOCK_OWNER_DISPLAYNAME, function () use ($nodeId, $node) {
@@ -278,7 +278,7 @@ private function getLockProperties(?FileLock $lock, Node $file): array {
278278
Application::DAV_PROPERTY_LOCK_OWNER_DISPLAYNAME => $lock ? $lock->getDisplayName() : null,
279279
Application::DAV_PROPERTY_LOCK_EDITOR => $lock ? $lock->getOwner() : null,
280280
Application::DAV_PROPERTY_LOCK_TIME => $lock ? $lock->getCreatedAt() : null,
281-
Application::DAV_PROPERTY_LOCK_TIMEOUT => $lock ? $lock->getTimeout() : null,
281+
Application::DAV_PROPERTY_LOCK_TIMEOUT => $lock && $lock->getETA() !== FileLock::ETA_INFINITE ? $lock->getTimeout() : null,
282282
Application::DAV_PROPERTY_LOCK_TOKEN => $lock ? $lock->getToken() : null,
283283
];
284284
}

tests/Feature/LockFeatureTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ public function testExtendLock() {
387387
$this->assertEquals($id, $locks[0]->getId());
388388
}
389389

390+
/**
391+
* Default config (LOCK_TIMEOUT = -1) must produce ETA_INFINITE, not a negative timestamp.
392+
* Regression: getTimeout() returned -60 which clients interpreted as a past expiry.
393+
*/
394+
public function testDefaultInfiniteTimeoutProducesEtaInfinite() {
395+
\OCP\Server::get(IConfig::class)->setAppValue(Application::APP_ID, ConfigService::LOCK_TIMEOUT, '-1');
396+
397+
$file = $this->loginAndGetUserFolder(self::TEST_USER1)->newFile('test-file', 'AAA');
398+
$this->lockManager->lock(new LockContext($file, ILock::TYPE_USER, self::TEST_USER1));
399+
$locks = $this->lockManager->getLocks($file->getId());
400+
401+
$this->assertCount(1, $locks);
402+
$this->assertEquals(FileLock::ETA_INFINITE, $locks[0]->getEta());
403+
}
404+
390405
/**
391406
* Regression test for https://github.com/nextcloud/files_lock/issues/130
392407
*/

0 commit comments

Comments
 (0)