Skip to content

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

Open
ndg63276 wants to merge 1 commit intomasterfrom
fix/LIMS-2141/suppress-errors-if-visit-dir-removed
Open

LIMS-2141: Suppress errors if visit directory has been replaced with a file#1051
ndg63276 wants to merge 1 commit intomasterfrom
fix/LIMS-2141/suppress-errors-if-visit-dir-removed

Conversation

@ndg63276
Copy link
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.

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.

1 participant