[ruby-core:92798] [Ruby trunk Feature#15868] Implement `File.absolute_path?`

From: shevegen@...
Date: 2019-05-23 13:32:19 UTC
List: ruby-core #92798
Issue #15868 has been updated by shevegen (Robert A. Heiler).


I have no particular pro/con opinion on the suggestion itself, but I should state that since Pathname was mentioned - I
myself use File.* related methods exclusively. I used to use pathname in the past but I sort of gave up on it eventually,
primarily because File.* seems to work just fine (and FileUtils); partially also because of having to do require 'pathname'
and my general impression that pathname is more clumsy to work with than File (but this is a subjective opinion). So this
comment from me here is mostly about pathname to File.* related methods - to me, in the current use cases, I could happily
use File.* but it would be unlikely for me to go back to when I used to use pathname.

So when File.* and Pathname is compared, I would like to point out that the way how ruby users use either of them may
be different rather than equal/synonymous. (I am not sure if this comment is very useful but I wanted to point this out
at the least once.)

Having said that, I personally have not had a need for File.absolute_path?() yet. I use File.absolute_path() a lot,
though, often because I have to deal/handle symlinks through ruby, including re-symlinking, removing old symlinks
etc....

I can say that this may be useful, but personally I honestly have not yet had a need for it.

As for the documentation - I guess it could easily be made more accurate or slightly lengthier in this case; I assume
that this may depend a lot on the operating system, since windows is mentioned here. Perhaps the documentation can
add a sentence about present windows support - I have worked only very little with windows, but the ruby code I write
tends to work very well on windows out of the box, without even me trying to do much at all (even ruby-gtk stuff
works on windows, which is pretty cool).

----------------------------------------
Feature #15868: Implement `File.absolute_path?`
https://bugs.ruby-lang.org/issues/15868#change-78172

* Author: deivid (David Rodr刕uez)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently there's no way to check whether a path is absolute or not in a way that works accross OSs. The pathname library has the #absolute? method, but that only checks whether the path starts with a slash, which is not appropriate for Windows.

I thought of reimplementing it as something like File.absolute_path(self) == self, but that would mean accessing the filesystem, which I don't think we want here.

I also thought of implementing the "windows letter checks" in the pathname's library, but then I saw that those are already implemented in file.c, so I thought it would be a good idea to expose those. So I propose to add File.absolute_path? for this.

If this is accepted, I can do a follow-up PR to change Pathname#absolute? to delegate to File.absolute_path?.

What do you think?

I attach a patch to add `File.absolute_path?` here (I also opened a PR on Github: https://github.com/ruby/ruby/pull/2198). 

---Files--------------------------------
0001-Add-File.absolute_path.patch (3.24 KB)


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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next