Skip to content

Conversation

@jordikroon
Copy link
Contributor

At some places the @ symbol was still used. This PR changes that behaviour with proper handling.

Since those checks are always (correct me if I am wrong) for internal paths. A simple file_exists & is_readable check is sufficient. If not we could override the error handler instead.

…handling

Replace error suppression operator (@) with explicit file existence and readability checks. Add new helper functions in include/file.inc (file_get_size, file_get_mtime, file_get_contents_if_exists) to safely handle file operations. This improves code reliability by catching actual errors rather than silencing them, and makes error handling explicit and testable throughout the codebase.
Add comprehensive documentation to the file header explaining the purpose
of helper functions and their safety checks. Remove trailing stray braces
that appear to be leftover code.
return false;
}

return file_get_contents($filename);
Copy link
Member

Choose a reason for hiding this comment

The 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 file_exists/is_readable, and the file_get_contents. This is quite possible, as the rsync process to put new data on the servers is not atomic. I would recommend keeping the @ here.

// 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)) {
Copy link
Member

Choose a reason for hiding this comment

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

This introduces a parse error, as the { is now gone matching the } on line 106.


// Open events CSV file, return on error
$fp = @fopen("backend/events.csv",'r');
$fp = fopen($path,'r');
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants