Login
You're viewing the functional.cafe public feed.

Replies

  • Nov 12, 2026, 12:46 AM

    @wolf480pl If I'm reading the code of the uutils fix correctly¹, uutils was basically applying 'mkdir -p' processing to all errors, even if you did plain mkdir. In 'mkdir -p', you skip reporting errors on directories that exist afterward.

    (The commit message talks about EEXIST but as far as I can see they don't check that that's the error they got from the mkdir(), they apply the processing to all errors.)

    ¹ github.com/uutils/coreutils/co

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 12:54 AM

    @cks
    oh, I read your previous post backwards - I thought they were trying to detect after mkdir that the dir exists, and if it does exist, fail to replicate GNU's behaviour, and that this was a TOCTOU.

    But yeah if it used to succeed when the dir exists - that's a much easier mistake to make.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 1:11 AM

    @wolf480pl @cks They still check path.is_dir() (`statx` on Linux) on recursive errors, instead of checking for EEXIST. So the current code is still buggy. The path might change after mkdir(2) fails and before statx(2) is called.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 2:04 AM

    @collinfunk
    hmm but how do you tell apart:
    1. mkdir -p a/b tries to create a, fails from EACCESS
    2. someone else creates a
    3. mkdir checks if a exists, it does, so it goes on to create a/b

    from

    1. someone else creates a
    2. mkdir tries to create a, fails from EEXISTS
    3. mkdir goes on to create a/b

    ?

    Oh, there's supposed to be a chmod, which would have to be tried (and potentially fail) after discovering the directory exists, not before...

    @cks

    💬 2🔄 0⭐ 0
  • Nov 12, 2026, 2:19 AM

    @collinfunk
    also, it seems to me what they're doing is fundamentally wrong: they're trying to implement POSIX semantics on top of a high-level filesystem API from Rust's stdlib, that AFAIK doesn't even make any promises wrt atomicity, so it might be mapping to some sequence of syscalls now and a semantically different sequence of syscalls in the future...
    @cks

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 2:29 AM

    @wolf480pl @cks I have similar concerns about that, but figured I was probably just being paranoid. I wonder how bad it would be for portability to just use rustix syscall wrappers.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 2:40 AM

    @collinfunk @wolf480pl In my view the only time 'mkdir -p' should fail is if at the end of its work, there is no 'a/b'. People using 'mkdir -p' care about whether or not the result exists, not how it got there. (Of course it could be renamed immediately afterward before your script does anything else, but so can anything.)

    I think POSIX can be read to be more narrow than this, but if so, deviation is likely to be extremely common in mkdirs in practice.

    💬 0🔄 0⭐ 0
  • Nov 12, 2026, 2:36 AM

    @wolf480pl @cks For 'mkdir -p', you generally don't check that the directory exists. You just create the directory, and try to enter it with chdir(2) or by opening a file descriptor (if you use a file descriptor, you'd use mkdirat(2) later to create the child relative to the parent that).

    💬 0🔄 0⭐ 0