File tree Expand file tree Collapse file tree
src/main/java/org/perlonjava/runtime/operators Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -252,7 +252,10 @@ public static RuntimeScalar mkdir(RuntimeList args) {
252252
253253 try {
254254 Path path = RuntimeIO .resolvePath (fileName );
255- Files .createDirectories (path );
255+ // Use createDirectory (not createDirectories) so it throws FileAlreadyExistsException
256+ // when the directory exists. This matches Perl's behavior where mkdir() fails
257+ // with EEXIST if the directory already exists.
258+ Files .createDirectory (path );
256259
257260 // Set permissions only if the file system supports POSIX permissions
258261 if (FileSystems .getDefault ().supportedFileAttributeViews ().contains ("posix" )) {
@@ -263,9 +266,9 @@ public static RuntimeScalar mkdir(RuntimeList args) {
263266
264267 return scalarTrue ;
265268 } catch (IOException e ) {
266- // Set $! (errno) in case of failure
267- getGlobalVariable ( "main::!" ). set ( e . getMessage ());
268- return scalarFalse ;
269+ // Set $! (errno) properly using handleIOException which maps
270+ // FileAlreadyExistsException to EEXIST (17), etc.
271+ return handleIOException ( e , fileName , 0 ) ;
269272 }
270273 }
271274}
You can’t perform that action at this time.
0 commit comments