* win32/win32.c (rb_w32_mkdir): should set EEXIST (not EACCES)

if file or directory already exists. (bcc32)

* win32/win32.c (rb_w32_rmdir): should set ENOTDIR (not EINVAL)
  if it is not directory. (bcc32, win32)

* win32/win32.c (rb_w32_rmdir, rb_w32_unlink): restore
  FILE_ATTRIBUTE_READONLY flag on function failure.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ocean 2005-07-13 10:40:06 +00:00
parent 4d52e65787
commit 80b0773d33
2 changed files with 34 additions and 23 deletions

View File

@ -1,3 +1,14 @@
Wed Jul 13 19:36:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_mkdir): should set EEXIST (not EACCES)
if file or directory already exists. (bcc32)
* win32/win32.c (rb_w32_rmdir): should set ENOTDIR (not EINVAL)
if it is not directory. (bcc32, win32)
* win32/win32.c (rb_w32_rmdir, rb_w32_unlink): restore
FILE_ATTRIBUTE_READONLY flag on function failure.
Wed Jul 13 12:40:00 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Wed Jul 13 12:40:00 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c: TclTkLib.do_one_event doesn't work. * ext/tk/tcltklib.c: TclTkLib.do_one_event doesn't work.

View File

@ -152,6 +152,7 @@ static struct {
{ ERROR_NEGATIVE_SEEK, EINVAL }, { ERROR_NEGATIVE_SEEK, EINVAL },
{ ERROR_SEEK_ON_DEVICE, EACCES }, { ERROR_SEEK_ON_DEVICE, EACCES },
{ ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
{ ERROR_DIRECTORY, ENOTDIR },
{ ERROR_NOT_LOCKED, EACCES }, { ERROR_NOT_LOCKED, EACCES },
{ ERROR_BAD_PATHNAME, ENOENT }, { ERROR_BAD_PATHNAME, ENOENT },
{ ERROR_MAX_THRDS_REACHED, EAGAIN }, { ERROR_MAX_THRDS_REACHED, EAGAIN },
@ -3623,19 +3624,17 @@ rb_w32_isatty(int fd)
} }
#endif #endif
#undef mkdir
#undef rmdir
int int
rb_w32_mkdir(const char *path, int mode) rb_w32_mkdir(const char *path, int mode)
{ {
int ret = -1; int ret = -1;
RUBY_CRITICAL(do { RUBY_CRITICAL(do {
if (mkdir(path) == -1) if (CreateDirectory(path, NULL) == FALSE) {
errno = map_errno(GetLastError());
break; break;
}
if (chmod(path, mode) == -1) { if (chmod(path, mode) == -1) {
int save_errno = errno; RemoveDirectory(path);
rmdir(path);
errno = save_errno;
break; break;
} }
ret = 0; ret = 0;
@ -3646,37 +3645,38 @@ rb_w32_mkdir(const char *path, int mode)
int int
rb_w32_rmdir(const char *path) rb_w32_rmdir(const char *path)
{ {
DWORD attr; int ret = 0;
int ret;
RUBY_CRITICAL({ RUBY_CRITICAL({
attr = GetFileAttributes(path); const DWORD attr = GetFileAttributes(path);
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) { if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
attr &= ~FILE_ATTRIBUTE_READONLY; SetFileAttributes(path, attr & ~FILE_ATTRIBUTE_READONLY);
SetFileAttributes(path, attr);
} }
ret = rmdir(path); if (RemoveDirectory(path) == FALSE) {
if (ret < 0 && attr != (DWORD)-1) { errno = map_errno(GetLastError());
SetFileAttributes(path, attr); ret = -1;
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
SetFileAttributes(path, attr);
}
} }
}); });
return ret; return ret;
} }
#undef unlink
int int
rb_w32_unlink(const char *path) rb_w32_unlink(const char *path)
{ {
DWORD attr; int ret = 0;
int ret;
RUBY_CRITICAL({ RUBY_CRITICAL({
attr = GetFileAttributes(path); const DWORD attr = GetFileAttributes(path);
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) { if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
attr &= ~FILE_ATTRIBUTE_READONLY; SetFileAttributes(path, attr & ~FILE_ATTRIBUTE_READONLY);
SetFileAttributes(path, attr);
} }
ret = unlink(path); if (DeleteFile(path) == FALSE) {
if (ret < 0 && attr != (DWORD)-1) { errno = map_errno(GetLastError());
SetFileAttributes(path, attr); ret = -1;
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
SetFileAttributes(path, attr);
}
} }
}); });
return ret; return ret;