Skip to content

Filesystem remove() function not throwing exception #38650

Closed
@UBERPHP

Description

@UBERPHP

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions