-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: Rename functions #1233
fs: Rename functions #1233
Conversation
"dirname" is the usual way to refer to the directory part of a path name. See for example dirname(1), or the dirname builtin in several languages. Also, in the context of mkdir(), "parents" is used to refer to mkdir -p, which is too similar to "parent", so it can lead to confusion. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Bogus ruby test. |
To be brutally honest I don't see the point of either of these... In terms of the name, dirname means strip off the last directory component, not what nxt_fs_mkdir_parent() does (it creates the last directory component). As for the other, I know the -p in mkdir is --parents, but I think all is also perfectly descriptive... (anyway _parents is too verbose, personally I'd have gone for _p). |
Damn, why does this ruby test keep failing for you?! I only see it occasionally fail... @andrey-zelenkov @arbourd any ideas? |
I wouldn't mind for the code as is, but I'm going to change nxt_fs_mkdir_parent() to be nxt_fs_mkdir_p_dirname() in a future PR, since I want to create all the parents of the dirname (and the dirname itself). This is a preparation to have a consistent naming scheme.
It strips off the last path-name component, not directory component. Usually this is done to strip a regular file name, and refer to the (parent) directory that contains it (thus the name). $ dirname dir1/dir2/file
dir1/dir2 nxt_fs_mkdir_parent() creates precisely the dirname of the path that you pass to it. alx@debian:~/src/nginx/unit/master$ grepc nxt_fs_mkdir_parent .
./src/nxt_fs.c:nxt_int_t
nxt_fs_mkdir_parent(const u_char *path, mode_t mode)
{
...
dir = nxt_strdup(path);
...
ptr = strrchr(dir, '/');
if (nxt_fast_path(ptr != NULL)) {
*ptr = '\0';
ret = nxt_fs_mkdir((const u_char *) dir, mode);
}
...
} nxt_fs_mkdir_parent("dir1/dir2/file", mode); is literally equivalent (ignoring the mode) to mkdir $(dirname "dir1/dir2/file") which evaluates to mkdir dir1/dir2
Hmmm, I like _p. |
"all" is too generic of an attribute to be meaningful. In the context of mkdir(), "parents" is used for this meaning, as in mkdir -p, so it should be more straightforward to readers. Signed-off-by: Alejandro Colomar <alx@kernel.org>
49b59aa
to
29e3efb
Compare
v2 changes:
|
So my plan is to end up with a function _mkdir_p() that does precisely |
@ac000 I don't. My cursory understanding is that it is an isolation test that flakes.
It's consistent with Ruby 3.2 though, and I have not seen it with 3.3. |
Correct.
It always seems to be this one, I see it fail occasionally and it always succeeds if you manually re-run it. Not sure why it seems to be failing consistently for Alex, but if you manually re-run it it should succeed (it did before). |
In my mind they are doing different things. _parent() may create the directory, but only if all the proceeding directories exist. But I can see where you're coming from in that _parent() effectively does a dirname(3)... |
But that should perhaps not involve nxt_fs_mkdir_parent() at all, as it will end up with different semantics. Creating all the directories vs only the last one. It may be that _parent() can be dropped, undecided... |
So to clarify. Personally I'm OK with _p() and I think _p_dirname() (although a bit unwieldy) should just be a new function. We can then decide what to do with _parent() afterwards... (This is all assuming someone doesn't come up with a reason not do this in the first place, like last time) |
Yep.
My intention was to first rename _parent => _dirname, and later add a commit that drops _dirname and adds _p_dirname. Since the code for _p_dirname will be almost the same as for _dirname (because the main job is getting the dirname), it will show as a modification of the function in the commit in git. |
If you want to see my full intentions, I can write a PR with all the commits together. |
My point is we may either want to keep _parent() with its current semantics or drop it... which is why I suggest not to touch it... |
If we leave _parent() as is and do remove it, then if at a later date we decide we do want it back, it's a simple revert... |
|
Closing in favour of #1235 |
No description provided.