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

[ClassLoader] Throw an exception if the cache is not writeable #21211

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 1 commit into from
Jan 9, 2017

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Jan 8, 2017

Q A
Branch? 2.7
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

In dev env:

from:

Notice: tempnam(): file created in the system's temporary directory

to:

Failed to write cache file "/var/www/html/var/cache/dev/classes.php".

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 9, 2017

Does that really work? I mean: "file created in the system's temporary directory" happens when tempnam returns false? Isn't the file created in the system's temporary directory returned instead?

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jan 9, 2017
@lyrixx
Copy link
Member Author

lyrixx commented Jan 9, 2017

Before the patch, in dev, I get the notice, and this notice is converted to an exception.
After the patch I get an exception with a proper error message.

So in both case I have to fix the permission.

Then, If I fix permissions, It works in both case.

@lyrixx
Copy link
Member Author

lyrixx commented Jan 9, 2017

Ok got it. Your are right. If I add the @ the result of the function is /tmp/classes.phpIo9eA9.
So the if false=== is useless.

What you I do? just add the @?

@stof
Copy link
Member

stof commented Jan 9, 2017

@lyrixx the goal of @ is to avoid the warning being triggered, so that our own exception is thrown rather than the ErrorException coming from the notice (allowing to have our more actionable error message)

@stof
Copy link
Member

stof commented Jan 9, 2017

and if (false === is not useless. It is the part detecting the error

@lyrixx lyrixx force-pushed the classloader-tmpname branch from af27fbe to c5b65de Compare January 9, 2017 13:41
@lyrixx
Copy link
Member Author

lyrixx commented Jan 9, 2017

I updated the code.

@lyrixx
Copy link
Member Author

lyrixx commented Jan 9, 2017

Oups, I forgot PHP 5.4.

I have different implementations:

        set_error_handler(function () use ($file) {
            throw new \RuntimeException(sprintf('Failed to create temporary file in "%s".', dirname($file)));
        });
        try {
            $tmpFile = tempnam(, basename($file));
        } catch(\RuntimeException $e) {
            restore_error_handler();

            throw $e;
        }
        restore_error_handler();

or something like

        $tmpFile = @tempnam(dirname($file), basename($file));
        if (dirname($file) !== dirname($tmpFile)) {
            throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
        }

or

        $dir = dirname($file);
        if (is_writable($dir)) {
            throw new \RuntimeException(sprintf('Failed to write cache in directory "%s".', $dir));
        }

Which one is the best?

@lyrixx lyrixx force-pushed the classloader-tmpname branch from c5b65de to 9f7ad90 Compare January 9, 2017 14:12
@lyrixx
Copy link
Member Author

lyrixx commented Jan 9, 2017

Did the 3/

$tmpFile = tempnam(dirname($file), basename($file));
$dir = dirname($file);
if (!is_writable($dir)) {
throw new \RuntimeException(sprintf('Failed to write cache in directory "%s".', $file));
Copy link
Member

Choose a reason for hiding this comment

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

$dir

@lyrixx lyrixx force-pushed the classloader-tmpname branch from 9f7ad90 to 69cc04e Compare January 9, 2017 14:20
@lyrixx lyrixx force-pushed the classloader-tmpname branch from 69cc04e to 3c887da Compare January 9, 2017 14:44
@nicolas-grekas
Copy link
Member

👍

@fabpot
Copy link
Member

fabpot commented Jan 9, 2017

Thank you @lyrixx.

@lyrixx lyrixx changed the title Classloader tmpname [ClassLoader] Throw an exception if the cache is not writeable Jan 9, 2017
@fabpot fabpot merged commit 3c887da into symfony:2.7 Jan 9, 2017
fabpot added a commit that referenced this pull request Jan 9, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Classloader tmpname

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

In dev env:

from:

> Notice: tempnam(): file created in the system's temporary directory

to:

> Failed to write cache file "/var/www/html/var/cache/dev/classes.php".

Commits
-------

3c887da [ClassLoader] Throw an exception if the cache is not writeable
@lyrixx lyrixx deleted the classloader-tmpname branch January 9, 2017 14:57
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.

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