Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade flysystem dependency and usage #1134

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
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
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());
}
yaraslau-kavaliou marked this conversation as resolved.
Show resolved Hide resolved

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
Loading