Project

General

Profile

Feature #3356

Add GetShortPathName to ruby

Added by Christian Höltje over 6 years ago. Updated 11 months ago.

Status:
Feedback
Priority:
Normal
[ruby-core:30470]

Description

=begin
Hi!

I use Ruby on windows and it would be really useful to have access to GetShortPathName in ruby.

I have a monkey-patch to add Pathname.shortpath (attached) to demonstrate it. Probably realpath, etc. should take this in to account as well, since in windows, only the shortpath is canonical.

In addition, the shortpath doesn't need to be escaped, so you can use it with backticks (`), etc.

Ciao!
=end

pathname-shortpath.rb View - Monkey patch to pathname (640 Bytes) Christian Höltje, 05/28/2010 01:42 AM

History

#1 Updated by Akira Tanaka over 6 years ago

=begin
2010/5/28 Christian Höltje redmine@ruby-lang.org:

Bug #3356: Add GetShortPathName to ruby
http://redmine.ruby-lang.org/issues/show/3356

I use Ruby on windows and it would be really useful to have access to GetShortPathName in ruby.

I think it should be defined as a class method of File at first,
as other many methods in Pathname.
--
Tanaka Akira

=end

#2 [ruby-core:39123] Updated by Roger Pack over 5 years ago

I could use this as well (because some File-like classes return an 8.3 filename, some the full filename, so not always is the 8.3 name available), though ffi is or winapi is a good work-around for the present.

#3 [ruby-core:43598] Updated by Yusuke Endoh over 4 years ago

  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada

#4 [ruby-core:43599] Updated by Nobuyoshi Nakada over 4 years ago

  • Status changed from Assigned to Feedback
  • Assignee deleted (Nobuyoshi Nakada)
  • Priority changed from Normal to 3

What do you mean by "canonical"?
It doesn't feel like "canonical" at all.

#5 [ruby-core:49709] Updated by Yusuke Endoh about 4 years ago

  • Target version set to next minor

#6 [ruby-core:49766] Updated by Luis Lavena about 4 years ago

  • Assignee set to Usaku NAKAMURA

Hello,

AFAIK shortnames might not be available on some NTFS volumes, under some circumstances I found is off for performance.

Shortname version of a filename is not canonical, is just one of many representations of a file in the filesystem.

If the intention is use short_name to be able to shell out, why not improve Windows support on ShellWords so it properly escapes the path instead?

We keep improving Ruby on Windows to properly support long names and path with spaces that adding this seems counter productive from my point of view.

I'm assigning to Nakamura-san for decision.

Thank you.

#7 [ruby-core:49800] Updated by Usaku NAKAMURA about 4 years ago

Hello,

In message " [ruby-trunk - Feature #3356] Add GetShortPathName to ruby"
on Nov.21,2012 00:17:14, luislavena@gmail.com wrote:

Shortname version of a filename is not canonical, is just one of many representations of a file in the filesystem.

agreed.
I've realized that the shortname is a kind of a hardlink.

If the intention is use short_name to be able to shell out, why not improve Windows support on ShellWords so it properly escapes the path instead?

We keep improving Ruby on Windows to properly support long names and path with spaces that adding this seems counter productive from my point of view.

agreed.

However, improving the longname (expecially including spaces) is not
conflict to add a new method to get shortname, I think.
Since I do not have a usecase of the method, I cannot judge whether
the method is necessery or not.
Therefore, users who need the method should show some suitable usecases.
Of course, as menthioned above, to gloss over the problems in ruby itself
with handling longnames.

Regards,
--
U.Nakamura usa@garbagecollect.jp

#8 [ruby-core:73019] Updated by Sebastian Schuberth 11 months ago

Usaku NAKAMURA wrote:

Since I do not have a usecase of the method, I cannot judge whether
the method is necessery or not.
Therefore, users who need the method should show some suitable usecases.

I'd also like to see a "shortpath" method implemented, but also the opposite "longpath" (like suggested at [1]).

My use-case is that I need de-duplicate a list of Windows paths, i.e. generate a list of unique paths. The list may contain short paths as well as long paths, so a solution would be to first convert all paths to their long form, and then do case-insensitive string matches. Currently, that does not seem possible in Ruby as there's not way to explicitly get a long path for a short path (also see [2]) or vice versa. If we have a "longpath" (or "shortpath) we should also have a "shortpath" (or "longpath") for symmetry.

[1] http://stackoverflow.com/a/8142448/1127485
[2] http://stackoverflow.com/q/34919422/1127485

#9 [ruby-core:73027] Updated by Nobuyoshi Nakada 11 months ago

You can get the stored name by File.realpath, and tell if two files are same by File.identical?.

Also available in: Atom PDF