Skip to content

Commit

Permalink
Merge pull request #194 from aedart/fix-contents-listing
Browse files Browse the repository at this point in the history
Fix contents listing
  • Loading branch information
aedart authored Jun 27, 2024
2 parents ba5fc94 + 91e7b6c commit 463635f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

* Updated dependencies (_service update_).

### Fixed

* Incorrect contents listing, due to missing separator affix in path (_in `DatabaseAdapter`_). [#193](https://github.com/aedart/athenaeum/issues/193).

## [8.5.0] - 2024-06-18

### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/Flysystem/Db/src/Adapters/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ protected function performContentsListing(
function (Builder $query) use ($path) {
$query
->where('path', '=', $path)
->orWhere('path', 'LIKE', "{$path}%");
->orWhere('path', 'LIKE', "{$path}/%");
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,87 @@ public function canListDirectoriesAndFiles(): void

$this->assertCount(15, $list);
}

/**
* @test
*
* @return void
*
* @throws \League\Flysystem\FilesystemException
*/
public function doesNotListContentsFromOtherDirectoriesWithSimilarPath(): void
{
// @see https://github.com/aedart/athenaeum/issues/193

$directories = [
'home/projects/2/src',
'home/projects/22/src', // Notice that this path is similar to previous (starts with "home/projects/2...")
// The adapter should NOT list files from this directory, unless requested!
'home/projects/3/src',
'home/utils',
];

$this->createDirectories($directories);

// ---------------------------------------------------------------- //

$pathA = 'home/projects/2/README.txt';
$pathB = 'home/projects/2/src/book.txt';

$pathC = 'home/projects/22/people.txt';
$pathD = 'home/projects/22/src/cookbook.txt';

$pathE = 'home/projects/3/README.txt';
$pathF = 'home/projects/3/src/book.txt';

$fs = $this->filesystem();

$fs->write($pathA, $this->getFaker()->sentence());
$fs->write($pathB, $this->getFaker()->sentence());
$fs->write($pathC, $this->getFaker()->sentence());
$fs->write($pathD, $this->getFaker()->sentence());
$fs->write($pathE, $this->getFaker()->sentence());
$fs->write($pathF, $this->getFaker()->sentence());

// ---------------------------------------------------------------- //
// List directories inside "project a"

$list = $this
->filesystem()
->listContents('home/projects/2')
->toArray();

ConsoleDebugger::output($list);

$this->assertCount(2, $list);
$this->assertSame('home/projects/2/README.txt', $list[0]->path());
$this->assertSame('home/projects/2/src', $list[1]->path());

// ---------------------------------------------------------------- //
// List directories inside "project a" deep

$list = $this
->filesystem()
->listContents('home/projects/2', true)
->toArray();

ConsoleDebugger::output($list);

$this->assertCount(3, $list);
$this->assertSame('home/projects/2/README.txt', $list[0]->path());
$this->assertSame('home/projects/2/src', $list[1]->path());
$this->assertSame('home/projects/2/src/book.txt', $list[2]->path());

// ---------------------------------------------------------------- //
// List all directories and files

$list = $this
->filesystem()
->listContents('', true)
->toArray();

ConsoleDebugger::output($list);

$this->assertCount(15, $list);
}
}

0 comments on commit 463635f

Please sign in to comment.