File tree 2 files changed +38
-1
lines changed
src/Symfony/Component/Filesystem
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -525,13 +525,21 @@ public function isAbsolutePath($file)
525
525
* @param null|int $mode The file mode (octal). If null, file permissions are not modified
526
526
* Deprecated since version 2.3.12, to be removed in 3.0.
527
527
*
528
- * @throws IOException If the file cannot be written to.
528
+ * @throws IOException if the file cannot be written to
529
529
*/
530
530
public function dumpFile ($ filename , $ content , $ mode = 0666 )
531
531
{
532
532
$ dir = dirname ($ filename );
533
533
534
534
if (!is_dir ($ dir )) {
535
+ if (is_file ($ dir )) {
536
+ throw new IOException (sprintf ('The parent path of "%s" is a file. ' , $ dir ));
537
+ }
538
+
539
+ if (is_link ($ dir )) {
540
+ throw new IOException (sprintf ('The parent path of "%s" is a symlink to a nonexistent directory. ' , $ dir ));
541
+ }
542
+
535
543
$ this ->mkdir ($ dir );
536
544
}
537
545
Original file line number Diff line number Diff line change @@ -1102,6 +1102,35 @@ public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
1102
1102
$ this ->assertFilePermissions (745 , $ filename );
1103
1103
}
1104
1104
1105
+ /**
1106
+ * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1107
+ * @expectedExceptionMessageRegExp /^The parent path of ".*" is a file\.$/
1108
+ */
1109
+ public function testDumpFailsIfParentDirectoryIsAnExistingFile ()
1110
+ {
1111
+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'foo ' ;
1112
+ $ target = $ file .DIRECTORY_SEPARATOR .'bar ' ;
1113
+ touch ($ file );
1114
+
1115
+ $ this ->filesystem ->dumpFile ($ target , 'baz ' );
1116
+ }
1117
+
1118
+ /**
1119
+ * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1120
+ * @expectedExceptionMessageRegExp /^The parent path of ".*" is a symlink to a nonexistent directory\.$/
1121
+ */
1122
+ public function testDumpFailsIfTargetIsSymlinkAndSymlinkTargetDoesNotExist ()
1123
+ {
1124
+ $ dir = $ this ->workspace .DIRECTORY_SEPARATOR .'foo ' ;
1125
+ mkdir ($ dir );
1126
+ $ link = $ this ->workspace .DIRECTORY_SEPARATOR .'bar ' ;
1127
+ symlink ($ dir , $ link );
1128
+ rmdir ($ dir );
1129
+ $ target = $ link .DIRECTORY_SEPARATOR .'baz ' ;
1130
+
1131
+ $ this ->filesystem ->dumpFile ($ target , 'baz ' );
1132
+ }
1133
+
1105
1134
public function testCopyShouldKeepExecutionPermission ()
1106
1135
{
1107
1136
$ this ->markAsSkippedIfChmodIsMissing ();
You can’t perform that action at this time.
0 commit comments