[ruby-core:64080] [ruby-trunk - Bug #10067] [Closed] File.file? misleading semantics & documentation for symbolic links

From: e@...
Date: 2014-07-27 20:25:18 UTC
List: ruby-core #64080
Issue #10067 has been updated by Zachary Scott.

Status changed from Assigned to Closed
% Done changed from 0 to 100

Applied in changeset r46978.

----------
* file.c: [DOC] Clarify how File.file? handles symbolic links. Also
  cleaned up the rdoc style for this method, more to follow.
  Originally reported by Michael Renner [Bug #10067]

----------------------------------------
Bug #10067: File.file? misleading semantics & documentation for symbolic links
https://bugs.ruby-lang.org/issues/10067#change-48089

* Author: Michael Renner
* Status: Closed
* Priority: Normal
* Assignee: Zachary Scott
* Category: doc
* Target version: current: 2.2.0
* ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
The documentation for ``File.file?`` states:

"Returns true if the named file exists and is a regular file."


When trying that out I get the following results:


~~~
% /usr/bin/stat link
  File: `link' -> `file'
  Size: 4         	Blocks: 0          IO Block: 4096   symbolic link
Device: 16h/22d	Inode: 2804357     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/    robe)   Gid: ( 1000/    robe)
Access: 2014-07-19 01:01:51.514979670 +0200
Modify: 2014-07-19 01:01:50.799975936 +0200
Change: 2014-07-19 01:01:50.799975936 +0200
 Birth: -
% ruby -e "puts File.file?('link')"
false
% ruby -e "puts File.symlink?('link')"
true
% touch file
% ruby -e "puts File.file?('link')"
true
% ruby -e "puts File.symlink?('link')"
true
%
~~~

which is entirely not what one would expect.

You need to decide if the ``File`` ``?``-methods offer [stat](http://pubs.opengroup.org/onlinepubs/009695399/functions/stat.html) _OR_ [lstat](http://pubs.opengroup.org/onlinepubs/009695399/functions/lstat.html) semantic, change it and document it accordingly.

The current documentation and implementation behavior is especially confusing since the [POSIX standard](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html) states that the type of a file can be either a regular file _OR_ a symlink, not both at the same time.



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next