List of usage examples for java.nio.file LinkOption NOFOLLOW_LINKS
LinkOption NOFOLLOW_LINKS
To view the source code for java.nio.file LinkOption NOFOLLOW_LINKS.
Click Source Link
From source file:onl.area51.filesystem.ftp.client.FTPClient.java
/** * Simple test to see if a remote file should be retrieved. * <p>/*w w w. java2 s .co m*/ * This returns true if file does not exist, if the lengths don't match or the remote file's date is newer than the local file * <p> * @param file * @param ftp * <p> * @return */ default boolean isPathRetrievable(Path file, FTPFile ftp) throws IOException { return !Files.exists(file, LinkOption.NOFOLLOW_LINKS) || Files.size(file) != ftp.getSize() || Files.getLastModifiedTime(file, LinkOption.NOFOLLOW_LINKS).toMillis() < ftp.getTimestamp() .getTimeInMillis(); }
From source file:com.liferay.sync.engine.file.system.SyncWatchEventProcessor.java
protected synchronized void processSyncWatchEvent(SyncWatchEvent syncWatchEvent) throws Exception { SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(_syncAccountId); if (syncAccount.getState() != SyncAccount.STATE_CONNECTED) { return;/*from w ww . j a v a2 s. c om*/ } if (_processedSyncWatchEventIds.contains(syncWatchEvent.getSyncWatchEventId())) { SyncWatchEventService.deleteSyncWatchEvent(syncWatchEvent.getSyncWatchEventId()); return; } String eventType = syncWatchEvent.getEventType(); if (eventType.equals(SyncWatchEvent.EVENT_TYPE_RENAME_FROM)) { eventType = SyncWatchEvent.EVENT_TYPE_DELETE; syncWatchEvent.setEventType(eventType); SyncWatchEventService.update(syncWatchEvent); } if (_logger.isDebugEnabled()) { _logger.debug("Processing Sync watch event {}", syncWatchEvent.toString()); } String fileType = syncWatchEvent.getFileType(); if (eventType.equals(SyncWatchEvent.EVENT_TYPE_CREATE)) { if (fileType.equals(SyncFile.TYPE_FILE)) { SyncWatchEvent duplicateSyncWatchEvent = null; if (OSDetector.isApple()) { duplicateSyncWatchEvent = SyncWatchEventService.fetchDuplicateSyncWatchEvent(syncWatchEvent); } if (duplicateSyncWatchEvent != null) { if (_logger.isDebugEnabled()) { _logger.debug("Skipping outdated Sync watch event"); } } else { addFile(syncWatchEvent); } } else { addFolder(syncWatchEvent); } } else if (eventType.equals(SyncWatchEvent.EVENT_TYPE_DELETE)) { deleteFile(syncWatchEvent); } else if (eventType.equals(SyncWatchEvent.EVENT_TYPE_MODIFY)) { SyncWatchEvent duplicateSyncWatchEvent = SyncWatchEventService .fetchDuplicateSyncWatchEvent(syncWatchEvent); if (duplicateSyncWatchEvent != null) { if (_logger.isDebugEnabled()) { _logger.debug("Skipping outdated Sync watch event"); } } else { if (OSDetector.isWindows()) { // SYNC-1713 String filePathName = syncWatchEvent.getFilePathName(); Path filePath = Paths.get(filePathName); if (FileUtil.exists(filePath)) { Path realFilePath = filePath.toRealPath(LinkOption.NOFOLLOW_LINKS); if (!filePathName.equals(realFilePath.toString())) { syncWatchEvent.setEventType(SyncWatchEvent.EVENT_TYPE_RENAME); syncWatchEvent.setFilePathName(realFilePath.toString()); syncWatchEvent.setPreviousFilePathName(filePathName); renameFile(syncWatchEvent); } if (fileType.equals(SyncFile.TYPE_FILE)) { modifyFile(syncWatchEvent); } } else { modifyFile(syncWatchEvent); } } else { modifyFile(syncWatchEvent); } } } else if (eventType.equals(SyncWatchEvent.EVENT_TYPE_MOVE)) { moveFile(syncWatchEvent); } else if (eventType.equals(SyncWatchEvent.EVENT_TYPE_RENAME)) { renameFile(syncWatchEvent); } syncAccount = SyncAccountService.fetchSyncAccount(_syncAccountId); if (syncAccount.getState() == SyncAccount.STATE_CONNECTED) { SyncWatchEventService.deleteSyncWatchEvent(syncWatchEvent.getSyncWatchEventId()); } }
From source file:org.eclipse.winery.repository.backend.filebased.FilebasedRepository.java
private static void getFiles(Path dir, String path, SortedSet<FileInfo> res) { if (!Files.exists(dir)) { return;//from w ww .j a v a 2 s . c om } assert (Files.isDirectory(dir)); try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir)) { for (Path p : ds) { if (Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS)) { getFiles(p, path + "/" + p.getFileName(), res); } else if (!p.getFileName().toString().endsWith(".mimetype")) { res.add(new FileInfo(path, p.getFileName().toString())); } } } catch (IOException e) { FilebasedRepository.logger.debug("Cannot close ds", e); } }
From source file:configuration.Util.java
/** * Get the owner's group of the current jar file * @return the owner's group of the current jar file *//* ww w . java 2 s . c o m*/ public static String getGroupJar() { Path jpath = Paths.get(currentPath()); try { GroupPrincipal group = Files.readAttributes(jpath, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS) .group(); return group.getName(); } catch (IOException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); System.out.println("Can't get Owner or the jar file"); System.out.println(ex); return ""; } }
From source file:edu.utah.bmi.ibiomes.lite.IBIOMESLiteManager.java
/** * Remove existing XML and HTML files/* w w w. j a v a2 s . co m*/ * @throws Exception */ public int cleanData() throws Exception { int nDelete = 0; if (this.outputToConsole) System.out.println("Removing experiments..."); //remove main XML file Path indexXmlPath = Paths.get(publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_LITE_XML_INDEX); if (Files.exists(indexXmlPath, LinkOption.NOFOLLOW_LINKS)) Files.delete(indexXmlPath); this.experimentListXml = new XmlExperimentListFile( publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_LITE_XML_INDEX); //remove main HTML file Path indexHtmlPath = Paths.get(publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_LITE_HTML_INDEX); if (Files.exists(indexHtmlPath, LinkOption.NOFOLLOW_LINKS)) Files.delete(indexHtmlPath); //remove experiments data (XML, HTML, files) File htmlDir = new File(publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_LITE_EXPERIMENT_DIR); File[] htmlFiles = htmlDir.listFiles(); for (int f = 0; f < htmlFiles.length; f++) { Utils.removeDirectoryRecursive(Paths.get(htmlFiles[f].getCanonicalPath())); nDelete++; } return nDelete; }
From source file:edu.utah.bmi.ibiomes.lite.IBIOMESLiteManager.java
/** * Remove XML and HTML files for a given experiment * @throws TransformerException //from w ww . jav a2s . co m * @throws IOException * @throws SAXException * @throws ParserConfigurationException * @throws XPathExpressionException */ public int removeExperiment(String experimentPath) throws TransformerException, IOException, XPathExpressionException, ParserConfigurationException, SAXException { File experimentDir = new File(experimentPath); if (!experimentDir.exists()) return -1; experimentPath = experimentDir.getCanonicalPath(); int experimentId = this.experimentListXml.removeExperiment(experimentPath); if (experimentId != -1) { //update XML list and regenerate HTML this.experimentListXml.saveXml(); this.experimentListXml.saveToHTML(publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_LITE_HTML_INDEX, publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_EXPERIMENT_SET_XSL_PATH); //delete experiment folder in iBIOMES Lite Path expWebDirPath = Paths.get(publicHtmlFolder + PATH_FOLDER_SEPARATOR + IBIOMES_LITE_EXPERIMENT_DIR + PATH_FOLDER_SEPARATOR + experimentId); if (Files.exists(expWebDirPath, LinkOption.NOFOLLOW_LINKS)) Utils.removeDirectoryRecursive(expWebDirPath); } return experimentId; }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImplTest.java
@Test public void testStoreWhenRequiredAndFileRealPathCannotBeDetermined() throws Exception { final PathUtils pathUtils = Mockito.mock(PathUtils.class); final Path path = Mockito.mock(Path.class); final IOException ioe = new IOException("test"); Mockito.when(context.getPathUtils()).thenReturn(pathUtils); Mockito.when(pathUtils.resolveAgainstDDFHome((Path) Mockito.any())).thenReturn(path); Mockito.when(pathUtils.relativizeFromDDFHome(Mockito.any())).thenReturn(path); Mockito.when(path.toRealPath(LinkOption.NOFOLLOW_LINKS)).thenThrow(ioe); final ExportMigrationEntryImpl entry = new ExportMigrationEntryImpl(context, FILE_PATH); final StringWriter writer = new StringWriter(); Mockito.when(context.getOutputStreamFor(Mockito.any())) .thenReturn(new WriterOutputStream(writer, Charsets.UTF_8)); Assert.assertThat(entry.store(true), Matchers.equalTo(false)); Assert.assertThat(writer.toString(), Matchers.emptyString()); Assert.assertThat(report.hasErrors(), Matchers.equalTo(true)); Assert.assertThat(report.hasWarnings(), Matchers.equalTo(false)); Assert.assertThat(report.wasSuccessful(), Matchers.equalTo(false)); thrown.expect(MigrationException.class); thrown.expectMessage(Matchers.containsString("cannot be read")); thrown.expectCause(Matchers.sameInstance(ioe)); report.verifyCompletion(); // to trigger an exception from the report }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImplTest.java
@Test public void testStoreWithFilterWhenRequiredAndFileRealPathCannotBeDeterminedAndMatching() throws Exception { final PathUtils pathUtils = Mockito.mock(PathUtils.class); final Path path = Mockito.mock(Path.class); final IOException ioe = new IOException("test"); Mockito.when(context.getPathUtils()).thenReturn(pathUtils); Mockito.when(pathUtils.resolveAgainstDDFHome((Path) Mockito.any())).thenReturn(path); Mockito.when(pathUtils.relativizeFromDDFHome(Mockito.any())).thenReturn(path); Mockito.when(path.toRealPath(LinkOption.NOFOLLOW_LINKS)).thenThrow(ioe); final ExportMigrationEntryImpl entry = new ExportMigrationEntryImpl(context, FILE_PATH); final StringWriter writer = new StringWriter(); Mockito.when(context.getOutputStreamFor(Mockito.any())) .thenReturn(new WriterOutputStream(writer, Charsets.UTF_8)); Assert.assertThat(entry.store(true, p -> true), Matchers.equalTo(false)); Assert.assertThat(writer.toString(), Matchers.emptyString()); Assert.assertThat(report.hasErrors(), Matchers.equalTo(true)); Assert.assertThat(report.hasWarnings(), Matchers.equalTo(false)); Assert.assertThat(report.wasSuccessful(), Matchers.equalTo(false)); thrown.expect(MigrationException.class); thrown.expectMessage(Matchers.containsString("cannot be read")); thrown.expectCause(Matchers.sameInstance(ioe)); report.verifyCompletion(); // to trigger an exception from the report }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImplTest.java
@Test public void testStoreWithFilterWhenRequiredAndFileRealPathCannotBeDeterminedAndNotMatching() throws Exception { final PathUtils pathUtils = Mockito.mock(PathUtils.class); final Path path = Mockito.mock(Path.class); final IOException ioe = new IOException("test"); Mockito.when(context.getPathUtils()).thenReturn(pathUtils); Mockito.when(pathUtils.resolveAgainstDDFHome((Path) Mockito.any())).thenReturn(path); Mockito.when(pathUtils.relativizeFromDDFHome(Mockito.any())).thenReturn(path); Mockito.when(path.toRealPath(LinkOption.NOFOLLOW_LINKS)).thenThrow(ioe); final ExportMigrationEntryImpl entry = new ExportMigrationEntryImpl(context, FILE_PATH); final StringWriter writer = new StringWriter(); Mockito.when(context.getOutputStreamFor(Mockito.any())) .thenReturn(new WriterOutputStream(writer, Charsets.UTF_8)); Assert.assertThat(entry.store(true, p -> false), Matchers.equalTo(false)); Assert.assertThat(writer.toString(), Matchers.emptyString()); Assert.assertThat(report.hasErrors(), Matchers.equalTo(true)); Assert.assertThat(report.hasWarnings(), Matchers.equalTo(false)); Assert.assertThat(report.wasSuccessful(), Matchers.equalTo(false)); Mockito.verify(context, Mockito.never()).getOutputStreamFor(Mockito.any()); thrown.expect(MigrationException.class); thrown.expectMessage(Matchers.containsString("does not match filter")); report.verifyCompletion(); // to trigger an exception from the report }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImplTest.java
@Test public void testGetPropertyReferencedEntryWhenValueIsAbsoluteNotUnderDDFHome() throws Exception { final Path migratablePath = testFolder.newFile("test.cfg").toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); final String migratableName = FilenameUtils.separatorsToUnix(migratablePath.toString()); storeProperty(PROPERTY_NAME, migratablePath.toAbsolutePath().toString()); final Optional<ExportMigrationEntry> oentry = entry.getPropertyReferencedEntry(PROPERTY_NAME, (r, v) -> true);/*from w w w .j a v a 2s .co m*/ Assert.assertThat(oentry, OptionalMatchers.isPresent()); final ExportMigrationEntry entry = oentry.get(); Assert.assertThat(entry.getId(), Matchers.equalTo(MIGRATABLE_ID)); Assert.assertThat(entry.getName(), Matchers.equalTo(migratableName)); Assert.assertThat(entry.getPath(), Matchers.equalTo(migratablePath)); // now check that it is a java property referenced entry that references the proper property // name Assert.assertThat(entry, Matchers.instanceOf(ExportMigrationJavaPropertyReferencedEntryImpl.class)); final ExportMigrationJavaPropertyReferencedEntryImpl jentry = (ExportMigrationJavaPropertyReferencedEntryImpl) entry; Assert.assertThat(jentry.getProperty(), Matchers.equalTo(PROPERTY_NAME)); // finally make sure no warnings or errors were recorded Assert.assertThat(report.hasErrors(), Matchers.equalTo(false)); Assert.assertThat(report.hasWarnings(), Matchers.equalTo(false)); }