mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* file.c (file_expand_path): fix for non-existent files and SFN of
symlinks. [ruby-talk:303736] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3bd8032918
commit
552d3a5bcc
2 changed files with 21 additions and 19 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Jun 3 16:06:09 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* file.c (file_expand_path): fix for non-existent files and SFN of
|
||||||
|
symlinks. [ruby-talk:303736]
|
||||||
|
|
||||||
Tue Jun 3 15:12:01 2008 Akinori MUSHA <knu@iDaemons.org>
|
Tue Jun 3 15:12:01 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* lib/set.rb (Set#classify): Back out the `group_by' alias.
|
* lib/set.rb (Set#classify): Back out the `group_by' alias.
|
||||||
|
|
35
file.c
35
file.c
|
@ -2830,57 +2830,54 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
|
||||||
|
|
||||||
#if USE_NTFS
|
#if USE_NTFS
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (1 &&
|
if (*(s = skipprefix(b = buf)) && !strpbrk(s, "*?")) {
|
||||||
#ifdef __CYGWIN__
|
|
||||||
!(buf[0] == '/' && !buf[1]) &&
|
|
||||||
#endif
|
|
||||||
!strpbrk(b = buf, "*?")) {
|
|
||||||
size_t len;
|
size_t len;
|
||||||
WIN32_FIND_DATA wfd;
|
WIN32_FIND_DATA wfd;
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
int lnk_added = 0, is_symlink = 0;
|
int lnk_added = 0, is_symlink = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char w32buf[MAXPATHLEN], sep = 0;
|
char w32buf[MAXPATHLEN];
|
||||||
p = 0;
|
p = strrdirsep(s);
|
||||||
if (lstat(buf, &st) == 0 && S_ISLNK(st.st_mode)) {
|
if (lstat(buf, &st) == 0 && S_ISLNK(st.st_mode)) {
|
||||||
is_symlink = 1;
|
is_symlink = 1;
|
||||||
p = strrdirsep(buf);
|
*p = '\0';
|
||||||
if (!p) p = skipprefix(buf);
|
|
||||||
if (p) {
|
|
||||||
sep = *p;
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cygwin_conv_to_win32_path(buf, w32buf) == 0) {
|
if (cygwin_conv_to_win32_path((*buf ? buf : "/"), w32buf) == 0) {
|
||||||
b = w32buf;
|
b = w32buf;
|
||||||
}
|
}
|
||||||
if (p) *p = sep;
|
|
||||||
else p = buf;
|
|
||||||
if (is_symlink && b == w32buf) {
|
if (is_symlink && b == w32buf) {
|
||||||
|
*p = '\\';
|
||||||
|
strlcat(w32buf, p, sizeof(w32buf));
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
if (len > 4 && STRCASECMP(p + len - 4, ".lnk") != 0) {
|
if (len > 4 && STRCASECMP(p + len - 4, ".lnk") != 0) {
|
||||||
lnk_added = 1;
|
lnk_added = 1;
|
||||||
strlcat(w32buf, ".lnk", sizeof(w32buf));
|
strlcat(w32buf, ".lnk", sizeof(w32buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*p = '/';
|
||||||
#endif
|
#endif
|
||||||
HANDLE h = FindFirstFile(b, &wfd);
|
HANDLE h = FindFirstFile(b, &wfd);
|
||||||
if (h != INVALID_HANDLE_VALUE) {
|
if (h != INVALID_HANDLE_VALUE) {
|
||||||
FindClose(h);
|
FindClose(h);
|
||||||
p = strrdirsep(buf);
|
|
||||||
len = strlen(wfd.cFileName);
|
len = strlen(wfd.cFileName);
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
if (lnk_added && len > 4 &&
|
if (lnk_added && len > 4 &&
|
||||||
STRCASECMP(wfd.cFileName + len - 4, ".lnk") == 0) {
|
STRCASECMP(wfd.cFileName + len - 4, ".lnk") == 0) {
|
||||||
wfd.cFileName[len -= 4] = '\0';
|
wfd.cFileName[len -= 4] = '\0';
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
p = strrdirsep(s);
|
||||||
#endif
|
#endif
|
||||||
if (!p) p = buf;
|
++p;
|
||||||
else ++p;
|
|
||||||
BUFCHECK(bdiff + len >= buflen);
|
BUFCHECK(bdiff + len >= buflen);
|
||||||
memcpy(p, wfd.cFileName, len + 1);
|
memcpy(p, wfd.cFileName, len + 1);
|
||||||
p += len;
|
p += len;
|
||||||
}
|
}
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
else {
|
||||||
|
p += strlen(p);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue