List of usage examples for java.nio.file.attribute PosixFilePermission OWNER_EXECUTE
PosixFilePermission OWNER_EXECUTE
To view the source code for java.nio.file.attribute PosixFilePermission OWNER_EXECUTE.
Click Source Link
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = Paths.get("home/docs/users.txt"); removePermission(path, PosixFilePermission.OWNER_EXECUTE); }
From source file:Helper.Helper.java
public static Set<PosixFilePermission> intToSetPosix(int chmod) { Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); int other = chmod % 10, group = (chmod / 10) % 10, owner = (chmod / 100) % 10; if (owner >= 4) { perms.add(PosixFilePermission.OWNER_READ); owner -= 4;//from w w w.j a v a2s. c o m } if (owner >= 2) { perms.add(PosixFilePermission.OWNER_WRITE); owner -= 2; } if (owner >= 1) { perms.add(PosixFilePermission.OWNER_EXECUTE); owner -= 1; } if (group >= 4) { perms.add(PosixFilePermission.GROUP_READ); group -= 4; } if (group >= 2) { perms.add(PosixFilePermission.GROUP_WRITE); group -= 2; } if (group >= 1) { perms.add(PosixFilePermission.GROUP_EXECUTE); group -= 1; } if (other >= 4) { perms.add(PosixFilePermission.OTHERS_READ); other -= 4; } if (other >= 2) { perms.add(PosixFilePermission.OTHERS_WRITE); other -= 2; } if (other >= 1) { perms.add(PosixFilePermission.OTHERS_EXECUTE); other -= 1; } return perms; }
From source file:org.esa.s2tbx.dataio.openjpeg.OpenJPEGActivator.java
private static void setExecutablePermissions(Path executablePathName) { if (IS_OS_UNIX) { Set<PosixFilePermission> permissions = new HashSet<>(Arrays.asList(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)); try {/*from ww w .java 2 s . c o m*/ Files.setPosixFilePermissions(executablePathName, permissions); } catch (IOException e) { // can't set the permissions for this file, eg. the file was installed as root // send a warning message, user will have to do that by hand. SystemUtils.LOG .severe("Can't set execution permissions for executable " + executablePathName.toString() + ". If required, please ask an authorised user to make the file executable."); } } }
From source file:it.sonarlint.cli.tools.CommandExecutor.java
public int execute(String[] args, @Nullable Path workingDir, Map<String, String> addEnv) throws IOException { if (!Files.isExecutable(file)) { Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_EXECUTE); Files.setPosixFilePermissions(file, perms); }//from www . j av a 2s . c om ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT); CommandLine cmd = new CommandLine(file.toFile()); cmd.addArguments(args); DefaultExecutor exec = new DefaultExecutor(); exec.setWatchdog(watchdog); exec.setStreamHandler(createStreamHandler()); exec.setExitValues(null); if (workingDir != null) { exec.setWorkingDirectory(workingDir.toFile()); } in.close(); LOG.info("Executing: {}", cmd.toString()); Map<String, String> env = new HashMap<>(System.getenv()); env.putAll(addEnv); return exec.execute(cmd, env); }
From source file:de.tudarmstadt.ukp.dkpro.discourse.pdtbparser.PDTBParserWrapper.java
public PDTBParserWrapper() throws IOException { tempDirectory = Files.createTempDirectory("temp_pdtb"); // FileUtils.copyFileToDirectory(); File tempDir = tempDirectory.toFile(); File tmpFile = File.createTempFile("tmp_pdtb", ".zip"); InputStream stream = getClass().getClassLoader().getResourceAsStream("pdtb-parser-v120415.zip"); FileUtils.copyInputStreamToFile(stream, tmpFile); ZipFile zipFile;/*from w w w . ja va 2 s . c o m*/ try { zipFile = new ZipFile(tmpFile); zipFile.extractAll(tempDir.getAbsolutePath()); } catch (ZipException e) { throw new IOException(e); } // delete temp file FileUtils.forceDelete(tmpFile); String folderPrefix = "/pdtb-parser-v120415/src"; String srcDir = tempDir.getCanonicalPath() + folderPrefix; // copy rewritten rb files copyFiles(new File(srcDir), "article.rb", "parser.rb"); Files.walkFileTree(tempDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Set<PosixFilePermission> permissions = new HashSet<>(); permissions.add(PosixFilePermission.OWNER_EXECUTE); permissions.add(PosixFilePermission.GROUP_EXECUTE); permissions.add(PosixFilePermission.OTHERS_EXECUTE); permissions.add(PosixFilePermission.OWNER_READ); permissions.add(PosixFilePermission.GROUP_READ); permissions.add(PosixFilePermission.OTHERS_READ); Files.setPosixFilePermissions(file, permissions); return super.visitFile(file, attrs); } }); parserRubyScript = srcDir + "/parser.rb"; System.out.println(parserRubyScript); }
From source file:com.sonar.scanner.api.it.tools.CommandExecutor.java
public int execute(String[] args, Map<String, String> env, @Nullable Path workingDir) throws IOException { if (!Files.isExecutable(file)) { Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_EXECUTE); Files.setPosixFilePermissions(file, perms); }//from w w w . j a va2 s. co m watchdog = new ExecuteWatchdog(TIMEOUT); CommandLine cmd = new CommandLine(file.toFile()); cmd.addArguments(args, false); DefaultExecutor exec = new DefaultExecutor(); exec.setWatchdog(watchdog); exec.setStreamHandler(createStreamHandler()); exec.setExitValues(null); if (workingDir != null) { exec.setWorkingDirectory(workingDir.toFile()); } in.close(); LOG.info("Executing: {}", cmd.toString()); return exec.execute(cmd, env); }
From source file:its.tools.CommandExecutor.java
public void execute(String[] args, @Nullable Path workingDir) throws IOException { if (!Files.isExecutable(file)) { Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_EXECUTE); Files.setPosixFilePermissions(file, perms); }// w w w. j av a2 s .c om watchdog = new ExecuteWatchdog(TIMEOUT); CommandLine cmd = new CommandLine(file.toFile()); cmd.addArguments(args); DefaultExecutor exec = new DefaultExecutor(); exec.setWatchdog(watchdog); exec.setStreamHandler(createStreamHandler()); exec.setExitValues(null); if (workingDir != null) { exec.setWorkingDirectory(workingDir.toFile()); } in.close(); LOG.info("Executing: {}", cmd.toString()); exec.execute(cmd, new ResultHander()); }
From source file:org.roda.core.plugins.PluginReportContentTest.java
@BeforeClass public static void setUp() throws Exception { basePath = TestsHelper.createBaseTempDir(PluginReportContentTest.class, true, PosixFilePermissions.asFileAttribute(new HashSet<>(Arrays.asList(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)))); boolean deploySolr = true; boolean deployLdap = true; boolean deployFolderMonitor = true; boolean deployOrchestrator = true; boolean deployPluginManager = true; boolean deployDefaultResources = false; RodaCoreFactory.instantiateTest(deploySolr, deployLdap, deployFolderMonitor, deployOrchestrator, deployPluginManager, deployDefaultResources); model = RodaCoreFactory.getModelService(); index = RodaCoreFactory.getIndexService(); LOGGER.debug("Running index tests under storage {}", basePath); }
From source file:com.streamsets.pipeline.stage.destination.hdfs.metadataexecutor.HdfsMetadataExecutorIT.java
@BeforeClass public static void setUpClass() throws Exception { // Conf dir/* w ww. ja va 2 s .co m*/ new File(confDir).mkdirs(); //setting some dummy kerberos settings to be able to test a mis-setting System.setProperty("java.security.krb5.realm", "foo"); System.setProperty("java.security.krb5.kdc", "localhost:0"); File minidfsDir = new File(baseDir, "minidfs").getAbsoluteFile(); if (!minidfsDir.exists()) { Assert.assertTrue(minidfsDir.mkdirs()); } Set<PosixFilePermission> set = new HashSet<>(); set.add(PosixFilePermission.OWNER_EXECUTE); set.add(PosixFilePermission.OWNER_READ); set.add(PosixFilePermission.OWNER_WRITE); set.add(PosixFilePermission.OTHERS_READ); java.nio.file.Files.setPosixFilePermissions(minidfsDir.toPath(), set); System.setProperty(MiniDFSCluster.PROP_TEST_BUILD_DATA, minidfsDir.getPath()); Configuration conf = new HdfsConfiguration(); conf.set("hadoop.proxyuser." + System.getProperty("user.name") + ".hosts", "*"); conf.set("hadoop.proxyuser." + System.getProperty("user.name") + ".groups", "*"); conf.set("dfs.namenode.acls.enabled", "true"); fooUgi = UserGroupInformation.createUserForTesting("foo", new String[] { "all" }); EditLogFileOutputStream.setShouldSkipFsyncForTesting(true); FileSystem.closeAll(); miniDFS = new MiniDFSCluster.Builder(conf).build(); miniDFS.getFileSystem().setPermission(new Path("/"), FsPermission.createImmutable((short) 0777)); fs = miniDFS.getFileSystem(); writeConfiguration(miniDFS.getConfiguration(0), confDir + "core-site.xml"); writeConfiguration(miniDFS.getConfiguration(0), confDir + "hdfs-site.xml"); }
From source file:net.spinetrak.rpitft.command.Command.java
private String init(final String script_) { final String VAR_TMP = "/var/tmp"; InputStream scriptIn = null;//from w ww . ja v a 2s . c om OutputStream scriptOut = null; final File script = new File(VAR_TMP + script_); final String dir = script.getParent(); if (null != dir) { if (!new File(dir).mkdirs()) { LOGGER.error("Unable to create dirs for " + dir); } } try { scriptIn = Command.class.getResourceAsStream(script_); scriptOut = new FileOutputStream(script); IOUtils.copy(scriptIn, scriptOut); final Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_EXECUTE); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.GROUP_WRITE); Files.setPosixFilePermissions(Paths.get(script.getAbsolutePath()), perms); } catch (final IOException ex_) { LOGGER.error(ex_.getMessage()); } finally { if (scriptIn != null) { try { scriptIn.close(); } catch (final IOException ex_) { LOGGER.error(ex_.getMessage()); } } if (scriptOut != null) { try { scriptOut.close(); } catch (final IOException ex_) { LOGGER.error(ex_.getMessage()); } } } return script.getAbsolutePath(); }