newFile.delete();
newFile.delete();
@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(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); }
@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); }