Skip to content

[BUG] mkdir -p f exits 0 with no error when f is an existing regular file #372

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main @ dbb6189)
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

dbb6189 (--version prints 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.18 (aarch64)

Installation Method

built from source

Steps to Reproduce

strands-shell -c 'echo x > f; mkdir -p f && echo made; echo "rc=$?"'

Expected Behavior

Same as coreutils 9.1: mkdir: cannot create directory 'f': File exists, nothing from echo made, and rc=1.

Actual Behavior

made
rc=0

No error is printed and f is still a regular file, so a script that guards on mkdir -p out && ... carries on without the directory. The same happens when the operand is a symlink to a regular file (ln -s f l; mkdir -p l exits 0; coreutils exits 1), and on a direct bind.

Without -p it is correct: mkdir f prints strands-shell: mkdir: f: already exists and exits 1.

Additional Context

Found while reviewing #354, which moves this code into a helper without changing it. The result is the same on that PR's base dbb6189 and head 4946e4b.

Possible Solution

The -p walk skips the last component when it exists, without checking that it is a directory: io::stat(os, &path).await.exists at src/commands/mkdir.rs:53 on main. Skipping only when stat.is_dir, and otherwise letting create_dir report the existing file, should do it. I have not written or tested a fix.

Related Issues

#354

Activity

  1. added
    bug
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions