Skip to content

Commit

Permalink
Merge pull request #1134 from oat-sa/feat/REL-1723/update-flysystem-lib
Browse files Browse the repository at this point in the history
Upgrade flysystem dependency and usage
  • Loading branch information
augustas authored Nov 27, 2024
2 parents 9b60d48 + 769be77 commit 4158053
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 499 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest ]
php-version: [ '7.4', '8.0', '8.1' ]
php-version: [ '8.1', '8.2', '8.3' ]
include:
- php-version: '8.1'
- php-version: '8.3'
coverage: true

steps:
Expand Down
35 changes: 20 additions & 15 deletions common/oatbox/filesystem/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

namespace oat\oatbox\filesystem;

use League\Flysystem\FileExistsException;

class Directory extends FileSystemHandler implements \IteratorAggregate
{
public const ITERATOR_RECURSIVE = '1';
Expand Down Expand Up @@ -87,14 +85,13 @@ public function getFlyIterator($flags = null)
$contents = $this->getFileSystem()->listContents($this->getPrefix(), $recursive);

if (!empty($contents)) {
$dirPath = $this->getFileSystem()->get($this->getPrefix())->getPath();
foreach ($contents as $content) {
if ($withDirectories && $content['type'] == 'dir') {
$iterator[] = $this->getDirectory(str_replace($dirPath, '', $content['path']));
$iterator[] = $this->getDirectory($this->stripDirectoryPath($content['path']));
}

if ($withFiles && $content['type'] == 'file') {
$iterator[] = $this->getFile(str_replace($dirPath, '', $content['path']));
$iterator[] = $this->getFile($this->stripDirectoryPath($content['path']));
}
}
}
Expand Down Expand Up @@ -127,7 +124,7 @@ public function getRelPath($content)
*/
public function exists()
{
return $this->getFileSystem()->has($this->getPrefix());
return $this->getFileSystem()->directoryExists($this->getPrefix());
}

/**
Expand All @@ -137,7 +134,14 @@ public function exists()
*/
public function deleteSelf()
{
return $this->getFileSystem()->deleteDir($this->getPrefix());
try {
$this->getFileSystem()->deleteDirectory($this->getPrefix());
return true;
} catch (FilesystemException $e) {
$this->logWarning($e->getMessage());
}

return false;
}

/**
Expand Down Expand Up @@ -185,15 +189,10 @@ public function rename($path)

foreach ($filePaths as $renaming) {
try {
if ($this->getFileSystem()->rename($renaming['source'], $renaming['destination']) === false) {
throw new \common_exception_FileSystemError(
"Unable to rename '" . $renaming['source'] . "' into '" . $renaming['destination'] . "'."
);
}
} catch (FileExistsException $e) {
$this->getFileSystem()->move($renaming['source'], $renaming['destination']);
} catch (FilesystemException $e) {
throw new \common_exception_FileSystemError(
"Unable to rename '" . $renaming['source'] . "' into '" . $renaming['destination']
. "'. File already exists."
"Unable to rename '" . $renaming['source'] . "' into '" . $renaming['destination'] . "'."
);
}
}
Expand All @@ -206,4 +205,10 @@ public function rename($path)

return true;
}

private function stripDirectoryPath(string $path): string
{
$strippedPath = str_replace($this->getPrefix(), '', $path);
return str_replace($this->getFileSystemId(), '', $strippedPath);
}
}
Loading

0 comments on commit 4158053

Please sign in to comment.