bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mkdir-p


From: Reuben Thomas
Subject: mkdir-p
Date: Fri, 12 May 2023 15:26:47 +0300

Hi,

I just tried to use this function and gave up.

I appreciate that it is carefully written to cope with a wide variety of situations, but at present it looks more like the innards of something else (which indeed it appears to be, I see it in coreutils's mkdir!) rather than a reusable function (a quick search online didn't reveal any other users).

Some questions I had while trying:

1. Is it correct that the "wd" argument should be initialised with "savewd_init()"? The documentation says "WD is the working directory, as in savewd.c", but as far as I can tell, this is not exactly true, it's more of a context variable that is set by make_dir_parents.

2. What's a good "make_ancestor"? I just tried using "mkdir", but that seems to ignore a lot of the problems that make_dir_parents tries to solve. Without supplying a suitable "make_ancestor", it seems a bit of a stretch to claim that "make_dir_parents" can indeed "Ensure that the directory DIR exists". It's more like, it *can* do this given suitable helpers!

3. What's the relationship with mkancesdirs (nice pun, I just realised when saying it out loud!)? I see that mkancesdirs only makes the ancestors, but it seems to use a rather different algorithm, and it's not obvious to me why the ancestors need different treatment from the last component. For my use case, it's not obvious that I shouldn't "just" have called mkancesdirs, though that still leaves point 4b).

4. Finally, I was defeated here: "the child process may not have finished yet -- it is the caller's responsibility to handle this". I can't work out easily a) how I can detect this case nor b) what I should do when I detect it (how do I wait for it to complete?).

If these points could be documented, that would be a big help, but maybe also it would be fair to put some sort of "here be dragons" at the top of the documentation, as a user like me hoping for a straightforward C equivalent of "mkdir -p" is probably going to be disappointed.

In my case, the obvious solution seems to be exactly to spawn "mkdir -p", as mkdir(1posix) gives me everything I need.

--
https://rrt.sc3d.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]