Skip to content

Commit 6eda194

Browse files
committed
merge revision(s) 21447:
* win32/win32.c (open_dir_handle): extracted from rb_w32_opendir. * win32/win32.c (winnt_stat): gets rid of strange behavior of GetFileAttributes(). [ruby-core:21269] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@22613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 3435f0c commit 6eda194

File tree

3 files changed

+79
-31
lines changed

3 files changed

+79
-31
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Wed Feb 25 14:56:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* win32/win32.c (open_dir_handle): extracted from rb_w32_opendir.
4+
5+
* win32/win32.c (winnt_stat): gets rid of strange behavior of
6+
GetFileAttributes(). [ruby-core:21269]
7+
18
Tue Feb 24 02:41:47 2009 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
29

310
* lib/erb.rb (PercentScanner): remove PercentScanner. fixed % after

version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#define RUBY_VERSION "1.8.6"
2-
#define RUBY_RELEASE_DATE "2009-02-24"
2+
#define RUBY_RELEASE_DATE "2009-02-25"
33
#define RUBY_VERSION_CODE 186
4-
#define RUBY_RELEASE_CODE 20090224
5-
#define RUBY_PATCHLEVEL 352
4+
#define RUBY_RELEASE_CODE 20090225
5+
#define RUBY_PATCHLEVEL 353
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8
99
#define RUBY_VERSION_TEENY 6
1010
#define RUBY_RELEASE_YEAR 2009
1111
#define RUBY_RELEASE_MONTH 2
12-
#define RUBY_RELEASE_DAY 24
12+
#define RUBY_RELEASE_DAY 25
1313

1414
#ifdef RUBY_EXTERN
1515
RUBY_EXTERN const char ruby_version[];

win32/win32.c

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,14 +1467,44 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
14671467
#define BitOfIsRep(n) ((n) * 2 + 1)
14681468
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
14691469

1470+
static HANDLE
1471+
open_dir_handle(const char *filename, WIN32_FIND_DATA *fd)
1472+
{
1473+
HANDLE fh;
1474+
static const char wildcard[] = "/*";
1475+
long len = strlen(filename);
1476+
char *scanname = malloc(len + sizeof(wildcard));
1477+
1478+
//
1479+
// Create the search pattern
1480+
//
1481+
if (!scanname) {
1482+
return INVALID_HANDLE_VALUE;
1483+
}
1484+
memcpy(scanname, filename, len + 1);
1485+
1486+
if (index("/\\:", *CharPrev(scanname, scanname + len)) == NULL)
1487+
memcpy(scanname + len, wildcard, sizeof(wildcard));
1488+
else
1489+
memcpy(scanname + len, wildcard + 1, sizeof(wildcard) - 1);
1490+
1491+
//
1492+
// do the FindFirstFile call
1493+
//
1494+
fh = FindFirstFile(scanname, fd);
1495+
free(scanname);
1496+
if (fh == INVALID_HANDLE_VALUE) {
1497+
errno = map_errno(GetLastError());
1498+
}
1499+
return fh;
1500+
}
1501+
14701502
DIR *
14711503
rb_w32_opendir(const char *filename)
14721504
{
14731505
DIR *p;
14741506
long len;
14751507
long idx;
1476-
char scannamespc[PATHLEN];
1477-
char *scanname = scannamespc;
14781508
struct stat sbuf;
14791509
WIN32_FIND_DATA fd;
14801510
HANDLE fh;
@@ -1492,35 +1522,17 @@ rb_w32_opendir(const char *filename)
14921522
return NULL;
14931523
}
14941524

1495-
//
1496-
// Get us a DIR structure
1497-
//
1498-
1499-
p = xcalloc(sizeof(DIR), 1);
1500-
if (p == NULL)
1525+
fh = open_dir_handle(filename, &fd);
1526+
if (fh == INVALID_HANDLE_VALUE) {
15011527
return NULL;
1502-
1503-
//
1504-
// Create the search pattern
1505-
//
1506-
1507-
strcpy(scanname, filename);
1508-
1509-
if (index("/\\:", *CharPrev(scanname, scanname + strlen(scanname))) == NULL)
1510-
strcat(scanname, "/*");
1511-
else
1512-
strcat(scanname, "*");
1528+
}
15131529

15141530
//
1515-
// do the FindFirstFile call
1531+
// Get us a DIR structure
15161532
//
1517-
1518-
fh = FindFirstFile(scanname, &fd);
1519-
if (fh == INVALID_HANDLE_VALUE) {
1520-
errno = map_errno(GetLastError());
1521-
free(p);
1533+
p = calloc(sizeof(DIR), 1);
1534+
if (p == NULL)
15221535
return NULL;
1523-
}
15241536

15251537
//
15261538
// now allocate the first part of the string table for the
@@ -3173,6 +3185,17 @@ fileattr_to_unixmode(DWORD attr, const char *path)
31733185
return mode;
31743186
}
31753187

3188+
static int
3189+
check_valid_dir(const char *path)
3190+
{
3191+
WIN32_FIND_DATA fd;
3192+
HANDLE fh = open_dir_handle(path, &fd);
3193+
if (fh == INVALID_HANDLE_VALUE)
3194+
return -1;
3195+
FindClose(fh);
3196+
return 0;
3197+
}
3198+
31763199
static int
31773200
winnt_stat(const char *path, struct stat *st)
31783201
{
@@ -3203,6 +3226,9 @@ winnt_stat(const char *path, struct stat *st)
32033226
errno = map_errno(GetLastError());
32043227
return -1;
32053228
}
3229+
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
3230+
if (check_valid_dir(path)) return -1;
3231+
}
32063232
st->st_mode = fileattr_to_unixmode(attr, path);
32073233
}
32083234

@@ -3212,6 +3238,21 @@ winnt_stat(const char *path, struct stat *st)
32123238
return 0;
32133239
}
32143240

3241+
#ifdef WIN95
3242+
static int
3243+
win95_stat(const char *path, struct stat *st)
3244+
{
3245+
int ret = stat(path, st);
3246+
if (ret) return ret;
3247+
if (st->st_mode & S_IFDIR) {
3248+
return check_valid_dir(path);
3249+
}
3250+
return 0;
3251+
}
3252+
#else
3253+
#define win95_stat(path, st) -1
3254+
#endif
3255+
32153256
int
32163257
rb_w32_stat(const char *path, struct stat *st)
32173258
{
@@ -3247,7 +3288,7 @@ rb_w32_stat(const char *path, struct stat *st)
32473288
} else if (*end == '\\' || (buf1 + 1 == end && *end == ':'))
32483289
strcat(buf1, ".");
32493290

3250-
ret = IsWinNT() ? winnt_stat(buf1, st) : stat(buf1, st);
3291+
ret = IsWinNT() ? winnt_stat(buf1, st) : win95_stat(buf1, st);
32513292
if (ret == 0) {
32523293
st->st_mode &= ~(S_IWGRP | S_IWOTH);
32533294
}

0 commit comments

Comments
 (0)