GNU bug report logs - #11271
dirname /home/dir/

Previous Next

Package: coreutils;

Reported by: Kevin Huanpeng Du <q24688 <at> gmail.com>

Date: Wed, 18 Apr 2012 16:19:02 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.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 11271 in the body.
You can then email your comments to 11271 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#11271; Package coreutils. (Wed, 18 Apr 2012 16:19:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kevin Huanpeng Du <q24688 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 18 Apr 2012 16:19:03 GMT) Full text and rfc822 format available.

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

From: Kevin Huanpeng Du <q24688 <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: dirname /home/dir/
Date: Wed, 18 Apr 2012 19:01:29 +0800
[Message part 1 (text/plain, inline)]
Hi,
i find dirname dirname strip a dir name when a string with out a filename.

₤ dirname /dir/file
₤ /dir
₤ dirname /dir/subdir/
₤ /dir # is this right? subdir is a not a file.

Thanks,
Du Huangpeng
[Message part 2 (text/html, inline)]

Added tag(s) notabug. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Wed, 18 Apr 2012 17:36:02 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Wed, 18 Apr 2012 17:36:02 GMT) Full text and rfc822 format available.

Notification sent to Kevin Huanpeng Du <q24688 <at> gmail.com>:
bug acknowledged by developer. (Wed, 18 Apr 2012 17:36:02 GMT) Full text and rfc822 format available.

Message #12 received at 11271-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Kevin Huanpeng Du <q24688 <at> gmail.com>
Cc: 11271-done <at> debbugs.gnu.org
Subject: Re: bug#11271: dirname /home/dir/
Date: Wed, 18 Apr 2012 11:35:23 -0600
[Message part 1 (text/plain, inline)]
tag 11271 notabug
thanks

On 04/18/2012 05:01 AM, Kevin Huanpeng Du wrote:
> Hi,
> i find dirname dirname strip a dir name when a string with out a filename.
> 
> ₤ dirname /dir/file
> ₤ /dir
> ₤ dirname /dir/subdir/
> ₤ /dir # is this right? subdir is a not a file.

Thanks for the report.  However, this is not a bug.  POSIX requires this
behavior.  In POSIX parlance, a "file" is any entity that can be
referenced by name as a member of a directory.  There are multiple types
of files: regular files, block device files, character device files,
sockets, and important to your case, subdirectories.  Only
subdirectories may have a trailing slash, but the point remains that
even without the trailing slash, 'subdir' is a file (of type directory,
rather than the more typical type regular file), which can be referenced
by name from the directory '/dir'.

The POSIX-mandated algorithm for the dirname executable is to strip
trailing slashes _before_ removing the trailing file name element,
precisely for usage like this:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dirname.html

1    If string is //, skip steps 2 to 5.

2    If string consists entirely of <slash> characters, string shall be
set to a single <slash> character. In this case, skip steps 3 to 8.

3    If there are any trailing <slash> characters in string, they shall
be removed.

4    If there are no <slash> characters remaining in string, string
shall be set to a single <period> character. In this case, skip steps 5
to 8.

5    If there are any trailing non- <slash> characters in string, they
shall be removed.

6    If the remaining string is //, it is implementation-defined whether
steps 7 and 8 are skipped or processed.

7    If there are any trailing <slash> characters in string, they shall
be removed.

8    If the remaining string is empty, string shall be set to a single
<slash> character.


And according to that algorithm, even though '/dir/subdir',
'/dir/subdir/' and '/dir/subdir/.' all resolve to the same location in
the file system, using dirname on the first two gives '/dir' while using
'dirname /dir/subdir/.' gives '/dir/subdir'.

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 17 May 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 30 days ago.

Previous Next


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