-
Notifications
You must be signed in to change notification settings - Fork 612
Remove error suppression operator (@) and add proper error handling #1741
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file contains helper functions to deal with files in a safe manner. | ||
| * These functions check for file existence and readability before performing | ||
| * any operations on them. | ||
| */ | ||
|
|
||
| function file_get_size(string $filename): int|false | ||
| { | ||
| if (!file_exists($filename) || !is_readable($filename)) { | ||
| return false; | ||
| } | ||
|
|
||
| return filesize($filename); | ||
| } | ||
|
|
||
| function file_get_mtime(string $filename): int|false | ||
| { | ||
| if (!file_exists($filename) || !is_readable($filename)) { | ||
| return false; | ||
| } | ||
|
|
||
| return filemtime($filename); | ||
| } | ||
|
|
||
| function file_get_contents_if_exists(string $filename): string|false | ||
| { | ||
| if (!file_exists($filename) || !is_readable($filename)) { | ||
| return false; | ||
| } | ||
|
|
||
| return file_get_contents($filename); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a race condition here, if the file gets removed between the |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,11 +101,11 @@ function manual_notes_load(string $id): array | |
|
|
||
| // Open the note file for reading and get the data (12KB) | ||
| // ..if it exists | ||
| if (!file_exists($notes_file)) { | ||
| // if (!file_exists($notes_file) || !is_readable($notes_file)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This introduces a parse error, as the |
||
| return []; | ||
| } | ||
| $notes = []; | ||
| if ($fp = @fopen($notes_file, "r")) { | ||
| if ($fp = fopen($notes_file, "r")) { | ||
| while (!feof($fp)) { | ||
| $line = chop(fgets($fp, 12288)); | ||
| if ($line == "") { continue; } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are race conditions here too for similar reasons.