Project

General

Profile

Actions

Bug #11206

closed

short file name match incompatibility

Added by naruse (Yui NARUSE) over 9 years ago. Updated over 9 years ago.

Status:
Closed
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 1 (0 open1 closed)

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

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

Conflict with #10819.
Can these reach a compromise?

Updated by nobu (Nobuyoshi Nakada) over 9 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) over 9 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) over 9 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) over 9 years ago

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

Actions #7

Updated by nobu (Nobuyoshi Nakada) over 9 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]
Actions #8

Updated by usa (Usaku NAKAMURA) over 9 years ago

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

Updated by usa (Usaku NAKAMURA) over 9 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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0