@JRubyMethod(name = "directory?") public RubyBoolean directory_p() { return getRuntime().newBoolean(stat.isDirectory()); }
@JRubyMethod(name = "directory?") public RubyBoolean directory_p() { return getRuntime().newBoolean(stat.isDirectory()); }
if (!executableOnly || (!stat.isDirectory() && stat.isExecutable())) return filename; } catch (Throwable t) {}
if (!executableOnly || (!stat.isDirectory() && stat.isExecutable())) return filename; } catch (Throwable t) {}
if (!executableOnly || (!stat.isDirectory() && stat.isExecutable())) return filename; } catch (Throwable t) {}
if (!executableOnly || (!stat.isDirectory() && stat.isExecutable())) return filename; } catch (Throwable t) {}
@JRubyMethod(name = "directory?") public RubyBoolean directory_p() { checkInitialized(); return getRuntime().newBoolean(stat.isDirectory()); }
@JRubyMethod(name = "directory?") public RubyBoolean directory_p() { checkInitialized(); return getRuntime().newBoolean(stat.isDirectory()); }
/** * Similar to getDir, but performs different checks to match rmdir behavior. * @param runtime * @param path * @return */ protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) { String dir = dirFromPath(path, runtime); JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir); // Order is important here...File.exists() will return false if the parent // dir can't be read, so we check permissions first // no permission File parentFile = directory.getParentFile(); if (parentFile.exists() && ! parentFile.canWrite()) { throw runtime.newErrnoEACCESError(path); } // Since we transcode we depend on posix to lookup stat stuff since // java.io.File does not seem to cut it. A failed stat will throw ENOENT. FileStat stat = runtime.getPosix().stat(directory.toString()); // is not directory if (!stat.isDirectory()) throw runtime.newErrnoENOTDIRError(path); return directory; }
/** * Similar to getDir, but performs different checks to match rmdir behavior. * @param runtime * @param path * @param mustExist * @return */ protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) { String dir = dirFromPath(path, runtime); JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir); // Order is important here...File.exists() will return false if the parent // dir can't be read, so we check permissions first // no permission if (directory.getParentFile().exists() && !directory.getParentFile().canWrite()) { throw runtime.newErrnoEACCESError(path); } // Since we transcode we depend on posix to lookup stat stuff since // java.io.File does not seem to cut it. A failed stat will throw ENOENT. FileStat stat = runtime.getPosix().stat(directory.toString()); // is not directory if (!stat.isDirectory()) throw runtime.newErrnoENOTDIRError(path); return directory; }
/** * Similar to getDir, but performs different checks to match rmdir behavior. * @param runtime * @param path * @return */ protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) { String dir = dirFromPath(path, runtime); JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir); // Order is important here...File.exists() will return false if the parent // dir can't be read, so we check permissions first // no permission File parentFile = directory.getParentFile(); if (parentFile.exists() && ! parentFile.canWrite()) { throw runtime.newErrnoEACCESError(path); } // Since we transcode we depend on posix to lookup stat stuff since // java.io.File does not seem to cut it. A failed stat will throw ENOENT. FileStat stat = runtime.getPosix().stat(directory.toString()); // is not directory if (!stat.isDirectory()) throw runtime.newErrnoENOTDIRError(path); return directory; }
/** * Similar to getDir, but performs different checks to match rmdir behavior. * @param runtime * @param path * @param mustExist * @return */ protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) { String dir = dirFromPath(path, runtime); JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir); // Order is important here...File.exists() will return false if the parent // dir can't be read, so we check permissions first // no permission if (directory.getParentFile().exists() && !directory.getParentFile().canWrite()) { throw runtime.newErrnoEACCESError(path); } // Since we transcode we depend on posix to lookup stat stuff since // java.io.File does not seem to cut it. A failed stat will throw ENOENT. FileStat stat = runtime.getPosix().stat(directory.toString()); // is not directory if (!stat.isDirectory()) throw runtime.newErrnoENOTDIRError(path); return directory; }
@JRubyMethod(name = {"empty?", "zero?"}, required = 1, module = true) public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; FileResource resource = fileResource(context, filename); // FIXME: Ultimately we should return a valid stat() from this but without massive NUL coverage // this is less risky. if (resource.isNull()) return runtime.newBoolean(true); FileStat stat = resource.stat(); if (stat == null) return runtime.getFalse(); // MRI behavior, enforced by RubySpecs. if (stat.isDirectory()) return runtime.newBoolean(Platform.IS_WINDOWS); return runtime.newBoolean(stat.st_size() == 0L); }
@JRubyMethod(name = {"empty?", "zero?"}, required = 1, module = true) public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; FileResource resource = fileResource(context, filename); // FIXME: Ultimately we should return a valid stat() from this but without massive NUL coverage // this is less risky. if (resource.isNull()) return runtime.newBoolean(true); FileStat stat = resource.stat(); if (stat == null) return runtime.getFalse(); // MRI behavior, enforced by RubySpecs. if (stat.isDirectory()) return runtime.newBoolean(Platform.IS_WINDOWS); return runtime.newBoolean(stat.st_size() == 0L); }
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); } } ZipEntry entry = file_in_archive(filename); if (entry != null) { return entry.isDirectory() ? runtime.getTrue() : runtime.getFalse(); } JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isDirectory()); }