Skip to content

[Cache] remove is_writable check on filesystem cache #21025

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
Dec 28, 2016

Conversation

4rthem
Copy link
Contributor

@4rthem 4rthem commented Dec 22, 2016

Q A
Branch? 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21024
License MIT
Doc PR -
  • Use 755 mode for directories creation
  • Remove is_writable check in FilesystemAdapter to avoid exception on read-only filesystems

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

when file_put_content fails (see https://github.com/symfony/symfony/pull/21025/files#diff-fe14fffdd6799f339b2daf1045d09360R133)
we should report more info. In the else block, I think we should call error_get_last and use the message there to throw a CacheException (the AbstractAdapter will deal with it properly).

@@ -34,14 +34,11 @@ public function __construct($namespace = '', $defaultLifetime = 0, $directory =
$directory .= '/'.$namespace;
}
if (!file_exists($dir = $directory.'/.')) {
@mkdir($directory, 0777, true);
@mkdir($directory, 0755, true);
Copy link
Member

Choose a reason for hiding this comment

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

This should be reverted: the complete code bases uses 777 when calling mkdir.

@@ -150,7 +147,7 @@ private function getFile($id, $mkdir = false)
$dir = $this->directory.strtoupper($hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR);

if ($mkdir && !file_exists($dir)) {
@mkdir($dir, 0777, true);
@mkdir($dir, 0755, true);
Copy link
Member

Choose a reason for hiding this comment

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

revert

@4rthem
Copy link
Contributor Author

4rthem commented Dec 23, 2016

OK but currently, the doSave method iterates over all the values to save, even if one fails. It's only at the end that we have return $ok;.

Adding an exception in this method will conflict with the boolean return IMO.
We should either throw an exception at the first fail or analyze why file_put_contents or rename has failed. Maybe an is_writable call if $ok is false?

// Symfony\Component\Cache\Adapter\FilesystemAdapter::doSave
if (!$ok && !is_writable($this->directory)) {
    throw new CacheException(sprintf('Cache directory is not writable (%s)', $this->directory));
}

@nicolas-grekas
Copy link
Member

True concern, and AbstractAdapter already has the required logic to do what you say: it retries saving each key individually when batch save fails.

@nicolas-grekas nicolas-grekas added this to the 3.1 milestone Dec 26, 2016
@nicolas-grekas
Copy link
Member

Thank you @4rthem.

@nicolas-grekas nicolas-grekas merged commit 4dc4f69 into symfony:3.1 Dec 28, 2016
nicolas-grekas added a commit that referenced this pull request Dec 28, 2016
This PR was merged into the 3.1 branch.

Discussion
----------

[Cache] remove is_writable check on filesystem cache

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

* Use 755 mode for directories creation
* Remove `is_writable` check in FilesystemAdapter to avoid exception on read-only filesystems

Commits
-------

4dc4f69 remove is_writable check on filesystem cache
@4rthem 4rthem deleted the cache-ro-fs branch January 2, 2017 08:43
This was referenced Jan 12, 2017
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.

3 participants