diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 34 |
1 files changed, 10 insertions, 24 deletions
@@ -126,14 +126,6 @@ int flock(int, int); #define STAT(p, s) stat((p), (s)) #endif -#if defined _WIN32 || defined __APPLE__ -# define USE_OSPATH 1 -# define TO_OSPATH(str) rb_str_encode_ospath(str) -#else -# define USE_OSPATH 0 -# define TO_OSPATH(str) (str) -#endif - VALUE rb_cFile; VALUE rb_mFileTest; VALUE rb_cStat; @@ -230,7 +222,7 @@ rb_get_path(VALUE obj) VALUE rb_str_encode_ospath(VALUE path) { -#if USE_OSPATH +#if defined _WIN32 || defined __APPLE__ int encidx = ENCODING_GET(path); #ifdef _WIN32 if (encidx == ENCINDEX_ASCII) { @@ -3841,10 +3833,11 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, else { struct stat sbuf; int ret; + VALUE testpath2 = rb_str_encode_ospath(testpath); #ifdef __native_client__ - ret = stat(RSTRING_PTR(testpath), &sbuf); + ret = stat(RSTRING_PTR(testpath2), &sbuf); #else - ret = lstat(RSTRING_PTR(testpath), &sbuf); + ret = lstat(RSTRING_PTR(testpath2), &sbuf); #endif if (ret == -1) { int e = errno; @@ -3916,12 +3909,9 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode if (!NIL_P(basedir)) { FilePathValue(basedir); - basedir = TO_OSPATH(rb_str_dup_frozen(basedir)); + basedir = rb_str_dup_frozen(basedir); } - enc = rb_enc_get(unresolved_path); - origenc = enc; - unresolved_path = TO_OSPATH(unresolved_path); RSTRING_GETMEM(unresolved_path, ptr, len); path_names = skipprefixroot(ptr, ptr + len, rb_enc_get(unresolved_path)); if (ptr != path_names) { @@ -3938,7 +3928,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode } } - curdir = rb_dir_getwd_ospath(); + curdir = rb_dir_getwd(); RSTRING_GETMEM(curdir, ptr, len); curdir_names = skipprefixroot(ptr, ptr + len, rb_enc_get(curdir)); resolved = rb_str_subseq(curdir, 0, curdir_names - ptr); @@ -3946,6 +3936,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode root_found: RSTRING_GETMEM(resolved, prefixptr, prefixlen); pend = prefixptr + prefixlen; + enc = rb_enc_get(resolved); ptr = chompdirsep(prefixptr, pend, enc); if (ptr < pend) { prefixlen = ++ptr - prefixptr; @@ -3960,6 +3951,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode } #endif + origenc = enc; switch (rb_enc_to_index(enc)) { case ENCINDEX_ASCII: case ENCINDEX_US_ASCII: @@ -3978,14 +3970,8 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode if (realpath_rec(&prefixlen, &resolved, path_names, loopcheck, mode, 1)) return Qnil; - if (origenc != rb_enc_get(resolved)) { - if (rb_enc_str_asciionly_p(resolved)) { - rb_enc_associate(resolved, origenc); - } - else { - resolved = rb_str_conv_enc(resolved, NULL, origenc); - } - } + if (origenc != enc && rb_enc_str_asciionly_p(resolved)) + rb_enc_associate(resolved, origenc); OBJ_TAINT(resolved); return resolved; |