|
From: | GNU bug Tracking System |
Subject: | [debbugs-tracker] bug#11271: closed (dirname /home/dir/) |
Date: | Wed, 18 Apr 2012 17:36:02 +0000 |
Your message dated Wed, 18 Apr 2012 11:35:23 -0600 with message-id <address@hidden> and subject line Re: bug#11271: dirname /home/dir/ has caused the debbugs.gnu.org bug report #11271, regarding dirname /home/dir/ to be marked as done. (If you believe you have received this mail in error, please contact address@hidden) -- 11271: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11271 GNU Bug Tracking System Contact address@hidden with problems
--- Begin Message ---Subject: dirname /home/dir/ Date: Wed, 18 Apr 2012 19:01:29 +0800 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
--- End Message ---
--- Begin Message ---Subject: Re: bug#11271: dirname /home/dir/ Date: Wed, 18 Apr 2012 11:35:23 -0600 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 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 address@hidden +1-919-301-3266 Libvirt virtualization library http://libvirt.orgsignature.asc
Description: OpenPGP digital signature
--- End Message ---
[Prev in Thread] | Current Thread | [Next in Thread] |