@Deprecated public Encoding getFileSystemEncoding(Ruby runtime) { return getFileSystemEncoding(); } }
@Deprecated public Encoding getFileSystemEncoding(Ruby runtime) { return getFileSystemEncoding(); } }
private static Map<RubyString, RubyString> asMapOfRubyStrings(final Ruby runtime, final Map<?, ?> map) { @SuppressWarnings("unchecked") final Map<RubyString, RubyString> rubyMap = new HashMap(map.size() + 2); Encoding keyEncoding = runtime.getEncodingService().getLocaleEncoding(); // On Windows, map doesn't have corresponding keys for these if (Platform.IS_WINDOWS) { // these may be null when in a restricted environment (JRUBY-6514) String home = SafePropertyAccessor.getProperty("user.home"); String user = SafePropertyAccessor.getProperty("user.name"); putRubyKeyValuePair(runtime, rubyMap, "HOME", keyEncoding, home == null ? "/" : home, keyEncoding); putRubyKeyValuePair(runtime, rubyMap, "USER", keyEncoding, user == null ? "" : user, keyEncoding); } for (Map.Entry<?, ?> entry : map.entrySet()) { Object val = entry.getKey(); if ( ! (val instanceof String) ) continue; // Java devs can stuff non-string objects into env final String key = (String) val; if (Platform.IS_WINDOWS && StringSupport.startsWith(key, '=')) continue; val = entry.getValue(); if ( ! (val instanceof String) ) continue; // Java devs can stuff non-string objects into env // Ensure PATH is encoded like filesystem Encoding valueEncoding = keyEncoding; if ( org.jruby.platform.Platform.IS_WINDOWS ? key.equalsIgnoreCase("PATH") : key.equals("PATH") ) { valueEncoding = runtime.getEncodingService().getFileSystemEncoding(); } putRubyKeyValuePair(runtime, rubyMap, key, keyEncoding, (String) val, valueEncoding); } return rubyMap; }
private static Map<RubyString, RubyString> asMapOfRubyStrings(final Ruby runtime, final Map<?, ?> map) { @SuppressWarnings("unchecked") final Map<RubyString, RubyString> rubyMap = new HashMap(map.size() + 2); Encoding keyEncoding = runtime.getEncodingService().getLocaleEncoding(); // On Windows, map doesn't have corresponding keys for these if (Platform.IS_WINDOWS) { // these may be null when in a restricted environment (JRUBY-6514) String home = SafePropertyAccessor.getProperty("user.home"); String user = SafePropertyAccessor.getProperty("user.name"); putRubyKeyValuePair(runtime, rubyMap, "HOME", keyEncoding, home == null ? "/" : home, keyEncoding); putRubyKeyValuePair(runtime, rubyMap, "USER", keyEncoding, user == null ? "" : user, keyEncoding); } for (Map.Entry<?, ?> entry : map.entrySet()) { Object val = entry.getKey(); if ( ! (val instanceof String) ) continue; // Java devs can stuff non-string objects into env final String key = (String) val; if (Platform.IS_WINDOWS && StringSupport.startsWith(key, '=')) continue; val = entry.getValue(); if ( ! (val instanceof String) ) continue; // Java devs can stuff non-string objects into env // Ensure PATH is encoded like filesystem Encoding valueEncoding = keyEncoding; if ( org.jruby.platform.Platform.IS_WINDOWS ? key.equalsIgnoreCase("PATH") : key.equals("PATH") ) { valueEncoding = runtime.getEncodingService().getFileSystemEncoding(); } putRubyKeyValuePair(runtime, rubyMap, key, keyEncoding, (String) val, valueEncoding); } return rubyMap; }
private static RubyString filePathConvert(ThreadContext context, RubyString path) { if (!Platform.IS_WINDOWS) { Ruby runtime = context.getRuntime(); EncodingService encodingService = runtime.getEncodingService(); Encoding pathEncoding = path.getEncoding(); // If we are not ascii and do not match fs encoding then transcode to fs. if (runtime.getDefaultInternalEncoding() != null && pathEncoding != encodingService.getUSAsciiEncoding() && pathEncoding != encodingService.getAscii8bitEncoding() && pathEncoding != encodingService.getFileSystemEncoding() && !path.isAsciiOnly()) { path = EncodingUtils.strConvEnc(context, path, pathEncoding, encodingService.getFileSystemEncoding()); } } return path; }
private static RubyString filePathConvert(ThreadContext context, RubyString path) { if (!Platform.IS_WINDOWS) { Ruby runtime = context.getRuntime(); EncodingService encodingService = runtime.getEncodingService(); Encoding pathEncoding = path.getEncoding(); // If we are not ascii and do not match fs encoding then transcode to fs. if (runtime.getDefaultInternalEncoding() != null && pathEncoding != encodingService.getUSAsciiEncoding() && pathEncoding != encodingService.getAscii8bitEncoding() && pathEncoding != encodingService.getFileSystemEncoding() && !path.isAsciiOnly()) { path = EncodingUtils.strConvEnc(context, path, pathEncoding, encodingService.getFileSystemEncoding()); } } return path; }
private static RubyString filePathConvert(ThreadContext context, RubyString path) { if (!org.jruby.platform.Platform.IS_WINDOWS) { Ruby runtime = context.getRuntime(); EncodingService encodingService = runtime.getEncodingService(); Encoding pathEncoding = path.getEncoding(); // If we are not ascii and do not match fs encoding then transcode to fs. if (runtime.getDefaultInternalEncoding() != null && pathEncoding != encodingService.getUSAsciiEncoding() && pathEncoding != encodingService.getAscii8bitEncoding() && pathEncoding != encodingService.getFileSystemEncoding(runtime) && !path.isAsciiOnly()) { ByteList bytes = Transcoder.strConvEnc(context, path.getByteList(), pathEncoding, encodingService.getFileSystemEncoding(runtime)); path = RubyString.newString(runtime, bytes); } } return path; }
private static RubyString filePathConvert(ThreadContext context, RubyString path) { if (!org.jruby.platform.Platform.IS_WINDOWS) { Ruby runtime = context.getRuntime(); EncodingService encodingService = runtime.getEncodingService(); Encoding pathEncoding = path.getEncoding(); // If we are not ascii and do not match fs encoding then transcode to fs. if (runtime.getDefaultInternalEncoding() != null && pathEncoding != encodingService.getUSAsciiEncoding() && pathEncoding != encodingService.getAscii8bitEncoding() && pathEncoding != encodingService.getFileSystemEncoding(runtime) && !path.isAsciiOnly()) { ByteList bytes = Transcoder.strConvEnc(context, path.getByteList(), pathEncoding, encodingService.getFileSystemEncoding(runtime)); path = RubyString.newString(runtime, bytes); } } return path; }
Encoding fsenc = runtime.getEncodingService().getFileSystemEncoding();
Encoding fsenc = runtime.getEncodingService().getFileSystemEncoding();
@JRubyMethod(required = 1, meta = true) public static IRubyObject readlink(ThreadContext context, IRubyObject recv, IRubyObject path) { Ruby runtime = context.runtime; if (Platform.IS_WINDOWS) { // readlink is not available on Windows. See above and jruby/jruby#3287. // TODO: MRI does not implement readlink on Windows, but perhaps we could? throw runtime.newNotImplementedError("readlink"); } JRubyFile link = file(path); try { String realPath = runtime.getPosix().readlink(link.toString()); if (realPath == null) { throw runtime.newErrnoFromLastPOSIXErrno(); } return RubyString.newString(runtime, realPath, runtime.getEncodingService().getFileSystemEncoding()); } catch (IOException e) { throw runtime.newIOError(e.getMessage()); } }
@JRubyMethod(required = 1, meta = true) public static IRubyObject readlink(ThreadContext context, IRubyObject recv, IRubyObject path) { Ruby runtime = context.runtime; if (Platform.IS_WINDOWS) { // readlink is not available on Windows. See above and jruby/jruby#3287. // TODO: MRI does not implement readlink on Windows, but perhaps we could? throw runtime.newNotImplementedError("readlink"); } JRubyFile link = file(path); try { String realPath = runtime.getPosix().readlink(link.toString()); if (realPath == null) { throw runtime.newErrnoFromLastPOSIXErrno(); } return RubyString.newString(runtime, realPath, runtime.getEncodingService().getFileSystemEncoding()); } catch (IOException e) { throw runtime.newIOError(e.getMessage()); } }
private static RubyString normalizeEnvString(ThreadContext context, RubyString key, RubyString value) { final Ruby runtime = context.runtime; RubyString valueStr; // Ensure PATH is encoded like filesystem if (Platform.IS_WINDOWS ? equalIgnoreCase(context, key, RubyString.newString(context.runtime, PATH_BYTES)) : key.getByteList().equal(PATH_BYTES)) { Encoding enc = runtime.getEncodingService().getFileSystemEncoding(); valueStr = EncodingUtils.strConvEnc(context, value, value.getEncoding(), enc); if (value == valueStr) valueStr = (RubyString) value.dup(); } else { valueStr = RubyString.newString(runtime, value.toString(), runtime.getEncodingService().getLocaleEncoding()); } valueStr.setFrozen(true); return valueStr; }
private static RubyString normalizeEnvString(ThreadContext context, RubyString key, RubyString value) { final Ruby runtime = context.runtime; RubyString valueStr; // Ensure PATH is encoded like filesystem if (Platform.IS_WINDOWS ? equalIgnoreCase(context, key, RubyString.newString(context.runtime, PATH_BYTES)) : key.getByteList().equal(PATH_BYTES)) { Encoding enc = runtime.getEncodingService().getFileSystemEncoding(); valueStr = EncodingUtils.strConvEnc(context, value, value.getEncoding(), enc); if (value == valueStr) valueStr = (RubyString) value.dup(); } else { valueStr = RubyString.newString(runtime, value.toString(), runtime.getEncodingService().getLocaleEncoding()); } valueStr.setFrozen(true); return valueStr; }