Subject: Re: bug#18179: stat doesn't dereference symlinked file name

From: Tomasz Pala <[email-masked]>
Date: Mon, 4 Aug 2014 20:33:34 +0200

On Sun, Aug 03, 2014 at 15:39:33 -0600, Bob Proulx wrote:

> misunderstanding of the available print formats.
> 
>> ~: stat -Lc "%n" b
>> b
> 
> You need %N to show what you are wanting to show.

No, I've mentioned %N later and it's just a shortcut for general state:
while dereferencing symlink, all the information come from dereferenced
file _except_ it's name.

~: ln -s a b
~: stat -L b

  File: `b'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: ah/10d  Inode: 26596       Links: 1
Access: (0600/-rw-------)  Uid: (  500/   gotar)   Gid: (  500/   gotar)
Access: 2014-08-04 20:12:40.008000499 +0200
Modify: 2014-08-04 20:12:40.008000499 +0200
Change: 2014-08-04 20:12:40.008000499 +0200

Inode 26596 contains file 'a', stat doesn't dereference file name.

>> ~: stat -Lc "%n" b
>> b
>> the last command should return 'a'.
> 
> Not quite.  The %n returns the file name as handed to stat on the
> command line.

But I've ordered to dereference that symlink (-L) first. What makes %n (and only
%n) to behave differently than %s or all the other sequences? In
different words: what makes %n to evaluate _before_ dereference (-L)
unike all the other sequences, which are evaluated _after_?

>  To get the quoted name dereference if a symbolic link
> then you need the %N format.
> 
>          %N     quoted file name with dereference if symbolic link

The problem with %N is: when dereferencing with -L switch, it doesn't
work as described:

~: stat -c "%N" b
`b' -> `a'

~:  stat -Lc "%N" b
`b'

The later one should print righthand part of the symlink. Anyway, I
don't want the quoted filename (especially useless `like this'), I need
simply the name. %N is all about quoting and printing reference.

> Perhaps you really want readlink?

No, as it operates on symlinks only, and I need to get real file.

Just take a look at this:

~: stat -c "%n" b
b			<- this is expected
~: stat -Lc "%n" b
b			<- this is not, -L is not effective

What's the point of returning the same data twice? None.

~: stat -c "%N" b
`b' -> `a'		<- like described in manual
~: stat -Lc "%N" b
`b'			<- definitely wrong, where's the dereference value?

Notice, I've used 4 different options and got 4 times 'b' and just one
'a' - this itself indicates a problem.

best regards,
-- 
Tomasz Pala <[email-masked]>