https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-05-23T12:04:20ZRuby Issue Tracking SystemRuby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=781692019-05-23T12:04:20ZEregon (Benoit Daloze)
<ul></ul><p><code>Pathname("C:/foo/bar").absolute?</code> should return <code>true</code> on Windows.<br>
I think it does already:<br>
<a href="https://github.com/ruby/ruby/blob/fe3ff5afb07e171fd950623c69abfbabbb2762a3/test/pathname/test_pathname.rb#L278-L282" class="external">https://github.com/ruby/ruby/blob/fe3ff5afb07e171fd950623c69abfbabbb2762a3/test/pathname/test_pathname.rb#L278-L282</a></p>
<p>On non-Windows platforms it will return <code>false</code>, which is correct for non-Windows platforms.</p>
<p>About <code>File.absolute_path?</code>, it sounds good to me.</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=781702019-05-23T12:25:00Zdeivid (David Rodríguez)
<ul></ul><p>Ouch!</p>
<p>I actually read the <code>Pathname</code> docs, which state:</p>
<ul>
<li>
<p>"However non-Unix pathnames are supported experimentally", in the main section.</p>
</li>
<li>
<p>"It returns true if the pathname begins with a slash", in the <code>#pathname</code> docs.</p>
</li>
</ul>
<p>And assumed this didn't work on Windows.</p>
<p>If this is the case, I'm not too strong towards adding <code>File.absolute_path?</code> although it still seems handy and simple?</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=781712019-05-23T13:11:29Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><blockquote>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gi">+ File.basename("/foo/bar\\baz").should == true
</span></code></pre>
</blockquote>
<p>The method name is wrong, and <code>File.absolute_path?("/foo/bar")</code> should be false on Windows as it doesn't have the drive letter.</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=781722019-05-23T13:32:19Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I have no particular pro/con opinion on the suggestion itself, but I should state that since Pathname was mentioned - I<br>
myself use File.* related methods exclusively. I used to use pathname in the past but I sort of gave up on it eventually,<br>
primarily because File.* seems to work just fine (and FileUtils); partially also because of having to do require 'pathname'<br>
and my general impression that pathname is more clumsy to work with than File (but this is a subjective opinion). So this<br>
comment from me here is mostly about pathname to File.* related methods - to me, in the current use cases, I could happily<br>
use File.* but it would be unlikely for me to go back to when I used to use pathname.</p>
<p>So when File.* and Pathname is compared, I would like to point out that the way how ruby users use either of them may<br>
be different rather than equal/synonymous. (I am not sure if this comment is very useful but I wanted to point this out<br>
at the least once.)</p>
<p>Having said that, I personally have not had a need for File.absolute_path?() yet. I use File.absolute_path() a lot,<br>
though, often because I have to deal/handle symlinks through ruby, including re-symlinking, removing old symlinks<br>
etc....</p>
<p>I can say that this may be useful, but personally I honestly have not yet had a need for it.</p>
<p>As for the documentation - I guess it could easily be made more accurate or slightly lengthier in this case; I assume<br>
that this may depend a lot on the operating system, since windows is mentioned here. Perhaps the documentation can<br>
add a sentence about present windows support - I have worked only very little with windows, but the ruby code I write<br>
tends to work very well on windows out of the box, without even me trying to do much at all (even ruby-gtk stuff<br>
works on windows, which is pretty cool).</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=781752019-05-23T14:07:45Zdeivid (David Rodríguez)
<ul><li><strong>File</strong> <a href="/attachments/7808">0001-Add-File.absolute_path.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7808/0001-Add-File.absolute_path.patch">0001-Add-File.absolute_path.patch</a> added</li></ul><p>Thanks <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/4">@nobu (Nobuyoshi Nakada)</a>, I updated the patch! Copy-pasta... :|</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=781812019-05-23T22:51:44Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>Out of interest, how does it treat relative paths like <code>C:foo\bar</code>?</p>
<p>(Funny observation: according to Microsoft, <code>\foo\bar</code> is an absolute path in Windows, according to their definition of "absolute path")</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=782222019-05-25T12:48:14Zdeivid (David Rodríguez)
<ul></ul><p>I added a couple more specs to check that in <a href="https://github.com/ruby/ruby/pull/2198/commits/d59a5c93dd4b20aa0898a24fab78a68a2cc84925" class="external">https://github.com/ruby/ruby/pull/2198/commits/d59a5c93dd4b20aa0898a24fab78a68a2cc84925</a>, but I'm not sure where I can check whether they pass on Windows or not.</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=812442019-08-29T05:58:47Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Agreed.</p>
<p>Matz.</p> Ruby master - Feature #15868: Implement `File.absolute_path?`https://bugs.ruby-lang.org/issues/15868?journal_id=814022019-09-05T11:01:23Zdeivid (David Rodríguez)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Add `File.absolute_path?` (#2198) In order to check whether a path is absolute or not in a porta..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/2a166cfea22b90e39e3fe9bafab6b806ed4813f6">git|2a166cfea22b90e39e3fe9bafab6b806ed4813f6</a>.</p>
<hr>
<p>Add <code>File.absolute_path?</code> (<a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: Process.spawn fails in 1.9.1 [ok in trunk] in windows (Rejected)" href="https://bugs.ruby-lang.org/issues/2198">#2198</a>)</p>
<p>In order to check whether a path is absolute or not in a portable way.</p>
<p>[Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Implement `File.absolute_path?` (Closed)" href="https://bugs.ruby-lang.org/issues/15868">#15868</a>]</p>