Forum: Ruby-core FileTest.exist? does not convert relative path to absolute path before testing existence

76f42be013abf833273224eb4eaef29c?d=identicon&s=25 unknown (Guest)
on 2014-04-11 15:01
(Received via mailing list)
Issue #9716 has been updated by Mario Maia.


Nobuyoshi Nakada wrote:
> If they do it, you have no way to test files start with '~'.

Good point, I hadn't thought about this borderline case. And from this
case, I take that this is not a bug on `FileTest`, but on
`#expand_path`.

I have played with a bit and it operates in an awkward way. It can
expand `~/~derp_folder~/~derp`, but it cant expand `~derp`.

>Or always File.exist?(path.sub(/\A~/, './~')) and so on.

It is not about what I prefer, but about what works. In my humble
opinion, I think this `#sub` (or some other method) will indeed have to
be called, but not on `FileTest`. It should be called on the first lines
of `#expand_path`. And this pattern will have to be refined a bit more.
I tried it on some cases and it works for some, but for others it
produces a path totally different. I think we will have to use `#sub`
passing a block to it to have more control over the pattern
substitution.

What do you think? And, by the way, should we continue this conversation
here or should I open a new bug reporting `#expand_path`?



----------------------------------------
Bug #9716: FileTest.exist? does not convert relative path to absolute
path before testing existence
https://bugs.ruby-lang.org/issues/9716#change-46162

* Author: Mario Maia
* Status: Rejected
* Priority: Normal
* Assignee:
* Category: core
* Target version:
* ruby -v: 2.1.1p76 (2014-02-24 revision 45161) [i686-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
This topic is locked and can not be replied to.