List of usage examples for java.io File setWritable
public boolean setWritable(boolean writable, boolean ownerOnly)
From source file:com.comcast.cdn.traffic_control.traffic_router.core.loc.AbstractServiceUpdater.java
private void moveDirectory(final File existingDB, final File newDB) throws IOException { LOGGER.info("[" + getClass().getSimpleName() + "] Moving Location database from: " + newDB + ", to: " + existingDB);/*from w w w .ja v a2s .c o m*/ for (final File file : existingDB.listFiles()) { file.setReadable(true, true); file.setWritable(true, false); file.delete(); } existingDB.delete(); Files.move(newDB.toPath(), existingDB.toPath(), StandardCopyOption.ATOMIC_MOVE); }
From source file:org.slc.sli.ingestion.tenant.TenantPopulator.java
/** * * Create the landing zone directory for the parent landing zone * *//*w ww. ja v a 2s.co m*/ private void createParentLzDirectory() { String lzPath = Matcher.quoteReplacement(parentLandingZoneDir); File lzDirectory = new File(lzPath); if (!lzDirectory.mkdir()) { LOG.debug("Failed to mkdir: {}", lzDirectory.getPath()); } if (!lzDirectory.setReadable(true, false)) { LOG.debug("Failed to setReadable: {}", lzDirectory.getPath()); } if (!lzDirectory.setWritable(true, false)) { LOG.debug("Failed to setWritable: {}", lzDirectory.getPath()); } }
From source file:hudson.cli.CLITest.java
License:asdf
/** Sets up a fake {@code user.home} so that tests {@code -ssh} mode does not get confused by the developers real {@code ~/.ssh/known_hosts}. */ private File tempHome() throws IOException { home = tmp.newFolder();//from w ww.java 2s .c o m // Seems it gets created automatically but with inappropriate permissions: File known_hosts = new File(new File(home, ".ssh"), "known_hosts"); assumeTrue(known_hosts.getParentFile().mkdir()); assumeTrue(known_hosts.createNewFile()); assumeTrue(known_hosts.setWritable(false, false)); assumeTrue(known_hosts.setWritable(true, true)); try { Files.getOwner(known_hosts.toPath()); } catch (IOException x) { assumeNoException( "Sometimes on Windows KnownHostsServerKeyVerifier.acceptIncompleteHostKeys says WARNING: Failed (FileSystemException) to reload server keys from \\\\.ssh\\\\known_hosts: Incorrect function.", x); } assumeThat( "or on Windows DefaultKnownHostsServerKeyVerifier.reloadKnownHosts says invalid file permissions: Owner violation (Administrators)", ModifiableFileWatcher.validateStrictConfigFilePermissions(known_hosts.toPath()), nullValue()); return home; }
From source file:org.neo4j.server.web.logging.HTTPLoggingFunctionalTest.java
private File createUnwritableDirectory() { File file; if (osIsWindows()) { file = new File("\\\\" + UUID.randomUUID().toString() + "\\"); } else {/*from www . ja v a2 s . co m*/ TargetDirectory targetDirectory = TargetDirectory.forTest(this.getClass()); file = targetDirectory.file("unwritable-" + System.currentTimeMillis()); file.mkdirs(); file.setWritable(false, false); } return file; }
From source file:com.seedboxer.seedboxer.ws.controller.DownloadsController.java
/** * Save torrent file to watch-dog directory of downloader application (rTorrent or uTorrent) and * add the same torrent to the user queue. * * @param fileName//from w ww. j a va 2s. c o m * @param torrentFileInStream * @throws Exception */ public void addTorrent(String username, String fileName, final InputStream torrentFileInStream) throws Exception { User user = getUser(username); File torrent = new File(watchDownloaderPath + File.separator + fileName); Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return torrentFileInStream; } }, torrent); torrent.setReadable(true, false); torrent.setWritable(true, false); String name = TorrentUtils.getName(torrent); putToDownload(user, Collections.singletonList(name), false); }
From source file:org.slc.sli.ingestion.tenant.TenantPopulator.java
/** * * Create the landing zone directory for a tenant. * * @param tenant/*from w w w . j av a 2 s . com*/ * , the tenant for which to create landing zone directories * */ private void createTenantLzDirectory(TenantRecord tenant) { List<LandingZoneRecord> landingZones = tenant.getLandingZone(); for (LandingZoneRecord lz : landingZones) { String lzPath = lz.getPath(); File lzDirectory = new File(lzPath); if (!lzDirectory.mkdir()) { LOG.debug("Failed to mkdir: {}", lzDirectory.getPath()); } if (!lzDirectory.setReadable(true, false)) { LOG.debug("Failed to setReadable: {}", lzDirectory.getPath()); } if (!lzDirectory.setWritable(true, false)) { LOG.debug("Failed to setWritable: {}", lzDirectory.getPath()); } } }
From source file:de.huxhorn.sulky.blobs.impl.BlobRepositoryImplTest.java
@SuppressWarnings({ "ResultOfMethodCallIgnored" }) // Using fail because of http://github.com/KentBeck/junit/issues/issue/132 //@Test(expected = IllegalStateException.class) @Test/*from www . j a va2 s . c o m*/ public void brokenBaseDirectory() throws IOException { BlobRepositoryImpl instance = new BlobRepositoryImpl(); File readonlyBaseDirectory = folder.newFolder("foo"); readonlyBaseDirectory.setWritable(false, false); File baseDirectory = new File(readonlyBaseDirectory, "bar"); // lets check if creating baseDirectory actually fails... assumeTrue(!baseDirectory.mkdirs()); if (logger.isInfoEnabled()) logger.info("Actually executing brokenBaseDirectory test..."); assumeTrue(false); try { instance.setBaseDirectory(baseDirectory); fail("Expected exception was not thrown!"); } catch (IllegalArgumentException ex) { // expected } }
From source file:org.eclipse.thym.blackberry.core.bdt.BlackBerryProjectGenerator.java
private void copyFilesToProject(HybridMobileLibraryResolver resolver, IPath project_path) throws IOException { IPath nodeModulesDest = project_path.append("cordova").append("node_modules"); IPath bbtoolsBinDest = project_path.append("cordova").append("dependencies").append("bb-tools") .append("bin"); IPath bbtoolsLibDest = project_path.append("cordova").append("dependencies").append("bb-tools") .append("lib"); String bbNativePackager = "blackberry-nativepackager"; String bbSigner = "blackberry-signer"; String bbDeploy = "blackberry-deploy"; String bbDebugTokenRequest = "blackberry-debugtokenrequest"; // create project using template directory if (!project_path.toFile().exists()) { project_path.toFile().mkdir();/* w w w . j a v a 2s . c o m*/ } directoryCopy(resolver.getTemplateFile(new Path("templateDir")), toURL(project_path.toFile())); // copy repo level target tool to project fileCopy(resolver.getTemplateFile(new Path("target")), toURL(project_path.append("cordova").toFile())); fileCopy(resolver.getTemplateFile(new Path("target.bat")), toURL(project_path.append("cordova").toFile())); fileCopy(resolver.getTemplateFile(new Path("lib/target.js")), toURL(project_path.append("cordova").append("lib").toFile())); fileCopy(resolver.getTemplateFile(new Path("lib.config.js")), toURL(project_path.append("cordova").append("lib").toFile())); // copy repo level init script to project fileCopy(resolver.getTemplateFile(new Path("whereis.cmd")), toURL(project_path.append("cordova").toFile())); fileCopy(resolver.getTemplateFile(new Path("init.bat")), toURL(project_path.append("cordova").toFile())); fileCopy(resolver.getTemplateFile(new Path("init")), toURL(project_path.append("cordova").toFile())); //copy VERSION file [used to identify corresponding ~/.cordova/lib directory for dependencies] URL versionFile = resolver.getTemplateFile(new Path("VERSION")); fileCopy(versionFile, toURL(project_path.toFile())); String version = ""; BufferedReader r = null; try { r = new BufferedReader(new FileReader(versionFile.getFile())); String line = r.readLine(); version = line.replaceAll("([^\\x00-\\xFF]|\\s)*", ""); } finally { if (r != null) { r.close(); } } // copy repo level check_reqs script to project fileCopy(resolver.getTemplateFile(new Path("check_reqs.bat")), toURL(project_path.append("cordova").toFile())); fileCopy(resolver.getTemplateFile(new Path("check_reqs")), toURL(project_path.append("cordova").toFile())); // change file permission for cordova scripts because ant copy doesn't preserve file permissions project_path.toFile().setExecutable(true); project_path.toFile().setWritable(true); project_path.toFile().setReadable(true); //copy cordova-*version*.js to www fileCopy(resolver.getTemplateFile(new Path("cordova.js")), toURL(project_path.append("www").toFile())); //copy node modules to cordova build directory File nodeModules = project_path.append("cordova").append("node_modules").toFile(); if (!nodeModules.exists()) { nodeModules.mkdir(); } nodeModules.setExecutable(true, false); nodeModules.setWritable(true, false); nodeModules.setReadable(true, false); directoryCopy(resolver.getTemplateFile(new Path("node_modules")), toURL(nodeModules)); //copy framework bootstrap for (String target : TARGETS) { IPath chromeDir = project_path.append("native").append(target).append("chrome"); IPath frameworkLibDir = chromeDir.append("lib"); if (!frameworkLibDir.toFile().exists()) { frameworkLibDir.toFile().mkdir(); } directoryCopy(resolver.getTemplateFile(new Path("bootstrapDir")), toURL(chromeDir.toFile())); directoryCopy(resolver.getTemplateFile(new Path("frameworkLibDir")), toURL(frameworkLibDir.toFile())); } // save release IPath updateDir = project_path.append("lib").append("cordova.").append(version); if (!updateDir.toFile().exists()) { updateDir.toFile().mkdir(); } directoryCopy(resolver.getTemplateFile(new Path("buildDir")), toURL(updateDir.toFile())); }
From source file:org.dspace.storage.rdbms.DatabaseUtils.java
/** * Whether or not to tell Discovery to reindex itself based on the updated * database.//from w w w. j a va2 s. com * <P> * Whenever a DB migration occurs this is set to "true" to ensure the * Discovery index is updated. When Discovery initializes it calls * checkReindexDiscovery() to reindex if this flag is true. * <P> * Because the DB migration may be initialized by commandline or any one of * the many DSpace webapps, setting this to "true" actually writes a temporary * file which lets Solr know when reindex is needed. * @param reindex true or false */ public static synchronized void setReindexDiscovery(boolean reindex) { File reindexFlag = new File(reindexDiscoveryFilePath); // If we need to flag Discovery to reindex, we'll create a temporary file to do so. if (reindex) { try { //If our flag file doesn't exist, create it as writeable to all if (!reindexFlag.exists()) { reindexFlag.createNewFile(); reindexFlag.setWritable(true, false); } } catch (IOException io) { log.error("Unable to create Discovery reindex flag file " + reindexFlag.getAbsolutePath() + ". You may need to reindex manually.", io); } } else // Otherwise, Discovery doesn't need to reindex. Delete the temporary file if it exists { //If our flag file exists, delete it if (reindexFlag.exists()) { boolean deleted = reindexFlag.delete(); if (!deleted) log.error("Unable to delete Discovery reindex flag file " + reindexFlag.getAbsolutePath() + ". You may need to delete it manually."); } } }
From source file:org.ngrinder.common.util.CompressionUtil.java
/** * Untar an input file into an output file. * /* w w w. ja va 2 s. c o m*/ * The output file is created in the output folder, having the same name as the input file, * minus the '.tar' extension. * * @param inFile * the input .tar file * @param outputDir * the output directory file. * @throws IOException * @throws FileNotFoundException * * @return The {@link List} of {@link File}s with the untared content. * @throws ArchiveException */ public static List<File> untar(final File inFile, final File outputDir) { final List<File> untaredFiles = new LinkedList<File>(); try { final InputStream is = new FileInputStream(inFile); final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory() .createArchiveInputStream("tar", is); TarArchiveEntry entry = null; while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) { final File outputFile = new File(outputDir, entry.getName()); if (entry.isDirectory()) { if (!outputFile.exists()) { if (!outputFile.mkdirs()) { throw new IllegalStateException( String.format("Couldn't create directory %s.", outputFile.getAbsolutePath())); } } } else { File parentFile = outputFile.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } final OutputStream outputFileStream = new FileOutputStream(outputFile); IOUtils.copy(debInputStream, outputFileStream); outputFileStream.close(); if (FilenameUtils.isExtension(outputFile.getName(), EXECUTABLE_EXTENSION)) { outputFile.setExecutable(true, true); } outputFile.setReadable(true); outputFile.setWritable(true, true); } untaredFiles.add(outputFile); } debInputStream.close(); } catch (Exception e) { LOGGER.error("Error while untar {} file by {}", inFile, e.getMessage()); LOGGER.debug("Trace is : ", e); throw new NGrinderRuntimeException("Error while untar file", e); } return untaredFiles; }