mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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/trunk@21447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7099360a6c
commit
729b4a813b
3 changed files with 75 additions and 28 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Mon Jan 12 16:45:28 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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]
|
||||||
|
|
||||||
Mon Jan 12 12:43:55 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Jan 12 12:43:55 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* instruby.rb (parse_args, install): added --strip option.
|
* instruby.rb (parse_args, install): added --strip option.
|
||||||
|
|
|
@ -97,6 +97,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_directory_p
|
def test_directory_p
|
||||||
assert(File.directory?(@dir))
|
assert(File.directory?(@dir))
|
||||||
|
assert(!(File.directory?(@dir+"/...")))
|
||||||
assert(!(File.directory?(@file)))
|
assert(!(File.directory?(@file)))
|
||||||
assert(!(File.directory?(@nofile)))
|
assert(!(File.directory?(@nofile)))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1412,13 +1412,44 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
||||||
#define BitOfIsRep(n) ((n) * 2 + 1)
|
#define BitOfIsRep(n) ((n) * 2 + 1)
|
||||||
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
|
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
|
||||||
|
|
||||||
|
static HANDLE
|
||||||
|
open_dir_handle(const char *filename, WIN32_FIND_DATA *fd)
|
||||||
|
{
|
||||||
|
HANDLE fh;
|
||||||
|
static const char wildcard[] = "/*";
|
||||||
|
long len = strlen(filename);
|
||||||
|
char *scanname = malloc(len + sizeof(wildcard));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create the search pattern
|
||||||
|
//
|
||||||
|
if (!scanname) {
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
memcpy(scanname, filename, len + 1);
|
||||||
|
|
||||||
|
if (index("/\\:", *CharPrev(scanname, scanname + len)) == NULL)
|
||||||
|
memcpy(scanname + len, wildcard, sizeof(wildcard));
|
||||||
|
else
|
||||||
|
memcpy(scanname + len, wildcard + 1, sizeof(wildcard) - 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
// do the FindFirstFile call
|
||||||
|
//
|
||||||
|
fh = FindFirstFile(scanname, fd);
|
||||||
|
free(scanname);
|
||||||
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
|
errno = map_errno(GetLastError());
|
||||||
|
}
|
||||||
|
return fh;
|
||||||
|
}
|
||||||
|
|
||||||
DIR *
|
DIR *
|
||||||
rb_w32_opendir(const char *filename)
|
rb_w32_opendir(const char *filename)
|
||||||
{
|
{
|
||||||
DIR *p;
|
DIR *p;
|
||||||
long len;
|
long len;
|
||||||
long idx;
|
long idx;
|
||||||
char *scanname;
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
struct stati64 sbuf;
|
struct stati64 sbuf;
|
||||||
WIN32_FIND_DATA fd;
|
WIN32_FIND_DATA fd;
|
||||||
|
@ -1436,6 +1467,11 @@ rb_w32_opendir(const char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fh = open_dir_handle(filename, &fd);
|
||||||
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get us a DIR structure
|
// Get us a DIR structure
|
||||||
//
|
//
|
||||||
|
@ -1443,32 +1479,6 @@ rb_w32_opendir(const char *filename)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
//
|
|
||||||
// Create the search pattern
|
|
||||||
//
|
|
||||||
len = strlen(filename) + 2 + 1;
|
|
||||||
if (!(scanname = malloc(len))) {
|
|
||||||
free(p);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strlcpy(scanname, filename, len);
|
|
||||||
|
|
||||||
if (index("/\\:", *CharPrev(scanname, scanname + strlen(scanname))) == NULL)
|
|
||||||
strlcat(scanname, "/*", len);
|
|
||||||
else
|
|
||||||
strlcat(scanname, "*", len);
|
|
||||||
|
|
||||||
//
|
|
||||||
// do the FindFirstFile call
|
|
||||||
//
|
|
||||||
fh = FindFirstFile(scanname, &fd);
|
|
||||||
free(scanname);
|
|
||||||
if (fh == INVALID_HANDLE_VALUE) {
|
|
||||||
errno = map_errno(GetLastError());
|
|
||||||
free(p);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -3466,6 +3476,17 @@ fileattr_to_unixmode(DWORD attr, const char *path)
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_valid_dir(const char *path)
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATA fd;
|
||||||
|
HANDLE fh = open_dir_handle(path, &fd);
|
||||||
|
if (fh == INVALID_HANDLE_VALUE)
|
||||||
|
return -1;
|
||||||
|
FindClose(fh);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
winnt_stat(const char *path, struct stati64 *st)
|
winnt_stat(const char *path, struct stati64 *st)
|
||||||
{
|
{
|
||||||
|
@ -3496,6 +3517,9 @@ winnt_stat(const char *path, struct stati64 *st)
|
||||||
errno = map_errno(GetLastError());
|
errno = map_errno(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
if (check_valid_dir(path)) return -1;
|
||||||
|
}
|
||||||
st->st_mode = fileattr_to_unixmode(attr, path);
|
st->st_mode = fileattr_to_unixmode(attr, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3505,6 +3529,21 @@ winnt_stat(const char *path, struct stati64 *st)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN95
|
||||||
|
static int
|
||||||
|
win95_stat(const char *path, struct stati64 *st)
|
||||||
|
{
|
||||||
|
int ret = stati64(path, st);
|
||||||
|
if (ret) return ret;
|
||||||
|
if (st->st_mode & S_IFDIR) {
|
||||||
|
return check_valid_dir(path);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define win95_stat(path, st) -1
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_w32_stat(const char *path, struct stat *st)
|
rb_w32_stat(const char *path, struct stat *st)
|
||||||
{
|
{
|
||||||
|
@ -3552,7 +3591,7 @@ rb_w32_stati64(const char *path, struct stati64 *st)
|
||||||
else if (*end == '\\' || (buf1 + 1 == end && *end == ':'))
|
else if (*end == '\\' || (buf1 + 1 == end && *end == ':'))
|
||||||
strlcat(buf1, ".", size);
|
strlcat(buf1, ".", size);
|
||||||
|
|
||||||
ret = IsWinNT() ? winnt_stat(buf1, st) : stati64(buf1, st);
|
ret = IsWinNT() ? winnt_stat(buf1, st) : win95_stat(buf1, st);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
st->st_mode &= ~(S_IWGRP | S_IWOTH);
|
st->st_mode &= ~(S_IWGRP | S_IWOTH);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue