@Override public boolean isDirectory() { return file.isDirectory(); }
@Override public boolean isDirectory() { return file.isDirectory(); }
@Override public boolean isDirectory() { return file.isDirectory(); }
JRubyFile theFile = JRubyFile.create(cwd,path); if (theFile.isDirectory() && flags.isWritable()) { throw new DirectoryAsFileException();
JRubyFile theFile = JRubyFile.create(cwd,path); if (theFile.isDirectory() && flags.isWritable()) { throw new DirectoryAsFileException();
JRubyFile theFile = JRubyFile.create(cwd,path); if (theFile.isDirectory() && modes.isWritable()) { throw runtime.newErrnoEISDirError(path);
JRubyFile theFile = JRubyFile.create(cwd,path); if (theFile.isDirectory() && modes.isWritable()) throw new DirectoryAsFileException();
JRubyFile theFile = JRubyFile.create(cwd,path); if (theFile.isDirectory() && modes.isWritable()) throw new DirectoryAsFileException();
JRubyFile theFile = JRubyFile.create(cwd,path); if (theFile.isDirectory() && modes.isWritable()) { throw runtime.newErrnoEISDirError(path);
/** Returns a Java <code>File</code> object for the specified path. If * <code>path</code> is not a directory, throws <code>IOError</code>. * * @param path path for which to return the <code>File</code> object. * @param mustExist is true the directory must exist. If false it must not. * @throws IOError if <code>path</code> is not a directory. */ protected static JRubyFile getDir(final Ruby runtime, final String path, final boolean mustExist) { String dir = dirFromPath(path, runtime); JRubyFile result = JRubyFile.create(runtime.getCurrentDirectory(), dir); if (mustExist && !result.exists()) { throw runtime.newErrnoENOENTError(dir); } boolean isDirectory = result.isDirectory(); if (mustExist && !isDirectory) { throw runtime.newErrnoENOTDIRError(path); } if (!mustExist && isDirectory) { throw runtime.newErrnoEEXISTError(dir); } return result; }
/** Returns a Java <code>File</code> object for the specified path. If * <code>path</code> is not a directory, throws <code>IOError</code>. * * @param path path for which to return the <code>File</code> object. * @param mustExist is true the directory must exist. If false it must not. * @throws IOError if <code>path</code> is not a directory. */ protected static JRubyFile getDir(final Ruby runtime, final String path, final boolean mustExist) { String dir = dirFromPath(path, runtime); JRubyFile result = JRubyFile.create(runtime.getCurrentDirectory(), dir); if (mustExist && !result.exists()) { throw runtime.newErrnoENOENTError(dir); } boolean isDirectory = result.isDirectory(); if (mustExist && !isDirectory) { throw runtime.newErrnoENOTDIRError(path); } if (!mustExist && isDirectory) { throw runtime.newErrnoEEXISTError(dir); } return result; }
@JRubyMethod(name = "zero?", required = 1, module = true) public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile)) { filename = get_path(context, filename); } ZipEntry entry = file_in_archive(filename); if (entry != null) { return runtime.newBoolean(entry.getSize() == 0L); } JRubyFile file = file(filename); if (file.exists()) { if (file.isDirectory()) { // MRI behavior, enforced by RubySpecs. return runtime.newBoolean(Platform.IS_WINDOWS); } else { return runtime.newBoolean(file.length() == 0L); } } else { return runtime.getFalse(); } }
@JRubyMethod(name = {"unlink", "delete"}, rest = true, meta = true) public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; for (int i = 0; i < args.length; i++) { RubyString filename = get_path(context, args[i]); JRubyFile lToDelete = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue()); boolean isSymlink = RubyFileTest.symlink_p(recv, filename).isTrue(); // Broken symlinks considered by exists() as non-existing, // so we need to check for symlinks explicitly. if (!lToDelete.exists() && !isSymlink) { throw runtime.newErrnoENOENTError(filename.getUnicodeValue()); } if (lToDelete.isDirectory() && !isSymlink) { throw runtime.newErrnoEPERMError(filename.getUnicodeValue()); } if (!lToDelete.delete()) { throw runtime.newErrnoEACCESError(filename.getUnicodeValue()); } } return runtime.newFixnum(args.length); }
@JRubyMethod(name = {"unlink", "delete"}, rest = true, meta = true) public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; for (int i = 0; i < args.length; i++) { RubyString filename = get_path(context, args[i]); JRubyFile lToDelete = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue()); boolean isSymlink = RubyFileTest.symlink_p(recv, filename).isTrue(); // Broken symlinks considered by exists() as non-existing, // so we need to check for symlinks explicitly. if (!lToDelete.exists() && !isSymlink) { throw runtime.newErrnoENOENTError(filename.getUnicodeValue()); } if (lToDelete.isDirectory() && !isSymlink) { throw runtime.newErrnoEPERMError(filename.getUnicodeValue()); } if (!lToDelete.delete()) { throw runtime.newErrnoEACCESError(filename.getUnicodeValue()); } } return runtime.newFixnum(args.length); }
@JRubyMethod(rest = true, meta = true) public static IRubyObject delete(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; for (int i = 0; i < args.length; i++) { RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i])); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue()); // Broken symlinks considered by exists() as non-existing, // so we need to check for symlinks explicitly. if (!file.exists() && !isSymlink(context, file)) { throw runtime.newErrnoENOENTError(filename.getUnicodeValue()); } if (file.isDirectory() && !isSymlink(context, file)) { throw runtime.newErrnoEISDirError(filename.getUnicodeValue()); } if (!file.delete()) { throw runtime.newErrnoEACCESError(filename.getUnicodeValue()); } } return runtime.newFixnum(args.length); }
@JRubyMethod(rest = true, meta = true) public static IRubyObject delete(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; for (int i = 0; i < args.length; i++) { RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i])); JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue()); // Broken symlinks considered by exists() as non-existing, // so we need to check for symlinks explicitly. if (!file.exists() && !isSymlink(context, file)) { throw runtime.newErrnoENOENTError(filename.getUnicodeValue()); } if (file.isDirectory() && !isSymlink(context, file)) { throw runtime.newErrnoEISDirError(filename.getUnicodeValue()); } if (!file.delete()) { throw runtime.newErrnoEACCESError(filename.getUnicodeValue()); } } return runtime.newFixnum(args.length); }
@JRubyMethod(rest = true, meta = true) public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; POSIX posix = runtime.getPosix(); if (!posix.isNative() || Platform.IS_WINDOWS) return delete(context, recv, args); for (int i = 0; i < args.length; i++) { RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i])); JRubyFile lToDelete = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue()); boolean isSymlink = RubyFileTest.symlink_p(recv, filename).isTrue(); // Broken symlinks considered by exists() as non-existing, // so we need to check for symlinks explicitly. if (!lToDelete.exists() && !isSymlink) { throw runtime.newErrnoENOENTError(filename.getUnicodeValue()); } if (lToDelete.isDirectory() && !isSymlink) { throw runtime.newErrnoEPERMError(filename.getUnicodeValue()); } if (posix.unlink(lToDelete.getAbsolutePath()) < 0) { throw runtime.newErrnoFromInt(posix.errno()); } } return runtime.newFixnum(args.length); }
@JRubyMethod(rest = true, meta = true) public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; POSIX posix = runtime.getPosix(); if (!posix.isNative() || Platform.IS_WINDOWS) return delete(context, recv, args); for (int i = 0; i < args.length; i++) { RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i])); JRubyFile lToDelete = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue()); boolean isSymlink = RubyFileTest.symlink_p(recv, filename).isTrue(); // Broken symlinks considered by exists() as non-existing, // so we need to check for symlinks explicitly. if (!lToDelete.exists() && !isSymlink) { throw runtime.newErrnoENOENTError(filename.getUnicodeValue()); } if (lToDelete.isDirectory() && !isSymlink) { throw runtime.newErrnoEPERMError(filename.getUnicodeValue()); } if (posix.unlink(lToDelete.getAbsolutePath()) < 0) { throw runtime.newErrnoFromInt(posix.errno()); } } return runtime.newFixnum(args.length); }
if (file.isDirectory()) { throw new ResourceException.FileIsDirectory(absolutePath());
if (file.isDirectory()) { throw new ResourceException.FileIsDirectory(absolutePath());