rename(p1, p2)
public
Show source
static VALUE
rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
{
struct rename_args ra;
VALUE f, t;
FilePathValue(from);
FilePathValue(to);
f = rb_str_encode_ospath(from);
t = rb_str_encode_ospath(to);
ra.src = StringValueCStr(f);
ra.dst = StringValueCStr(t);
errno = 0;
if ((int)(VALUE)rb_thread_call_without_gvl(no_gvl_rename, &ra,
RUBY_UBF_IO, 0) < 0) {
int e = errno;
switch (e) {
case EEXIST:
if (chmod(ra.dst, 0666) == 0 &&
unlink(ra.dst) == 0 &&
rename(ra.src, ra.dst) == 0)
return INT2FIX(0);
}
syserr_fail2(e, from, to);
}
return INT2FIX(0);
}