Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  [Filesystem] Check if failed unlink was caused by permission denied
  fix APCu installation for the nightly build job
  skip Vulcain-based tests if the binary cannot be executed
  • Loading branch information
fabpot committed Oct 21, 2020
2 parents 2ca5176 + 0921fda commit 870b4f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function remove($files)
if (!self::box('rmdir', $file) && file_exists($file)) {
throw new IOException(sprintf('Failed to remove directory "%s": ', $file).self::$lastError);
}
} elseif (!self::box('unlink', $file) && file_exists($file)) {
} elseif (!self::box('unlink', $file) && (false !== strpos(self::$lastError, 'Permission denied') || file_exists($file))) {
throw new IOException(sprintf('Failed to remove file "%s": ', $file).self::$lastError);
}
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Filesystem\Tests;

use Symfony\Component\Filesystem\Exception\IOException;

/**
* Test class for Filesystem.
*/
Expand Down Expand Up @@ -334,6 +336,28 @@ public function testRemoveIgnoresNonExistingFiles()
$this->assertFileDoesNotExist($basePath.'dir');
}

public function testRemoveThrowsExceptionOnPermissionDenied()
{
$this->markAsSkippedIfChmodIsMissing();

$basePath = $this->workspace.\DIRECTORY_SEPARATOR.'dir_permissions';
mkdir($basePath);
$file = $basePath.\DIRECTORY_SEPARATOR.'file';
touch($file);
chmod($basePath, 0400);

try {
$this->filesystem->remove($file);
$this->fail('Filesystem::remove() should throw an exception');
} catch (IOException $e) {
$this->assertStringContainsString('Failed to remove file "'.$file.'"', $e->getMessage());
$this->assertStringContainsString('Permission denied', $e->getMessage());
} finally {
// Make sure we can clean up this file
chmod($basePath, 0777);
}
}

public function testRemoveCleansInvalidLinks()
{
$this->markAsSkippedIfSymlinkIsMissing();
Expand Down

0 comments on commit 870b4f0

Please sign in to comment.