/** * 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 * @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; }
File parent = theFile.getParentFile(); if (parent != null && parent != theFile && !parent.exists()) { throw new FileNotFoundException(path);
File parent = theFile.getParentFile(); if (parent != null && parent != theFile && !parent.exists()) { throw new FileNotFoundException(path);
/** * 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 * @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; }
if (!(oldFile.exists() || isOldSymlink) || !newFile.getParentFile().exists()) { throw runtime.newErrnoENOENTError(oldNameJavaString + " or " + newNameJavaString);
if (!(oldFile.exists() || isOldSymlink) || !newFile.getParentFile().exists()) { throw runtime.newErrnoENOENTError(oldNameJavaString + " or " + newNameJavaString);
@JRubyMethod(required = 2, meta = true) public static IRubyObject rename(ThreadContext context, IRubyObject recv, IRubyObject oldName, IRubyObject newName) { Ruby runtime = context.runtime; RubyString oldNameString = get_path(context, oldName); RubyString newNameString = get_path(context, newName); String newNameJavaString = newNameString.getUnicodeValue(); String oldNameJavaString = oldNameString.getUnicodeValue(); JRubyFile oldFile = JRubyFile.create(runtime.getCurrentDirectory(), oldNameJavaString); JRubyFile newFile = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString); if (!oldFile.exists() || !newFile.getParentFile().exists()) { throw runtime.newErrnoENOENTError(oldNameJavaString + " or " + newNameJavaString); } JRubyFile dest = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString); if (oldFile.renameTo(dest)) { // rename is successful return RubyFixnum.zero(runtime); } // rename via Java API call wasn't successful, let's try some tricks, similar to MRI if (newFile.exists()) { runtime.getPosix().chmod(newNameJavaString, 0666); newFile.delete(); } if (oldFile.renameTo(dest)) { // try to rename one more time return RubyFixnum.zero(runtime); } throw runtime.newErrnoEACCESError(oldNameJavaString + " or " + newNameJavaString); }
@JRubyMethod(required = 2, meta = true) public static IRubyObject rename(ThreadContext context, IRubyObject recv, IRubyObject oldName, IRubyObject newName) { Ruby runtime = context.runtime; RubyString oldNameString = get_path(context, oldName); RubyString newNameString = get_path(context, newName); String newNameJavaString = newNameString.getUnicodeValue(); String oldNameJavaString = oldNameString.getUnicodeValue(); JRubyFile oldFile = JRubyFile.create(runtime.getCurrentDirectory(), oldNameJavaString); JRubyFile newFile = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString); if (!oldFile.exists() || !newFile.getParentFile().exists()) { throw runtime.newErrnoENOENTError(oldNameJavaString + " or " + newNameJavaString); } JRubyFile dest = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString); if (oldFile.renameTo(dest)) { // rename is successful return RubyFixnum.zero(runtime); } // rename via Java API call wasn't successful, let's try some tricks, similar to MRI if (newFile.exists()) { runtime.getPosix().chmod(newNameJavaString, 0666); newFile.delete(); } if (oldFile.renameTo(dest)) { // try to rename one more time return RubyFixnum.zero(runtime); } throw runtime.newErrnoEACCESError(oldNameJavaString + " or " + newNameJavaString); }
File parent = file.getParentFile(); if (parent != null && parent != file && !parent.exists()) { throw new ResourceException.NotFound(absolutePath());
File parent = file.getParentFile(); if (parent != null && parent != file && !parent.exists()) { throw new ResourceException.NotFound(absolutePath());