Skip to content

fix: preserve errno across CORE::GLOBAL success paths#397

Draft
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-errno-preservation-success-paths
Draft

fix: preserve errno across CORE::GLOBAL success paths#397
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-errno-preservation-success-paths

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented May 13, 2026

What

Protect $! (errno) from being clobbered by internal helper calls on successful CORE::GLOBAL override paths.

Why

Issue #396: _abs_path_to_file() calls getcwd() (relative paths) and getpwent()/endpwent() (tilde paths), which can set $! as a side effect. Since no override saved/restored errno, callers saw dirty $! after successful operations — violating POSIX semantics where builtins don't modify errno on success.

How

  • local $! at the top of _abs_path_to_file() — protects all 16 call sites at once
  • local $! around Cwd::getcwd() in __cwd_abs_path() — surgical guard that doesn't mask the intentional $! = ELOOP set later in that function

Two lines of protection, zero behavioral change on failure paths.

Testing

New t/errno_preservation.t — verifies $! survives open, stat, unlink, and Cwd::abs_path on mocked files. Full test suite passes.

Closes #396

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 91 insertions(+), 1 deletion(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Internal helpers _abs_path_to_file() and __cwd_abs_path() call
getcwd() and getpwent() which can clobber $! as a side effect.
Add local $! guards so callers see their own errno, not internal
noise. Fixes cpan-authors#396.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

bug: CORE::GLOBAL overrides may clobber $! (errno) on success paths

1 participant