Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/org/perlonjava/runtime/operators/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ public static RuntimeScalar mkdir(RuntimeList args) {

try {
Path path = RuntimeIO.resolvePath(fileName);
Files.createDirectories(path);
// Use createDirectory (not createDirectories) so it throws FileAlreadyExistsException
// when the directory exists. This matches Perl's behavior where mkdir() fails
// with EEXIST if the directory already exists.
Files.createDirectory(path);

// Set permissions only if the file system supports POSIX permissions
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
Expand All @@ -263,9 +266,9 @@ public static RuntimeScalar mkdir(RuntimeList args) {

return scalarTrue;
} catch (IOException e) {
// Set $! (errno) in case of failure
getGlobalVariable("main::!").set(e.getMessage());
return scalarFalse;
// Set $! (errno) properly using handleIOException which maps
// FileAlreadyExistsException to EEXIST (17), etc.
return handleIOException(e, fileName, 0);
}
}
}
Loading