8000 Filesystem remove() function not throwing exception · Issue #38650 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

Filesystem remove() function not throwing exception #38650

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

Closed
UBERPHP opened this issue Oct 20, 2020 · 1 comment
Closed

Filesystem remove() function not throwing exception #38650

UBERPHP opened this issue Oct 20, 2020 · 1 comment

Comments

@UBERPHP
Copy link
UBERPHP commented Oct 20, 2020

Symfony version(s) affected: 4.4.15

Description
remove method should throw an exception when fails to remove the file due to permissions problem.

How to reproduce
composer require symfony/filesystem

<?php
include('vendor'.DIRECTORY_SEPARATOR.'autoload.php');

use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;

$filesystem = new Filesystem();
try {
    $filesystem->mkdir('dir');
    $filesystem->touch('dir'.DIRECTORY_SEPARATOR.'file');
    $filesystem->chmod('dir', 0400);
    $filesystem->remove('dir'.DIRECTORY_SEPARATOR.'file');
} catch (IOExceptionInterface $exception) {
    echo $exception->getMessage().PHP_EOL;
}
$filesystem->chmod('dir', 0700);
if ($filesystem->exists('dir'.DIRECTORY_SEPARATOR.'file')) {
    echo 'File exist!'.PHP_EOL;
}

Possible Solution
https://github.com/UBERPHP/symfony/commit/81cbacb03043224e12149b88cdd4dd759f6a7e4b
However, I'm not really sure about behaviour here, especially && file_exists($file) in remove method.

Additional context
Correct me if I'm wrong about this behaviour. I also have some failures in e.g. testRemoveSymlink method by using centos 8 vagrant box

@Nyholm
Copy link
Member
Nyholm commented Oct 20, 2020

I can confirm that this is an issue.

It happens because the directory is unreadable. We are trying to remove a file in it and we fail but since file_exists() return false (since we cannot read the directory) it just plays along.

Have a look at #38652, will that patch solve your issues?

@fabpot fabpot closed this as completed Oct 21, 2020
fabpot added a commit that referenced this issue Oct 21, 2020
…on denied (Nyholm)

This PR was submitted for the 4.4 branch but it was squashed and merged into the 3.4 branch instead.

Discussion
----------

[Filesystem] Check if failed unlink was caused by permission denied

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38650
| License       | MIT
| Doc PR        |

Check why we failed to unlink the file. If the file was missing, then no exception should be thrown. However, if we failed to unlink it because of permissions, we should throw an exception.

Commits
-------

1cde6ca [Filesystem] Check if failed unlink was caused by permission denied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0