Project

General

Profile

Bug #11206

short file name match incompatibility

Added by naruse (Yui NARUSE) about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:69435]

Description

When I develop a foo.gem, my working diretory has foo.gemspec and foo.gem.
If I run gem install -l foo, it fails as following:

ERROR: While executing gem ... (Gem::Package::FormatError)
package metadata is missing in foo.gemspec

Because gem command tries to traverse the current directory with Dir["*.gem"],
and it include *.gemspec.

Another example, Rakefile has rake clean task and it is specified by CLEAN constant.
if I specify CLEAN.include( "*.gem" ), it removes *.gemspec.


Related issues

Related to Ruby master - Bug #10819: can't glob win32 short pathname Closed02/02/2015Actions

Associated revisions

Revision 9375ff5b
Added by nobu (Nobuyoshi Nakada) about 4 years ago

dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 50760
Added by nobu (Nobuyoshi Nakada) about 4 years ago

dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]

Revision 50760
Added by nobu (Nobuyoshi Nakada) about 4 years ago

dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]

Revision 50760
Added by nobu (Nobuyoshi Nakada) about 4 years ago

dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]

Revision 50760
Added by nobu (Nobuyoshi Nakada) about 4 years ago

dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]

Revision 50760
Added by nobu (Nobuyoshi Nakada) about 4 years ago

dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]

History

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

Conflict with #10819.
Can these reach a compromise?

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

Running these commands as the administrator would fix the problem:

  1. fsutil 8dot3name set 1
  2. fsutil 8dot3name strip /s /f c:\

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

For better or worse, extension names are something special things on Windows, so what about matching extension of long names, but not short names?

diff --git i/dir.c w/dir.c
index a6934bd..2b03a72 100644
--- i/dir.c
+++ w/dir.c
@@ -1596,7 +1596,21 @@ dirent_match(const char *pat, rb_encoding *enc, const char *name, const struct d
     if (fnmatch(pat, enc, name, flags) == 0) return 1;
 #ifdef _WIN32
     if (dp->d_altname) {
-   if (fnmatch(pat, enc, dp->d_altname, flags) == 0) return 1;
+   const char *altname = dp->d_altname;
+   long altextlen = strlen(dp->d_altname);
+   const char *altext = ruby_enc_find_extname(altname, &altextlen, enc);
+   if (altext) {
+       long extlen = NAMLEN(dp);
+       const char *ext = ruby_enc_find_extname(name, &extlen, enc);
+       if (ext) {
+       char *tmpname = ALLOCA_N(char, altext - altname + extlen + 1);
+       memcpy(tmpname, altname, altext - altname);
+       memcpy(tmpname + (altext - altname), ext, extlen);
+       tmpname[altext - altname + extlen] = '\0';
+       altname = tmpname;
+       }
+   }
+   if (fnmatch(pat, enc, altname, flags) == 0) return 1;
     }
 #endif
     return 0;

Updated by usa (Usaku NAKAMURA) about 4 years ago

IMO, ruby should offer an option to users to select matching short names or not. (maybe File::FNM_SHORTNAME, or somehow.)
And, the default should not match short names.

Updated by usa (Usaku NAKAMURA) about 4 years ago

Seems good.
Thank you, nobu. Commit it, please.

#7

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Assigned to Closed

Applied in changeset r50760.


dir.c: FNM_SHORTNAME

  • dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206]
#8

Updated by usa (Usaku NAKAMURA) about 4 years ago

  • Related to Bug #10819: can't glob win32 short pathname added

Updated by usa (Usaku NAKAMURA) about 4 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: UNKNOWN

Also available in: Atom PDF