summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'file.c')
-rw-r--r--file.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/file.c b/file.c
index 1449303f06..12d71f0bf3 100644
--- a/file.c
+++ b/file.c
@@ -1333,13 +1333,27 @@ static VALUE
rb_file_s_rename(klass, from, to)
VALUE klass, from, to;
{
+ const char *src, *dst;
SafeStringValue(from);
SafeStringValue(to);
- if (rename(StringValueCStr(from), StringValueCStr(to)) < 0) {
+ src = StringValueCStr(from);
+ dst = StringValueCStr(to);
+ if (rename(src, dst) < 0) {
#if defined __CYGWIN__
extern unsigned long __attribute__((stdcall)) GetLastError();
errno = GetLastError(); /* This is a Cygwin bug */
+#elif defined DOSISH && !defined _WIN32
+ if (errno == EEXIST
+#if defined (__EMX__)
+ || errno == EACCES
+#endif
+ ) {
+ if (chmod(dst, 0666) == 0 &&
+ unlink(dst) == 0 &&
+ rename(src, dst) == 0)
+ return INT2FIX(0);
+ }
#endif
sys_fail2(from, to);
}