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); }
@JRubyMethod(name = "setgid?", required = 1, module = true) public static IRubyObject setgid_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isSetgid()); }
@JRubyMethod(name = "socket?", required = 1, module = true) public static IRubyObject socket_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isSocket()); }
@JRubyMethod(name = "owned?", required = 1, module = true) public static IRubyObject owned_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isOwned()); }
@JRubyMethod(name = "sticky?", required = 1, module = true) public static IRubyObject sticky_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isSticky()); }
@JRubyMethod(name = "blockdev?", required = 1, module = true) public static IRubyObject blockdev_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isBlockDev()); }
@JRubyMethod(name = "pipe?", required = 1, module = true) public static IRubyObject pipe_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isNamedPipe()); }
@JRubyMethod(name = "blockdev?", required = 1, module = true) public static IRubyObject blockdev_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isBlockDev()); }
@JRubyMethod(name = "setuid?", required = 1, module = true) public static IRubyObject setuid_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isSetuid()); }
@JRubyMethod(name = "socket?", required = 1, module = true) public static IRubyObject socket_p(IRubyObject recv, IRubyObject filename) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isSocket()); }
@JRubyMethod(name = "grpowned?", required = 1, module = true) public static IRubyObject grpowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileStat stat = fileResource(filename).stat(); // JRUBY-4446, grpowned? always returns false on Windows if (Platform.IS_WINDOWS) return runtime.getFalse(); return runtime.newBoolean(stat != null && stat.isGroupOwned()); }
public static IRubyObject rowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isROwned()); }
@JRubyMethod(name = "grpowned?", required = 1, module = true) public static IRubyObject grpowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileStat stat = fileResource(filename).stat(); // JRUBY-4446, grpowned? always returns false on Windows if (Platform.IS_WINDOWS) return runtime.getFalse(); return runtime.newBoolean(stat != null && stat.isGroupOwned()); }
@JRubyMethod(name = "chardev?", required = 1, module = true) public static IRubyObject chardev_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isCharDev()); }
@JRubyMethod(name = "executable?", required = 1, module = true) public static IRubyObject executable_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isExecutable()); }
@JRubyMethod(name = "executable_real?", required = 1, module = true) public static IRubyObject executable_real_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isExecutableReal()); }
@JRubyMethod(name = "sticky?", required = 1, module = true) public static IRubyObject sticky_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isSticky()); }
@JRubyMethod(name = "owned?", required = 1, module = true) public static IRubyObject owned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isOwned()); }
@JRubyMethod(name = "size", required = 1, module = true) public static IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject filename) { if (!(filename instanceof RubyFile) && filename.respondsTo("to_io")) { filename = TypeConverter.convertToType(filename, context.runtime.getIO(), "to_io"); } FileStat stat = fileResource(filename).stat(); if (stat == null) noFileError(filename); return context.runtime.newFixnum(stat.st_size()); }
@JRubyMethod(name = "grpowned?", required = 1, module = true) public static IRubyObject grpowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); // JRUBY-4446, grpowned? always returns false on Windows if (Platform.IS_WINDOWS) { return runtime.getFalse(); } return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isGroupOwned()); }