If mkdir fails, check again to see if dir has been created
since our initial check, and return true if so.
Also, in initial check, only return true if $dir is really
a directory, not a file.
Bug: 49391
Change-Id: I2b331669fae70948ce79ba1477c05968a3095c3d
wfDebug( "$caller: called wfMkdirParents($dir)\n" );
}
- if ( strval( $dir ) === '' || file_exists( $dir ) ) {
+ if ( strval( $dir ) === '' || ( file_exists( $dir ) && is_dir( $dir ) ) ) {
return true;
}
wfRestoreWarnings();
if ( !$ok ) {
+ //directory may have been created on another request since we last checked
+ if ( is_dir( $dir ) ) {
+ return true;
+ }
+
// PHP doesn't report the path in its warning message, so add our own to aid in diagnosis.
wfLogWarning( sprintf( "failed to mkdir \"%s\" mode 0%o", $dir, $mode ) );
}
return $a;
}
+ function testWfMkdirParents() {
+ // Should not return true if file exists instead of directory
+ $fname = $this->getNewTempFile();
+ wfSuppressWarnings();
+ $ok = wfMkdirParents( $fname );
+ wfRestoreWarnings();
+ $this->assertFalse( $ok );
+ }
+
/**
* @dataProvider provideWfShellMaintenanceCmdList
*/