Skip to content

Commit

Permalink
use correct clock interface for 25
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Oct 25, 2023
1 parent 2bea43b commit 99e84de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions apps/files_external/lib/Config/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorageFactory;
use OCP\Files\StorageNotAvailableException;
use OCP\IUser;
use Psr\Clock\ClockInterface;

/**
* Make the old files_external config work with the new public mount config api
Expand All @@ -50,7 +50,7 @@ class ConfigAdapter implements IMountProvider {
public function __construct(
private UserStoragesService $userStoragesService,
private UserGlobalStoragesService $userGlobalStoragesService,
private ClockInterface $clock,
private ITimeFactory $clock,
) {}

/**
Expand Down
29 changes: 14 additions & 15 deletions lib/private/Files/Storage/Wrapper/KnownMtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace OC\Files\Storage\Wrapper;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Cache\CappedMemoryCache;
use OCP\Files\Storage\IStorage;
use Psr\Clock\ClockInterface;

/**
* Wrapper that overwrites the mtime return by stat/getMetaData if the returned value
Expand All @@ -14,7 +14,7 @@
*/
class KnownMtime extends Wrapper {
private CappedMemoryCache $knowMtimes;
private ClockInterface $clock;
private ITimeFactory $clock;

public function __construct($arguments) {
parent::__construct($arguments);
Expand All @@ -25,8 +25,7 @@ public function __construct($arguments) {
public function file_put_contents($path, $data) {
$result = parent::file_put_contents($path, $data);
if ($result) {
$now = $this->clock->now()->getTimestamp();
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $this->clock->getTime());
}
return $result;
}
Expand Down Expand Up @@ -62,80 +61,80 @@ public function filemtime($path) {
public function mkdir($path) {
$result = parent::mkdir($path);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $this->clock->getTime());
}
return $result;
}

public function rmdir($path) {
$result = parent::rmdir($path);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $this->clock->getTime());
}
return $result;
}

public function unlink($path) {
$result = parent::unlink($path);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $this->clock->getTime());
}
return $result;
}

public function rename($source, $target) {

Check failure on line 85 in lib/private/Files/Storage/Wrapper/KnownMtime.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParamNameMismatch

lib/private/Files/Storage/Wrapper/KnownMtime.php:85:25: ParamNameMismatch: Argument 1 of OC\Files\Storage\Wrapper\KnownMtime::rename has wrong name $source, expecting $path1 as defined by OCP\Files\Storage\IStorage::rename (see https://psalm.dev/230)

Check failure on line 85 in lib/private/Files/Storage/Wrapper/KnownMtime.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParamNameMismatch

lib/private/Files/Storage/Wrapper/KnownMtime.php:85:34: ParamNameMismatch: Argument 2 of OC\Files\Storage\Wrapper\KnownMtime::rename has wrong name $target, expecting $path2 as defined by OCP\Files\Storage\IStorage::rename (see https://psalm.dev/230)

Check failure

Code scanning / Psalm

ParamNameMismatch Error

Argument 1 of OC\Files\Storage\Wrapper\KnownMtime::rename has wrong name $source, expecting $path1 as defined by OCP\Files\Storage\IStorage::rename

Check failure

Code scanning / Psalm

ParamNameMismatch Error

Argument 2 of OC\Files\Storage\Wrapper\KnownMtime::rename has wrong name $target, expecting $path2 as defined by OCP\Files\Storage\IStorage::rename
$result = parent::rename($source, $target);
if ($result) {
$this->knowMtimes->set($target, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($source, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($target, $this->clock->getTime());
$this->knowMtimes->set($source, $this->clock->getTime());
}
return $result;
}

public function copy($source, $target) {

Check failure on line 94 in lib/private/Files/Storage/Wrapper/KnownMtime.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParamNameMismatch

lib/private/Files/Storage/Wrapper/KnownMtime.php:94:23: ParamNameMismatch: Argument 1 of OC\Files\Storage\Wrapper\KnownMtime::copy has wrong name $source, expecting $path1 as defined by OCP\Files\Storage\IStorage::copy (see https://psalm.dev/230)

Check failure on line 94 in lib/private/Files/Storage/Wrapper/KnownMtime.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParamNameMismatch

lib/private/Files/Storage/Wrapper/KnownMtime.php:94:32: ParamNameMismatch: Argument 2 of OC\Files\Storage\Wrapper\KnownMtime::copy has wrong name $target, expecting $path2 as defined by OCP\Files\Storage\IStorage::copy (see https://psalm.dev/230)

Check failure

Code scanning / Psalm

ParamNameMismatch Error

Argument 1 of OC\Files\Storage\Wrapper\KnownMtime::copy has wrong name $source, expecting $path1 as defined by OCP\Files\Storage\IStorage::copy

Check failure

Code scanning / Psalm

ParamNameMismatch Error

Argument 2 of OC\Files\Storage\Wrapper\KnownMtime::copy has wrong name $target, expecting $path2 as defined by OCP\Files\Storage\IStorage::copy
$result = parent::copy($source, $target);
if ($result) {
$this->knowMtimes->set($target, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($target, $this->clock->getTime());
}
return $result;
}

public function fopen($path, $mode) {
$result = parent::fopen($path, $mode);
if ($result && $mode === 'w') {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $this->clock->getTime());
}
return $result;
}

public function touch($path, $mtime = null) {
$result = parent::touch($path, $mtime);
if ($result) {
$this->knowMtimes->set($path, $mtime ?? $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $mtime ?? $this->clock->getTime());
}
return $result;
}

public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
$result = parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
if ($result) {
$this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($targetInternalPath, $this->clock->getTime());
}
return $result;
}

public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
$result = parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
if ($result) {
$this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($targetInternalPath, $this->clock->getTime());
}
return $result;
}

public function writeStream(string $path, $stream, int $size = null): int {
$result = parent::writeStream($path, $stream, $size);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
$this->knowMtimes->set($path, $this->clock->getTime());
}
return $result;
}
Expand Down
14 changes: 5 additions & 9 deletions tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\KnownMtime;
use OCP\AppFramework\Utility\ITimeFactory;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Clock\ClockInterface;
use Test\Files\Storage\Storage;

/**
Expand All @@ -21,21 +21,17 @@ class KnownMtimeTest extends Storage {
/** @var Temporary */
private $sourceStorage;

/** @var ClockInterface|MockObject */
/** @var ITimeFactory|MockObject */
private $clock;
private int $fakeTime = 0;

protected function setUp(): void {
parent::setUp();
$this->fakeTime = 0;
$this->sourceStorage = new Temporary([]);
$this->clock = $this->createMock(ClockInterface::class);
$this->clock->method('now')->willReturnCallback(function () {
if ($this->fakeTime) {
return new \DateTimeImmutable("@{$this->fakeTime}");
} else {
return new \DateTimeImmutable();
}
$this->clock = $this->createMock(ITimeFactory::class);
$this->clock->method('getTime')->willReturnCallback(function () {
return $this->fakeTime;
});
$this->instance = $this->getWrappedStorage();
}
Expand Down

0 comments on commit 99e84de

Please sign in to comment.