GNU bug report logs - #18179
stat doesn't dereference symlinked file name

Previous Next

Package: coreutils;

Reported by: Tomasz Pala <gotar <at> polanet.pl>

Date: Sun, 3 Aug 2014 09:41:01 UTC

Severity: normal

Tags: notabug

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18179 in the body.
You can then email your comments to 18179 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#18179; Package coreutils. (Sun, 03 Aug 2014 09:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tomasz Pala <gotar <at> polanet.pl>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 03 Aug 2014 09:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tomasz Pala <gotar <at> polanet.pl>
To: bug-coreutils <at> gnu.org
Subject: stat doesn't dereference symlinked file name
Date: Sun, 3 Aug 2014 11:20:01 +0200
~: touch a
~: ln -s a b
~: stat -c "%n" a
a
~: stat -c "%n" b
b
~: stat -Lc "%n" b
b

the last command should return 'a'. To be more verbose:

~: stat b
  File: `b' -> `a'
  Size: 1               Blocks: 0          IO Block: 4096   symbolic link
Device: 10h/16d Inode: 60112068    Links: 1

~: stat -L b
  File: `b'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 10h/16d Inode: 60112022    Links: 1
[...]

one cannot get the righthand part of dereference only (the same applies
to %N).

-- 
Tomasz Pala <gotar <at> pld-linux.org>




Information forwarded to bug-coreutils <at> gnu.org:
bug#18179; Package coreutils. (Sun, 03 Aug 2014 21:40:01 GMT) Full text and rfc822 format available.

Message #8 received at 18179 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Tomasz Pala <gotar <at> polanet.pl>
Cc: 18179 <at> debbugs.gnu.org
Subject: Re: bug#18179: stat doesn't dereference symlinked file name
Date: Sun, 3 Aug 2014 15:39:33 -0600
tag 18179 + notabug
close 18179
thanks

Thanks for the bug report.  However this seems to be a
misunderstanding of the available print formats.

Tomasz Pala wrote:
> ~: touch a
> ~: ln -s a b
> ~: stat -c "%n" a
> a
> ~: stat -c "%n" b
> b
> ~: stat -Lc "%n" b
> b

You need %N to show what you are wanting to show.

  $ stat -c %N b
  ‘b’ -> ‘a’
  $ stat -Lc %N b
  ‘b’

> ~: 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.  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

> To be more verbose:
> 
> ~: stat b
>   File: `b' -> `a'
>   Size: 1               Blocks: 0          IO Block: 4096   symbolic link
> Device: 10h/16d Inode: 60112068    Links: 1
> 
> ~: stat -L b
>   File: `b'
>   Size: 0               Blocks: 0          IO Block: 4096   regular empty file
> Device: 10h/16d Inode: 60112022    Links: 1
> [...]
> 
> one cannot get the righthand part of dereference only (the same applies
> to %N).

I read the above part several times but your meaning was not clear.
In any case I see no bug in stat.

Perhaps you really want readlink?

  $ readlink b
  a

  $ readlink -f b
  /tmp/a

For what I believe you are doing the typical idiom is to use
"readlink" to print the value of the symbolic link.

Bob




Added tag(s) notabug. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Sun, 03 Aug 2014 21:40:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 18179 <at> debbugs.gnu.org and Tomasz Pala <gotar <at> polanet.pl> Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Sun, 03 Aug 2014 21:40:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#18179; Package coreutils. (Mon, 04 Aug 2014 18:34:02 GMT) Full text and rfc822 format available.

Message #15 received at 18179 <at> debbugs.gnu.org (full text, mbox):

From: Tomasz Pala <gotar <at> polanet.pl>
To: Bob Proulx <bob <at> proulx.com>
Cc: 18179 <at> debbugs.gnu.org
Subject: Re: bug#18179: stat doesn't dereference symlinked file name
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 <gotar <at> pld-linux.org>




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 02 Sep 2014 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 289 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.