/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
@Override String[] linkCount(File file) throws IOException { String[] buf = new String[getLinkCountCommand.length]; System.arraycopy(getLinkCountCommand, 0, buf, 0, getLinkCountCommand.length); buf[getLinkCountCommand.length - 1] = FileUtil.makeShellPath(file, true); return buf; } }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @param makeCanonicalPath * Whether to make canonical path for the file passed * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file, boolean makeCanonicalPath) throws IOException { if (makeCanonicalPath) { return makeShellPath(file.getCanonicalPath()); } else { return makeShellPath(file.toString()); } }
/** * Convert a os-native filename to a path that works for the shell * and avoids script injection attacks. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeSecureShellPath(File file) throws IOException { if (Shell.WINDOWS) { // Currently it is never called, but it might be helpful in the future. throw new UnsupportedOperationException("Not implemented for Windows"); } else { return makeShellPath(file, false).replace("'", "'\\''"); } }
/** * Use the command chmod to set permission. */ @Override public void setPermission(Path p, FsPermission permission) throws IOException { if (NativeIO.isAvailable()) { NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(), permission.toShort()); } else { String perm = String.format("%04o", permission.toShort()); Shell.execCommand(Shell.getSetPermissionCommand(perm, false, FileUtil.makeShellPath(pathToFile(p), true))); } }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
/** * Convert a os-native filename to a path that works for the shell. * @param file The filename to convert * @return The unix pathname * @throws IOException on windows, there can be problems with the subprocess */ public static String makeShellPath(File file) throws IOException { return makeShellPath(file, false); }
@Override String[] linkOne(File file, File linkName) throws IOException { String[] buf = hardLinkCommand.get(); //unix wants argument order: "ln <existing> <new>" buf[buf.length-2] = FileUtil.makeShellPath(file, true); buf[buf.length-1] = FileUtil.makeShellPath(linkName, true); return buf; }
@Override String[] linkCount(File file) throws IOException { String[] buf = new String[getLinkCountCommand.length]; System.arraycopy(getLinkCountCommand, 0, buf, 0, getLinkCountCommand.length); buf[getLinkCountCommand.length - 1] = FileUtil.makeShellPath(file, true); return buf; } }
@Override String[] linkCount(File file) throws IOException { String[] buf = new String[getLinkCountCommand.length]; System.arraycopy(getLinkCountCommand, 0, buf, 0, getLinkCountCommand.length); buf[getLinkCountCommand.length - 1] = FileUtil.makeShellPath(file, true); return buf; } }
@Override String[] linkCount(File file) throws IOException { String[] buf = new String[getLinkCountCommand.length]; System.arraycopy(getLinkCountCommand, 0, buf, 0, getLinkCountCommand.length); buf[getLinkCountCommand.length - 1] = FileUtil.makeShellPath(file, true); return buf; } }
@Override String[] linkCount(File file) throws IOException { String[] buf = new String[getLinkCountCommand.length]; System.arraycopy(getLinkCountCommand, 0, buf, 0, getLinkCountCommand.length); buf[getLinkCountCommand.length - 1] = FileUtil.makeShellPath(file, true); return buf; } }
@Override String[] linkCount(File file) throws IOException { String[] buf = getLinkCountCommand.get(); buf[buf.length - 1] = FileUtil.makeShellPath(file, true); return buf; }
public static String execCommand(File f,String...cmd) throws IOException{ String[] args=new String[cmd.length+1]; System.arraycopy(cmd, 0, args, 0, cmd.length); args[cmd.length]=FileUtil.makeShellPath(f, true); String output=Shell.execCommand(args); return output; }
public static String execCommand(File f,String...cmd) throws IOException{ String[] args=new String[cmd.length+1]; System.arraycopy(cmd, 0, args, 0, cmd.length); args[cmd.length]=FileUtil.makeShellPath(f, true); String output=Shell.execCommand(args); return output; }
public static List<String> captureOutAndErrorTee(List<String> setup, List<String> cmd, File stdoutFilename, File stderrFilename, long tailLength) throws IOException { String stdout = FileUtil.makeShellPath(stdoutFilename); List<String> result = new ArrayList<String>(3); result.add(bashCommand); result.add("-c"); StringBuilder mergedCmd = new StringBuilder(); mergedCmd.append(addCommand(cmd, true)); mergedCmd.append(" 2>&1 | tee ").append(stdout); result.add(mergedCmd.toString()); return result; }