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); }
private final void checkDirIgnoreClosed() { testFrozen("Dir"); // update snapshot (if changed) : if (snapshot == null || dir.exists() && dir.lastModified() > lastModified) { lastModified = dir.lastModified(); snapshot = list(dir); } }
static IOException mapFileNotFoundOnGetChannel(final FileResource file, final FileNotFoundException ex) { // Java throws FileNotFoundException both if the file doesn't exist or there were // permission issues, but Ruby needs to disambiguate those two cases return file.exists() ? new ResourceException.PermissionDenied(file.absolutePath()) : new ResourceException.NotFound(file.absolutePath()); }
private static FileResource getExistingDir(final Ruby runtime, final String path) { FileResource result = JRubyFile.createResource(runtime, path); if (result == null || !result.exists()) { throw runtime.newErrnoENOENTError(path); } if (!result.isDirectory()) { throw runtime.newErrnoENOTDIRError(path); } return result; }
private static FileResource getExistingDir(final Ruby runtime, final String path) { FileResource result = JRubyFile.createResource(runtime, path); if (result == null || !result.exists()) { throw runtime.newErrnoENOENTError(path); } if (!result.isDirectory()) { throw runtime.newErrnoENOTDIRError(path); } return result; }
static IOException mapFileNotFoundOnGetChannel(final FileResource file, final FileNotFoundException ex) { // Java throws FileNotFoundException both if the file doesn't exist or there were // permission issues, but Ruby needs to disambiguate those two cases return file.exists() ? new ResourceException.PermissionDenied(file.absolutePath()) : new ResourceException.NotFound(file.absolutePath()); }
static boolean exist(ThreadContext context, RubyString path) { final String pathStr = path.decodeString(); if (!Ruby.isSecurityRestricted()) { if (JRubyFile.createResource(context.runtime, pathStr).exists()) return true; } return existsOnClasspath(context, pathStr); }
static boolean exist(ThreadContext context, RubyString path) { final String pathStr = path.decodeString(); if (!Ruby.isSecurityRestricted()) { if (JRubyFile.createResource(context.runtime, pathStr).exists()) return true; } return existsOnClasspath(context, pathStr); }
private final void checkDirIgnoreClosed() { testFrozen("Dir"); // update snapshot (if changed) : if (snapshot == null || dir.exists() && dir.lastModified() > lastModified) { lastModified = dir.lastModified(); snapshot = list(dir); } }
@JRubyMethod(name = {"readable?", "readable_real?"}, required = 1, module = true) public static IRubyObject readable_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile)) { filename = get_path(context, filename); } FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.canRead()); }
@JRubyMethod(name = "file?", required = 1, module = true) public static RubyBoolean file_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile)) { filename = get_path(context, filename); } FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.isFile()); }
private static String[] getEntries(ThreadContext context, FileResource dir, String path) { if (!dir.isDirectory()) { if (dir.exists()) { throw context.runtime.newErrnoENOTDIRError(path); } throw context.runtime.newErrnoENOENTError(path); } if (!dir.canRead()) throw context.runtime.newErrnoEACCESError(path); String[] list = dir.list(); return list == null ? NO_FILES : list; }
private static String[] getEntries(ThreadContext context, FileResource dir, String path) { if (!dir.isDirectory()) { if (dir.exists()) { throw context.runtime.newErrnoENOTDIRError(path); } throw context.runtime.newErrnoENOENTError(path); } if (!dir.canRead()) throw context.runtime.newErrnoEACCESError(path); String[] list = dir.list(); return list == null ? NO_FILES : list; }
public static IRubyObject directory_p(ThreadContext context, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile || filename instanceof RubyIO)) { if (filename.respondsTo("to_io")) { filename = (RubyIO) TypeConverter.convertToType(filename, context.runtime.getIO(), "to_io"); } else { filename = get_path(context, filename); } } FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.isDirectory()); }
@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 = "pipe?", required = 1, module = true) public static IRubyObject pipe_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isNamedPipe()); }
@JRubyMethod(name = "setgid?", required = 1, module = true) public static IRubyObject setgid_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isSetgid()); }
@JRubyMethod(name = "setuid?", required = 1, module = true) public static IRubyObject setuid_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isSetuid()); }
@JRubyMethod(name = "socket?", required = 1, module = true) public static IRubyObject socket_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isSocket()); }
@JRubyMethod(name = "blockdev?", required = 1, module = true) public static IRubyObject blockdev_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); FileResource file = fileResource(filename); return runtime.newBoolean(file.exists() && file.stat(runtime.getPosix()).isBlockDev()); }