Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function mkdir(string $path, bool $force = false, array $metadata = []):
private function normalizePath(string $path): string {
$path = trim($path, '/');
//FIXME why do we sometimes get a path like 'files//username'?
$path = str_replace('//', '/', $path);
$path = preg_replace('#/{2,}#', '/', $path);

// dirname('/folder') returns '.' but internally (in the cache) we store the root as ''
if (!$path || $path === '.') {
Expand Down Expand Up @@ -456,6 +456,7 @@ public function file_put_contents(string $path, mixed $data): int {
}

public function writeStream(string $path, $stream, ?int $size = null): int {
$path = $this->normalizePath($path);
if ($size === null) {
$stats = fstat($stream);
if (is_array($stats) && isset($stats['size'])) {
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ public function testStat(): void {
}
}

public function testWriteStreamNormalizesPath(): void {
$this->instance->mkdir('files');
$this->instance->mkdir('files/user');

$this->instance->file_put_contents('files//user/test.txt', 'foo');

$cache = $this->instance->getCache();
$this->assertTrue($cache->inCache('files/user/test.txt'));
$this->assertFalse($cache->inCache('files//user/test.txt'));
$this->assertEquals('foo', $this->instance->file_get_contents('files/user/test.txt'));
}

public function testCheckUpdate(): void {
$this->markTestSkipped('Detecting external changes is not supported on object storages');
}
Expand Down