Skip to content

LIMS-2141: Suppress errors if visit directory has been replaced with a file#1051

Merged
ndg63276 merged 2 commits intopre-release/2026-R2.2from
fix/LIMS-2141/suppress-errors-if-visit-dir-removed
Apr 7, 2026
Merged

LIMS-2141: Suppress errors if visit directory has been replaced with a file#1051
ndg63276 merged 2 commits intopre-release/2026-R2.2from
fix/LIMS-2141/suppress-errors-if-visit-dir-removed

Conversation

@ndg63276
Copy link
Copy Markdown
Collaborator

JIRA ticket: LIMS-2141

Summary:

If the whole visit folder (or any folder in the path of an expected file) has been replaced with a file, then the combination of file_exists and open_basedir cause an error. See eg https://ispyb.diamond.ac.uk/dc/visit/cm40636-1

Changes:

  • Use the @ operator to suppress errors on file_exist calls on the data collection page

To test:

  • Deploy to a full server with open_basedir set, then go to /dc/visit/cm40636-1. Check there are no errors.

Alternatives:
The other option would be to manually check all paths for directories replaced by files, eg

function safe_file_exists($fullPath) {
    $parts = explode('/', trim($fullPath, '/'));
    $current = '';
    foreach ($parts as $part) {
        $current .= '/' . $part;
        if ($current !== $fullPath) {
            if (!is_dir($current)) {
                return false;
            }
        }
    }
    return file_exists($fullPath);
}

But that seemed to be slower by a factor of 5-10x, and could result in a lot of extra calls to the metadata server.

@ndg63276 ndg63276 changed the base branch from master to pre-release/2026-R2.2 April 7, 2026 10:14
@ndg63276 ndg63276 merged commit f87fabf into pre-release/2026-R2.2 Apr 7, 2026
@ndg63276 ndg63276 deleted the fix/LIMS-2141/suppress-errors-if-visit-dir-removed branch April 7, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants