On 01/11/2025 16:01, Patrick GARCIA via Gnulib discussion list wrote:
ok,
<< What do you mean by "logical" file name resolution? >>
"logical" is the boolean variable define in the file we talk about :
"lib/canonicalize.c"
line 187 : bool logical = ...;
<< "NOLINKS" flag - what do you mean by that? >>
"CAN_NOLINKS" is a flag that modifs "logical" boolean variable in the
file we talk about : "lib/canonicalize.c"
line 187 : bool logical = (can_mode & CAN_NOLINKS) != 0;
<< "current-directory is a symbolic-link" - what do you mean by that? >>
suppose "/tmp/logical_dir" is a symbolic-link to directory
"/tmp/phisical_dir".
if you change directory to "/tmp/logical_dir", then "current-directory
is a symbolic-link"
example script :
{
mkdir -p /tmp/phisical_dir
ln -sf phisical_dir /tmp/logical_dir
cd -L /tmp/logical_dir
pwd
}
I have attache a new version of my commit-proposal including a section
"How to reproduce".
about unit-test :
- here is the use-case I wanted to add in "tests/test-canonicalize.c"
around line 430 :
/* Check that "." and "$PWD" result the same way */
{
ASSERT (0 == chdir(BASE "/s"));
char *wd = get_current_dir_name();
char *result1 = canonicalize_filename_mode ( ".", 0);
char *result2 = canonicalize_filename_mode ( ".", CAN_NOLINKS);
char *result3 = canonicalize_filename_mode ( wd, 0);
char *result4 = canonicalize_filename_mode ( wd, CAN_NOLINKS);
ASSERT (0 == chdir("../.."));
ASSERT (result1 != NULL);
ASSERT (result2 != NULL);
ASSERT (result3 != NULL);
ASSERT (result4 != NULL);
ASSERT (str_endswith (wd, "/" BASE "/s"));
ASSERT (str_startswith (result1, wd));
ASSERT (str_startswith (result2, wd));
ASSERT (str_startswith (result3, wd));
ASSERT (str_startswith (result4, wd));
ASSERT (str_endswith (result1, "/" BASE "/d"));
ASSERT (0 == strcmp (result1, result2));
ASSERT (0 == strcmp (result1, result3));
ASSERT (str_endswith (result4, "/" BASE "/s"));
free (wd);
free (result1);
free (result2);
free (result3);
free (result4);
}
- but this test does not work due to chdir(BASE "/s") that behave as
chdir(BASE "/d") in the test-context.
- feel free to have a look but I did not found any C langage workaround.
- I did a working unit-test on coreutil realpath executable. I attach the
corresponding commit to this post.
Patrick
On 01/11/2025 12:58, Bruno Haible wrote:
Hi,
Patrick GARCIA wrote:
I did not manage to use "vc-dwim" properly.
vc-dwim is used to create a ChangeLog entry. When you provide a patch
with a reasonable git commit message, we can easily turn that into
a ChangeLog entry. Therefore, no real need to use 'vc-dwim'.
When you propose a patch, you should provide an explanation regarding
the situation where it provides an improvement.
- Which OS? I guess GNU/Linux, but you should better state that
explicitly.
- What are the "How to reproduce" instructions?
Your git commit message gives only partial answers:
- What do you mean by "logical" file name resolution?
- "NOLINKS" flag - what do you mean by that?
- "current-directory is a sybolic-link" - what do you mean by that?
When a process enters a directory via chdir(), is follows symbolic
links. Therefore the current directory is _never_ a symbolic link,
it is _always_ a real directory.
PS : I will, then, propose a shell unit-test to the coreutils team.
Ideally, since Gnulib is a C functions library, the unit test should
be a small self-contained C program. That test program lives in
gnulib/tests/.
I've only thought about this for a few minutes, but
we may make a change here so that at least realpath -s
will use $PWD if set, so that symlinks in $PWD are propagated.
Note you can already get this functionality using realpath(1) like:
realpath -s $(pwd -L)/../whatever
But I suppose that doesn't lend itself to multiple args to realpath(1).
Note cd really is the only thing that honors $PWD like this,
so that `cd ..` will operate relative to the source of the link,
while `cd -P ..` or `ls ..` etc. will operate relative to the destination.
So we'd have to be careful that commands using this interface
would not get unexpected results. Mitigating that is the fact
that this canonicalize module originated in coreutils,
and CAN_NOLINKS is only used from realpath().
Note glibc's get_current_dir_name() used in this patch is not portable enough.
Also one needs to check that it doesn't return NULL.
In coreutils pwd.c we have logical_cwd() which would do the job more portably.
That suggests that we could handle this in realpath(1) entirely.
In any case we can use logical_cwd() instead for this.
I'll handle further changes if needed.
thanks,
Padraig