File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ public function remove($files)
180
180
if (!self ::box ('rmdir ' , $ file ) && file_exists ($ file )) {
181
181
throw new IOException (sprintf ('Failed to remove directory "%s": ' , $ file ).self ::$ lastError );
182
182
}
183
- } elseif (!self ::box ('unlink ' , $ file ) && file_exists ($ file )) {
183
+ } elseif (!self ::box ('unlink ' , $ file ) && ( false !== strpos ( self :: $ lastError , ' Permission denied ' ) || file_exists ($ file) )) {
184
184
throw new IOException (sprintf ('Failed to remove file "%s": ' , $ file ).self ::$ lastError );
185
185
}
186
186
}
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Filesystem \Tests ;
13
13
14
+ use Symfony \Component \Filesystem \Exception \IOException ;
15
+
14
16
/**
15
17
* Test class for Filesystem.
16
18
*/
@@ -334,6 +336,28 @@ public function testRemoveIgnoresNonExistingFiles()
334
336
$ this ->assertFileDoesNotExist ($ basePath .'dir ' );
335
337
}
336
338
339
+ public function testRemoveThrowsExceptionOnPermissionDenied ()
340
+ {
341
+ $ this ->markAsSkippedIfChmodIsMissing ();
342
+
343
+ $ basePath = $ this ->workspace .\DIRECTORY_SEPARATOR .'dir_permissions ' ;
344
+ mkdir ($ basePath );
345
+ $ file = $ basePath .\DIRECTORY_SEPARATOR .'file ' ;
346
+ touch ($ file );
347
+ chmod ($ basePath , 0400 );
348
+
349
+ try {
350
+ $ this ->filesystem ->remove ($ file );
351
+ $ this ->fail ('Filesystem::remove() should throw an exception ' );
352
+ } catch (IOException $ e ) {
353
+ $ this ->assertStringContainsString ('Failed to remove file " ' .$ file .'" ' , $ e ->getMessage ());
354
+ $ this ->assertStringContainsString ('Permission denied ' , $ e ->getMessage ());
355
+ } finally {
356
+ // Make sure we can clean up this file
357
+ chmod ($ basePath , 0777 );
358
+ }
359
+ }
360
+
337
361
public function testRemoveCleansInvalidLinks ()
338
362
{
339
363
$ this ->markAsSkippedIfSymlinkIsMissing ();
You can’t perform that action at this time.
0 commit comments