Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use Symfony/filesystem #1601

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

Merged
merged 17 commits into from
Mar 16, 2022
Merged

Use Symfony/filesystem #1601

merged 17 commits into from
Mar 16, 2022

Conversation

tvdijen
Copy link
Member

@tvdijen tvdijen commented Feb 25, 2022

Instead of making our lives difficult, we should be using the already available symfony/filesystem.
Added bonus is that these classes can be DI'ed for unit testing purposes.

Note: I haven't field-tested this change yet and we may want to add more cases.

@tvdijen tvdijen force-pushed the filesystem branch 18 times, most recently from 3bdb5c1 to 1f907fa Compare March 1, 2022 17:16
@codecov
Copy link

codecov bot commented Mar 1, 2022

Codecov Report

Merging #1601 (318709e) into master (6c3e866) will increase coverage by 0.02%.
The diff coverage is 24.33%.

@@             Coverage Diff              @@
##             master    #1601      +/-   ##
============================================
+ Coverage     42.33%   42.36%   +0.02%     
+ Complexity     3457     3449       -8     
============================================
  Files           143      143              
  Lines         10029    10039      +10     
============================================
+ Hits           4246     4253       +7     
- Misses         5783     5786       +3     

$string = str_replace($formats, $replacements, $string);
file_put_contents($this->logFile, $string . \PHP_EOL, FILE_APPEND);
if (preg_match('/^php:\/\//', $this->logFile)) {
// Dirty hack to get unit tests for Windows working.. Symfony doesn't deal well with them.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't get a response, I've opened an issue for this: symfony/symfony#45749

@tvdijen tvdijen force-pushed the filesystem branch 5 times, most recently from 0466064 to 8b7736f Compare March 1, 2022 23:17
@tvdijen tvdijen requested a review from thijskh March 1, 2022 23:32
@tvdijen
Copy link
Member Author

tvdijen commented Mar 1, 2022

Still have to test this, but a first review wouldn't hurt

Copy link
Member

@thijskh thijskh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in principle. It does save some code we can reuse from Symfony. I would think to depend as much as possible on this code: one advantage of changing this is that we can use the error handling that the Symfony functions provide over the builtin php functions. So I'd tend to 'just call' whatever operation is what we want to do and trust that symfony/filesystem will throw the appropriate excetion e.g. on unreadability.

try {
$this->fileSystem->mkdir($loc, 0777);
} catch (IOException $e) {
Logger::error('Failed to create directory ' . $loc . ': ' . $e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this creates an error we can also just use exception mkdir will generate when we don't put it in a try/catch block? Same in instances below.

Copy link
Member Author

@tvdijen tvdijen Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file, we catch the error and return either null or false.. If we don't do that, the exception will break execution. I didn't want to change the original behaviour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow: Logger:error will break execution, also?

Copy link
Member Author

@tvdijen tvdijen Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I don't follow.. Logger::error only logs something.. The line underneath false is returned and the caller can handle that... If we don't catch the IOException, the caller never regains control.. We can let the caller catch it if you like that better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This explains the confusion. I was under the impression that an error halts execution. While it apparently doesn't.

try {
$this->fileSystem->mkdir($loc, 0777);
} catch (IOException $e) {
Logger::error('Failed to create directory ' . $loc . ': ' . $e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this creates an error we can also just use exception mkdir will generate when we don't put it in a try/catch block?

lib/SimpleSAML/Metadata/Sources/MDQ.php Outdated Show resolved Hide resolved
lib/SimpleSAML/Metadata/Sources/MDQ.php Outdated Show resolved Hide resolved
lib/SimpleSAML/Metadata/Sources/MDQ.php Outdated Show resolved Hide resolved
lib/SimpleSAML/Metadata/Sources/MDQ.php Outdated Show resolved Hide resolved
@tvdijen tvdijen merged commit 853206e into master Mar 16, 2022
@tvdijen tvdijen deleted the filesystem branch March 16, 2022 16:42
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.