public Integer invoke(File f, VirtualChannel channel) throws IOException { return PosixAPI.get().stat(f.getPath()).mode(); } });
public Integer invoke(File f, VirtualChannel channel) throws IOException { return PosixAPI.get().stat(f.getPath()).mode(); } });
@Override public int mode(File file) { try { return PosixAPI.get().stat(file.getPath()).mode(); } catch (Throwable ex) { throw new NativeAccessException("Failed to get File mode. " + ex.getLocalizedMessage()); } }
@Override public boolean makeFileWritable(File file) { try { POSIX posix = PosixAPI.get(); String path = file.getAbsolutePath(); FileStat stat = posix.stat(path); return posix.chmod(path, stat.mode() | 0200) == 0; // u+w } catch (Throwable ex) { throw new NativeAccessException("Failed to make file writable. " + ex.getLocalizedMessage()); } }
private void setup(String filename, boolean lstat) { if (Platform.IS_WINDOWS && filename.length() == 2 && filename.charAt(1) == ':' && Character.isLetter(filename.charAt(0))) { filename += "/"; } file = JRubyFile.create(getRuntime().getCurrentDirectory(), filename); if (lstat) { stat = getRuntime().getPosix().lstat(file.getAbsolutePath()); } else { stat = getRuntime().getPosix().stat(file.getAbsolutePath()); } }
/** * Makes the given file writable by any means possible. */ @IgnoreJRERequirement private static void makeWritable(File f) { // try chmod. this becomes no-op if this is not Unix. try { Chmod chmod = new Chmod(); chmod.setProject(new Project()); chmod.setFile(f); chmod.setPerm("u+w"); chmod.execute(); } catch (BuildException e) { LOGGER.log(Level.INFO,"Failed to chmod "+f,e); } // also try JDK6-way of doing it. try { f.setWritable(true); } catch (NoSuchMethodError e) { // not JDK6 } try {// try libc chmod POSIX posix = PosixAPI.get(); String path = f.getAbsolutePath(); FileStat stat = posix.stat(path); posix.chmod(path, stat.mode()|0200); // u+w } catch (Throwable t) { LOGGER.log(Level.FINE,"Failed to chmod(2) "+f,t); } }
@JRubyMethod(name = "identical?", required = 2, module = true) public static IRubyObject identical_p(IRubyObject recv, IRubyObject filename1, IRubyObject filename2) { Ruby runtime = recv.getRuntime(); JRubyFile file1 = file(filename1); JRubyFile file2 = file(filename2); return runtime.newBoolean(file1.exists() && file2.exists() && runtime.getPosix().stat(file1.getAbsolutePath()).isIdentical(runtime.getPosix().stat(file2.getAbsolutePath()))); }
public static IRubyObject rowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isROwned()); }
@JRubyMethod(name = "executable_real?", required = 1, module = true) public static IRubyObject executable_real_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isExecutableReal()); }
@JRubyMethod(name = "setgid?", required = 1, module = true) public static IRubyObject setgid_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isSetgid()); }
@JRubyMethod(name = "socket?", required = 1, module = true) public static IRubyObject socket_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isSocket()); }
@JRubyMethod(name = "directory?", required = 1, module = true) public static IRubyObject directory_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isDirectory()); }
@JRubyMethod(name = "grpowned?", required = 1, module = true) public static IRubyObject grpowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isGroupOwned()); }
@JRubyMethod(name = "executable?", required = 1, module = true) public static IRubyObject executable_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isExecutable()); }
@JRubyMethod(name = "pipe?", required = 1, module = true) public static IRubyObject pipe_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isNamedPipe()); }
@JRubyMethod(name = "sticky?", required = 1, module = true) public static IRubyObject sticky_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isSticky()); }
@JRubyMethod(name = "blockdev?", required = 1, module = true) public static IRubyObject blockdev_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isBlockDev()); }
@JRubyMethod(name = "chardev?", required = 1, module = true) public static IRubyObject chardev_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isCharDev()); }
@JRubyMethod(name = "owned?", required = 1, module = true) public static IRubyObject owned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isOwned()); }
@JRubyMethod(name = "setuid?", required = 1, module = true) public static IRubyObject setuid_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isSetuid()); }