/** * Change permissions via NIO. */ private static void _chmod(File f, int mask) throws IOException { // TODO WindowsPosix actually does something here (WindowsLibC._wchmod); should we let it? // Anyway the existing calls already skip this method if on Windows. if (File.pathSeparatorChar==';') return; // noop if (Util.NATIVE_CHMOD_MODE) { PosixAPI.jnr().chmod(f.getAbsolutePath(), mask); } else { Files.setPosixFilePermissions(fileToPath(f), Util.modeToPermissions(mask)); } }
/** * @deprecated use {@link #jnr} and {@link POSIX#isNative} */ @Deprecated public boolean isNative() { return supportsNative(); }
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { f.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(f); try { props.store(os,"Credential store"); } finally { os.close(); } // try to protect this file from other users, if we can. PosixAPI.get().chmod(f.getAbsolutePath(),0600); return null; } });
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { f.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(f); try { props.store(os,"Credential store"); } finally { os.close(); } // try to protect this file from other users, if we can. PosixAPI.get().chmod(f.getAbsolutePath(),0600); return null; } });
public Integer invoke(File f, VirtualChannel channel) throws IOException { return PosixAPI.get().stat(f.getPath()).mode(); } });
/** * Gets the mode of a file/directory, if appropriate. Only includes read, write, and * execute permissions for the owner, group, and others, i.e. the max return value * is 0777. Consider using {@link Files#getPosixFilePermissions} instead if you only * care about access permissions. * <p>If the file is symlink, the mode is that of the link target, not the link itself. * @return a file mode, or -1 if not on Unix * @throws PosixException if the file could not be statted, e.g. broken symlink */ public static int mode(File f) throws PosixException { if(Functions.isWindows()) return -1; try { if (Util.NATIVE_CHMOD_MODE) { return PosixAPI.jnr().stat(f.getPath()).mode(); } else { return Util.permissionsToMode(Files.getPosixFilePermissions(fileToPath(f))); } } catch (IOException cause) { PosixException e = new PosixException("Unable to get file permissions", null); e.initCause(cause); throw e; } }
/** * @deprecated use {@link #jnr} and {@link POSIX#isNative} */ @Deprecated public boolean isNative() { return supportsNative(); }
public Integer invoke(File f, VirtualChannel channel) throws IOException { return PosixAPI.get().stat(f.getPath()).mode(); } });
/** * Run chmod via jnr-posix */ private static void _chmod(File f, int mask) throws IOException { // TODO WindowsPosix actually does something here (WindowsLibC._wchmod); should we let it? // Anyway the existing calls already skip this method if on Windows. if (File.pathSeparatorChar==';') return; // noop PosixAPI.jnr().chmod(f.getAbsolutePath(),mask); }
@IgnoreJRERequirement private void process(File f) { if (f.isFile()) { if(Functions.isMustangOrAbove()) f.setExecutable(true, false); else { try { GNUCLibrary.LIBC.chmod(f.getAbsolutePath(),0755); } catch (LinkageError e) { // if JNA is unavailable, fall back. // we still prefer to try JNA first as PosixAPI supports even smaller platforms. PosixAPI.get().chmod(f.getAbsolutePath(),0755); } } } else { File[] kids = f.listFiles(); if (kids != null) { for (File kid : kids) { process(kid); } } } } }
/** * Gets the mode of a file/directory, if appropriate. * @return a file mode, or -1 if not on Unix * @throws PosixException if the file could not be statted, e.g. broken symlink */ public static int mode(File f) throws PosixException { if(Functions.isWindows()) return -1; return PosixAPI.jnr().stat(f.getPath()).mode(); }
@IgnoreJRERequirement private void process(File f) { if (f.isFile()) { if(Functions.isMustangOrAbove()) f.setExecutable(true, false); else { try { GNUCLibrary.LIBC.chmod(f.getAbsolutePath(),0755); } catch (LinkageError e) { // if JNA is unavailable, fall back. // we still prefer to try JNA first as PosixAPI supports even smaller platforms. PosixAPI.get().chmod(f.getAbsolutePath(),0755); } } } else { File[] kids = f.listFiles(); if (kids != null) { for (File kid : kids) { process(kid); } } } } }
/** * Makes the given file writable by any means possible. */ private static void makeWritable(@Nonnull File f) { if (f.setWritable(true)) { return; } // TODO do we still need to try anything else? // 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); } try {// try libc chmod POSIX posix = PosixAPI.jnr(); 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); } }
private void process(final File file) { assert file != null; if (file.isFile()) { if (Functions.isMustangOrAbove()) { if (!file.setExecutable(true, false)) { log.error("Failed to chmod: {}", file); } } else { try { GNUCLibrary.LIBC.chmod(file.getAbsolutePath(), mode); } catch (LinkageError e) { // if JNA is unavailable, fall back PosixAPI.get().chmod(file.getAbsolutePath(), mode); } } } else { File[] children = file.listFiles(); if (children != null) { for (File child : children) { process(child); } } } } }
POSIX posix = PosixAPI.jnr(); if (posix.isNative()) {
r = PosixAPI.get().symlink(targetPath,symlinkFile.getAbsolutePath());
r = PosixAPI.get().symlink(targetPath,symlinkFile.getAbsolutePath());
return PosixAPI.get().readlink(filename);
return PosixAPI.get().readlink(filename);
/** * 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); } }