Skip to content

Fix mkdir to set $! errno correctly (EEXIST)#323

Merged
fglock merged 1 commit into
masterfrom
fix/mkdir-eexist
Mar 16, 2026
Merged

Fix mkdir to set $! errno correctly (EEXIST)#323
fglock merged 1 commit into
masterfrom
fix/mkdir-eexist

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 16, 2026

Summary

  • Use Files.createDirectory() instead of Files.createDirectories() so it throws FileAlreadyExistsException when directory already exists
  • Use handleIOException() which properly maps exceptions to errno values (e.g., FileAlreadyExistsException -> EEXIST=17)

This fixes jcpan failing on re-run when build directories exist. The CPAN::Distribution module relies on mkdir returning false with $! set to EEXIST to increment the suffix number for build directories.

Before: $!+0 returned 0 regardless of error type
After: $!+0 returns 17 (EEXIST) when mkdir fails on existing directory

Test plan

  • make passes
  • Manual test: ./jperl -e 'use Errno; mkdir("/tmp", 0777); print ($!+0), " == ", Errno::EEXIST()' now prints 17 == 17
  • Manual test: ./jcpan -t Mo works on first run
  • Manual test: ./jcpan -t Mo works on second run (was failing before this fix)

Generated with Devin

- Use Files.createDirectory() instead of Files.createDirectories() so it
  throws FileAlreadyExistsException when directory already exists
- Use handleIOException() which properly maps exceptions to errno values
  (e.g., FileAlreadyExistsException -> EEXIST=17)

This fixes jcpan failing on re-run when build directories exist. The
CPAN::Distribution module relies on mkdir returning false with $! set to
EEXIST to increment the suffix number for build directories.

Before: $!+0 returned 0 regardless of error type
After:  $!+0 returns 17 (EEXIST) when mkdir fails on existing directory

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 985e4cc into master Mar 16, 2026
2 checks passed
@fglock fglock deleted the fix/mkdir-eexist branch March 16, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant