List of usage examples for java.io File setExecutable
public boolean setExecutable(boolean executable, boolean ownerOnly)
From source file:com.codesourcery.internal.installer.InstallManager.java
/** * Copies the installer to a location.//from w w w . j a v a 2 s .co m * * @param location Destination location * @param monitor Progress monitor * @throws CoreException on failure */ private void copyInstaller(IPath destinationLocation, IProgressMonitor monitor) throws CoreException { try { File uninstallDirectory = destinationLocation.toFile(); if (!uninstallDirectory.exists()) { uninstallDirectory.mkdirs(); } String[] uninstallFiles = getInstallDescription().getUninstallFiles(); if (uninstallFiles != null) { for (String uninstallFile : uninstallFiles) { String destinationFileName = uninstallFile; String srcFileName = uninstallFile; // Parse file name for ":" if renaming of destination file is desired. if (uninstallFile.contains(":")) { srcFileName = uninstallFile.substring(0, uninstallFile.indexOf(":")); destinationFileName = uninstallFile.substring(uninstallFile.indexOf(":") + 1); } IPath destPath = destinationLocation.append(destinationFileName); File srcFile = Installer.getDefault().getInstallFile(srcFileName); if (srcFile.exists()) { File destFile = destPath.toFile(); if (srcFile.isDirectory()) { FileUtils.copyDirectory(srcFile, destFile); } else { FileUtils.copyFile(srcFile, destFile); } // Set permissions destFile.setExecutable(srcFile.canExecute(), false); destFile.setReadable(srcFile.canRead(), false); destFile.setWritable(srcFile.canWrite(), false); } } } } catch (Exception e) { Installer.log( "Failed to copy installer. This could be because you are running from the Eclipse workbench and the exported RCP binary files are not available."); } }
From source file:org.apache.geode.internal.cache.BackupDUnitTest.java
private long setBackupFiles(final VM vm) { SerializableCallable setUserBackups = new SerializableCallable("set user backups") { public Object call() { final int pid = DUnitEnv.get().getPid(); File vmdir = new File("userbackup_" + pid); File test1 = new File(vmdir, "test1"); File test2 = new File(test1, "test2"); File mytext = new File(test2, "my.txt"); final ArrayList<File> backuplist = new ArrayList<>(); test2.mkdirs();/*from www .j av a2 s . co m*/ PrintStream ps = null; try { ps = new PrintStream(mytext); } catch (FileNotFoundException e) { fail(e.getMessage()); } ps.println(pid); ps.close(); mytext.setExecutable(true, true); long lastModified = mytext.lastModified(); backuplist.add(test2); Cache cache = getCache(); GemFireCacheImpl gfci = (GemFireCacheImpl) cache; gfci.setBackupFiles(backuplist); return lastModified; } }; return (long) vm.invoke(setUserBackups); }
From source file:org.apache.flink.runtime.blob.BlobServerPutTest.java
/** * Uploads a byte array to a server which cannot create incoming files via the {@link * BlobServer}. File transfers should fail. * * @param jobId//ww w .j ava 2 s .c o m * job id * @param blobType * whether the BLOB should become permanent or transient */ private void testPutBufferFailsIncoming(@Nullable final JobID jobId, BlobKey.BlobType blobType) throws IOException { assumeTrue(!OperatingSystem.isWindows()); //setWritable doesn't work on Windows. final Configuration config = new Configuration(); config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporaryFolder.newFolder().getAbsolutePath()); File tempFileDir = null; try (BlobServer server = new BlobServer(config, new VoidBlobStore())) { server.start(); // make sure the blob server cannot create any files in its storage dir tempFileDir = server.createTemporaryFilename().getParentFile(); assertTrue(tempFileDir.setExecutable(true, false)); assertTrue(tempFileDir.setReadable(true, false)); assertTrue(tempFileDir.setWritable(false, false)); byte[] data = new byte[2000000]; rnd.nextBytes(data); // upload the file to the server directly exception.expect(IOException.class); exception.expectMessage(" (Permission denied)"); try { put(server, jobId, data, blobType); } finally { File storageDir = tempFileDir.getParentFile(); // only the incoming directory should exist (no job directory!) assertArrayEquals(new String[] { "incoming" }, storageDir.list()); } } finally { // set writable again to make sure we can remove the directory if (tempFileDir != null) { //noinspection ResultOfMethodCallIgnored tempFileDir.setWritable(true, false); } } }
From source file:org.apache.flink.runtime.blob.BlobServerPutTest.java
/** * Uploads a byte array to a server which cannot create any files via the {@link BlobServer}. * File transfers should fail./*from w ww . java2s. c o m*/ * * @param jobId * job id * @param blobType * whether the BLOB should become permanent or transient */ private void testPutBufferFails(@Nullable final JobID jobId, BlobKey.BlobType blobType) throws IOException { assumeTrue(!OperatingSystem.isWindows()); //setWritable doesn't work on Windows. final Configuration config = new Configuration(); config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporaryFolder.newFolder().getAbsolutePath()); File tempFileDir = null; try (BlobServer server = new BlobServer(config, new VoidBlobStore())) { server.start(); // make sure the blob server cannot create any files in its storage dir tempFileDir = server.createTemporaryFilename().getParentFile().getParentFile(); assertTrue(tempFileDir.setExecutable(true, false)); assertTrue(tempFileDir.setReadable(true, false)); assertTrue(tempFileDir.setWritable(false, false)); byte[] data = new byte[2000000]; rnd.nextBytes(data); // upload the file to the server directly exception.expect(AccessDeniedException.class); put(server, jobId, data, blobType); } finally { // set writable again to make sure we can remove the directory if (tempFileDir != null) { //noinspection ResultOfMethodCallIgnored tempFileDir.setWritable(true, false); } } }
From source file:hudson.plugins.project_inheritance.projects.view.InheritanceViewAction.java
private void dumpMasterScript(boolean isLinux, List<File> generatedScripts, File srcDir) throws IOException { Map<String, String> parameters = getResolvedBuildParameters(this.getBuild()); String scrFile = (isLinux) ? "build.sh" : "build.bat"; String scrPreamble = (isLinux) ? "#!/bin/bash" : "@echo off"; String scrSetCmd = (isLinux) ? "export" : "set"; String scrInvoke = (isLinux) ? "./" : "CALL "; String lineEnd = (isLinux) ? "\n" : "\r\n"; File mainScript = new File(srcDir, scrFile); BufferedWriter out = new BufferedWriter(new FileWriter(mainScript, true)); out.write(scrPreamble);/*from ww w.j a va 2s. c o m*/ out.write(lineEnd); if (parameters.size() > 0) { for (String parameter : parameters.keySet()) { out.write( String.format("%s %s=\"%s\"%s", scrSetCmd, parameter, parameters.get(parameter), lineEnd)); } } for (File script : generatedScripts) { if (isLinux) { out.write(String.format("echo 'Will run %s now ...'%s", script.getName(), lineEnd)); } else { out.write(String.format("echo Will run %s now ...%s", script.getName(), lineEnd)); } out.write(String.format("%s%s%s", scrInvoke, script.getName(), lineEnd)); } if (isLinux) { mainScript.setExecutable(true, false); mainScript.setWritable(true, false); mainScript.setReadable(true, false); } out.close(); generatedScripts.add(mainScript); }
From source file:org.apache.flink.runtime.blob.BlobServerPutTest.java
/** * Uploads a byte array to a server which cannot move incoming files to the final blob store via * the {@link BlobServer}. File transfers should fail. * * @param jobId/*from www . ja v a 2s .c o m*/ * job id * @param blobType * whether the BLOB should become permanent or transient */ private void testPutBufferFailsStore(@Nullable final JobID jobId, BlobKey.BlobType blobType) throws IOException { assumeTrue(!OperatingSystem.isWindows()); //setWritable doesn't work on Windows. final Configuration config = new Configuration(); config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporaryFolder.newFolder().getAbsolutePath()); File jobStoreDir = null; try (BlobServer server = new BlobServer(config, new VoidBlobStore())) { server.start(); // make sure the blob server cannot create any files in its storage dir jobStoreDir = server.getStorageLocation(jobId, BlobKey.createKey(blobType)).getParentFile(); assertTrue(jobStoreDir.setExecutable(true, false)); assertTrue(jobStoreDir.setReadable(true, false)); assertTrue(jobStoreDir.setWritable(false, false)); byte[] data = new byte[2000000]; rnd.nextBytes(data); // upload the file to the server directly exception.expect(AccessDeniedException.class); try { put(server, jobId, data, blobType); } finally { // there should be no remaining incoming files File incomingFileDir = new File(jobStoreDir.getParent(), "incoming"); assertArrayEquals(new String[] {}, incomingFileDir.list()); // there should be no files in the job directory assertArrayEquals(new String[] {}, jobStoreDir.list()); } } finally { // set writable again to make sure we can remove the directory if (jobStoreDir != null) { //noinspection ResultOfMethodCallIgnored jobStoreDir.setWritable(true, false); } } }
From source file:edu.umd.cs.buildServer.BuildServer.java
/** * Makes a directory world-readable.//from ww w. j a v a2 s .c om * <p> * This will not work on Windows! * * @param dirName * The directory to make world-readable. * @throws IOException */ private void makeDirectoryWorldReadable(File dir) throws IOException { // TODO Make sure that this is a non-Windows machine. if (dir.isDirectory()) { dir.setReadable(true, false); dir.setWritable(true, false); dir.setExecutable(true, false); } }
From source file:org.apache.flink.runtime.blob.BlobCachePutTest.java
/** * Uploads a byte array to a server which cannot create incoming files via the {@link * BlobCacheService}. File transfers should fail. * * @param jobId/* w ww .j ava2 s . c om*/ * job id * @param blobType * whether the BLOB should become permanent or transient */ private void testPutBufferFailsIncoming(@Nullable final JobID jobId, BlobKey.BlobType blobType) throws IOException { assumeTrue(!OperatingSystem.isWindows()); //setWritable doesn't work on Windows. final Configuration config = new Configuration(); config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporaryFolder.newFolder().getAbsolutePath()); File tempFileDir = null; try (BlobServer server = new BlobServer(config, new VoidBlobStore()); BlobCacheService cache = new BlobCacheService(config, new VoidBlobStore(), new InetSocketAddress("localhost", server.getPort()))) { server.start(); // make sure the blob server cannot create any files in its storage dir tempFileDir = server.createTemporaryFilename().getParentFile(); assertTrue(tempFileDir.setExecutable(true, false)); assertTrue(tempFileDir.setReadable(true, false)); assertTrue(tempFileDir.setWritable(false, false)); byte[] data = new byte[2000000]; rnd.nextBytes(data); // upload the file to the server via the cache exception.expect(IOException.class); exception.expectMessage("PUT operation failed: "); try { put(cache, jobId, data, blobType); } finally { File storageDir = tempFileDir.getParentFile(); // only the incoming directory should exist (no job directory!) assertArrayEquals(new String[] { "incoming" }, storageDir.list()); } } finally { // set writable again to make sure we can remove the directory if (tempFileDir != null) { //noinspection ResultOfMethodCallIgnored tempFileDir.setWritable(true, false); } } }
From source file:org.apache.flink.runtime.blob.BlobCachePutTest.java
/** * Uploads a byte array to a server which cannot create any files via the {@link * BlobCacheService}. File transfers should fail. * * @param jobId// w w w . ja v a2s . c om * job id * @param blobType * whether the BLOB should become permanent or transient */ private void testPutBufferFails(@Nullable final JobID jobId, BlobKey.BlobType blobType) throws IOException { assumeTrue(!OperatingSystem.isWindows()); //setWritable doesn't work on Windows. final Configuration config = new Configuration(); config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporaryFolder.newFolder().getAbsolutePath()); File tempFileDir = null; try (BlobServer server = new BlobServer(config, new VoidBlobStore()); BlobCacheService cache = new BlobCacheService(config, new VoidBlobStore(), new InetSocketAddress("localhost", server.getPort()))) { server.start(); // make sure the blob server cannot create any files in its storage dir tempFileDir = server.createTemporaryFilename().getParentFile().getParentFile(); assertTrue(tempFileDir.setExecutable(true, false)); assertTrue(tempFileDir.setReadable(true, false)); assertTrue(tempFileDir.setWritable(false, false)); byte[] data = new byte[2000000]; rnd.nextBytes(data); // upload the file to the server via the cache exception.expect(IOException.class); exception.expectMessage("PUT operation failed: "); put(cache, jobId, data, blobType); } finally { // set writable again to make sure we can remove the directory if (tempFileDir != null) { //noinspection ResultOfMethodCallIgnored tempFileDir.setWritable(true, false); } } }
From source file:org.apache.flink.runtime.blob.BlobCachePutTest.java
/** * Uploads a byte array to a server which cannot create files via the {@link BlobCacheService}. * File transfers should fail.// www . ja v a 2 s . c o m * * @param jobId * job id * @param blobType * whether the BLOB should become permanent or transient */ private void testPutBufferFailsStore(@Nullable final JobID jobId, BlobKey.BlobType blobType) throws IOException { assumeTrue(!OperatingSystem.isWindows()); //setWritable doesn't work on Windows. final Configuration config = new Configuration(); config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporaryFolder.newFolder().getAbsolutePath()); File jobStoreDir = null; try (BlobServer server = new BlobServer(config, new VoidBlobStore()); BlobCacheService cache = new BlobCacheService(config, new VoidBlobStore(), new InetSocketAddress("localhost", server.getPort()))) { server.start(); // make sure the blob server cannot create any files in its storage dir jobStoreDir = server.getStorageLocation(jobId, BlobKey.createKey(blobType)).getParentFile(); assertTrue(jobStoreDir.setExecutable(true, false)); assertTrue(jobStoreDir.setReadable(true, false)); assertTrue(jobStoreDir.setWritable(false, false)); byte[] data = new byte[2000000]; rnd.nextBytes(data); // upload the file to the server via the cache exception.expect(IOException.class); exception.expectMessage("PUT operation failed: "); try { put(cache, jobId, data, blobType); } finally { // there should be no remaining incoming files File incomingFileDir = new File(jobStoreDir.getParent(), "incoming"); assertArrayEquals(new String[] {}, incomingFileDir.list()); // there should be no files in the job directory assertArrayEquals(new String[] {}, jobStoreDir.list()); } } finally { // set writable again to make sure we can remove the directory if (jobStoreDir != null) { //noinspection ResultOfMethodCallIgnored jobStoreDir.setWritable(true, false); } } }