private void setup(String filename, boolean lstat) { Ruby runtime = getRuntime(); if (Platform.IS_WINDOWS && filename.length() == 2 && filename.charAt(1) == ':' && Character.isLetter(filename.charAt(0))) { filename += '/'; } file = JRubyFile.createResource(runtime, filename); stat = lstat ? file.lstat() : file.stat(); if (stat == null) throw runtime.newErrnoFromInt(file.errno(), filename); }
private void setup(String filename, boolean lstat) { Ruby runtime = getRuntime(); if (Platform.IS_WINDOWS && filename.length() == 2 && filename.charAt(1) == ':' && Character.isLetter(filename.charAt(0))) { filename += '/'; } file = JRubyFile.createResource(runtime, filename); stat = lstat ? file.lstat() : file.stat(); if (stat == null) throw runtime.newErrnoFromInt(file.errno(), filename); }
private void setup(String filename, boolean lstat) { if (Platform.IS_WINDOWS && filename.length() == 2 && filename.charAt(1) == ':' && Character.isLetter(filename.charAt(0))) { filename += "/"; } file = JRubyFile.createResource(getRuntime().getCurrentDirectory(), filename); if (!file.exists()) { throw getRuntime().newErrnoENOENTError("No such file or directory - " + filename); } POSIX posix = getRuntime().getPosix(); stat = lstat ? file.lstat(posix) : file.stat(posix); }
@JRubyMethod(name = "symlink?", required = 1, module = true) public static RubyBoolean symlink_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); try { // Note: We can't use file.exists() to check whether the symlink // exists or not, because that method returns false for existing // but broken symlink. So, we try without the existence check, // but in the try-catch block. // MRI behavior: symlink? on broken symlink should return true. return runtime.newBoolean(file.lstat(runtime.getPosix()).isSymlink()); } catch (SecurityException re) { return runtime.getFalse(); } catch (RaiseException re) { return runtime.getFalse(); } }