@Override public String toString() { return file.toString(); }
@Override public String toString() { return file.toString(); }
@Override public String toString() { return file.toString(); }
private static RubyFixnum rmdirCommon(Ruby runtime, String path) { JRubyFile directory = getDirForRmdir(runtime, path); // at this point, only thing preventing delete should be non-emptiness if (runtime.getPosix().rmdir(directory.toString()) < 0) { throw runtime.newErrnoENOTEMPTYError(path); } return runtime.newFixnum(0); }
private static RubyFixnum rmdirCommon(Ruby runtime, String path) { JRubyFile directory = getDirForRmdir(runtime, path); // at this point, only thing preventing delete should be non-emptiness if (runtime.getPosix().rmdir(directory.toString()) < 0) { throw runtime.newErrnoENOTEMPTYError(path); } return runtime.newFixnum(0); }
private static IRubyObject rmdirCommon(Ruby runtime, String path) { JRubyFile directory = getDirForRmdir(runtime, path); // at this point, only thing preventing delete should be non-emptiness if (runtime.getPosix().rmdir(directory.toString()) < 0) { throw runtime.newErrnoENOTEMPTYError(path); } return runtime.newFixnum(0); }
private static IRubyObject rmdirCommon(Ruby runtime, String path) { JRubyFile directory = getDirForRmdir(runtime, path); // at this point, only thing preventing delete should be non-emptiness if (runtime.getPosix().rmdir(directory.toString()) < 0) { throw runtime.newErrnoENOTEMPTYError(path); } return runtime.newFixnum(0); }
@JRubyMethod(required = 2, meta = true) public static IRubyObject link(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) { Ruby runtime = context.runtime; String fromStr = file(from).toString(); String toStr = file(to).toString(); int ret = runtime.getPosix().link(fromStr, toStr); if (ret != 0) { if (runtime.getPosix().isNative()) { throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr)); } else { // In most cases, when there is an error during the call, // the POSIX handler throws an exception, but not in case // with pure Java POSIX layer (when native support is disabled), // so we deal with it like this: throw runtime.newErrnoEEXISTError(fromStr + " or " + toStr); } } return runtime.newFixnum(ret); }
@JRubyMethod(required = 1, meta = true) public static IRubyObject readlink(ThreadContext context, IRubyObject recv, IRubyObject path) { Ruby runtime = context.runtime; if (Platform.IS_WINDOWS) { // readlink is not available on Windows. See above and jruby/jruby#3287. // TODO: MRI does not implement readlink on Windows, but perhaps we could? throw runtime.newNotImplementedError("readlink"); } JRubyFile link = file(path); try { String realPath = runtime.getPosix().readlink(link.toString()); if (realPath == null) { throw runtime.newErrnoFromLastPOSIXErrno(); } return RubyString.newString(runtime, realPath, runtime.getEncodingService().getFileSystemEncoding()); } catch (IOException e) { throw runtime.newIOError(e.getMessage()); } }
@JRubyMethod(required = 1, meta = true) public static IRubyObject readlink(ThreadContext context, IRubyObject recv, IRubyObject path) { Ruby runtime = context.runtime; if (Platform.IS_WINDOWS) { // readlink is not available on Windows. See above and jruby/jruby#3287. // TODO: MRI does not implement readlink on Windows, but perhaps we could? throw runtime.newNotImplementedError("readlink"); } JRubyFile link = file(path); try { String realPath = runtime.getPosix().readlink(link.toString()); if (realPath == null) { throw runtime.newErrnoFromLastPOSIXErrno(); } return RubyString.newString(runtime, realPath, runtime.getEncodingService().getFileSystemEncoding()); } catch (IOException e) { throw runtime.newIOError(e.getMessage()); } }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject lchmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int count = 0; RubyInteger mode = args[0].convertToInteger(); for (int i = 1; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchmod(file.toString(), (int)mode.getLongValue())) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject lchmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int count = 0; RubyInteger mode = args[0].convertToInteger(); for (int i = 1; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchmod(file.toString(), (int) mode.getLongValue())) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject lchmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int count = 0; RubyInteger mode = args[0].convertToInteger(); for (int i = 1; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchmod(file.toString(), (int) mode.getLongValue())) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject lchmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int count = 0; RubyInteger mode = args[0].convertToInteger(); for (int i = 1; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchmod(file.toString(), (int)mode.getLongValue())) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 2, rest = true, meta = true) public static IRubyObject lchown(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int owner = !args[0].isNil() ? RubyNumeric.num2int(args[0]) : -1; int group = !args[1].isNil() ? RubyNumeric.num2int(args[1]) : -1; int count = 0; for (int i = 2; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchown(file.toString(), owner, group)) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 2, rest = true, meta = true) public static IRubyObject lchown(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int owner = !args[0].isNil() ? RubyNumeric.num2int(args[0]) : -1; int group = !args[1].isNil() ? RubyNumeric.num2int(args[1]) : -1; int count = 0; for (int i = 2; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchown(file.toString(), owner, group)) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 2, rest = true, meta = true) public static IRubyObject lchown(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int owner = !args[0].isNil() ? RubyNumeric.num2int(args[0]) : -1; int group = !args[1].isNil() ? RubyNumeric.num2int(args[1]) : -1; int count = 0; for (int i = 2; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchown(file.toString(), owner, group)) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 2, rest = true, meta = true) public static IRubyObject lchown(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int owner = !args[0].isNil() ? RubyNumeric.num2int(args[0]) : -1; int group = !args[1].isNil() ? RubyNumeric.num2int(args[1]) : -1; int count = 0; for (int i = 2; i < args.length; i++) { JRubyFile file = file(args[i]); if (0 != runtime.getPosix().lchown(file.toString(), owner, group)) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 2, rest = true, meta = true) public static IRubyObject chmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int count = 0; RubyInteger mode = args[0].convertToInteger(); for (int i = 1; i < args.length; i++) { JRubyFile filename = file(args[i]); if (!filename.exists()) { throw runtime.newErrnoENOENTError(filename.toString()); } if (0 != runtime.getPosix().chmod(filename.getAbsolutePath(), (int)mode.getLongValue())) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }
@JRubyMethod(required = 2, rest = true, meta = true) public static IRubyObject chmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; int count = 0; RubyInteger mode = args[0].convertToInteger(); for (int i = 1; i < args.length; i++) { JRubyFile filename = file(args[i]); if (!filename.exists()) { throw runtime.newErrnoENOENTError(filename.toString()); } if (0 != runtime.getPosix().chmod(filename.getAbsolutePath(), (int) mode.getLongValue())) { throw runtime.newErrnoFromLastPOSIXErrno(); } else { count++; } } return runtime.newFixnum(count); }