/** * Like the unix command of the same name, creates an empty file or updates the last modified * timestamp of the existing file at the given path to the current system time. */ @SuppressWarnings("GoodTime") // reading system time without TimeSource public static void touch(Path path) throws IOException { checkNotNull(path); try { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis())); } catch (NoSuchFileException e) { try { Files.createFile(path); } catch (FileAlreadyExistsException ignore) { // The file didn't exist when we called setLastModifiedTime, but it did when we called // createFile, so something else created the file in between. The end result is // what we wanted: a new file that probably has its last modified time set to approximately // now. Or it could have an arbitrary last modified time set by the creator, but that's no // different than if another process set its last modified time to something else after we // created it here. } } }
/** * Like the unix command of the same name, creates an empty file or updates the last modified * timestamp of the existing file at the given path to the current system time. */ public static void touch(Path path) throws IOException { checkNotNull(path); try { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis())); } catch (NoSuchFileException e) { try { Files.createFile(path); } catch (FileAlreadyExistsException ignore) { // The file didn't exist when we called setLastModifiedTime, but it did when we called // createFile, so something else created the file in between. The end result is // what we wanted: a new file that probably has its last modified time set to approximately // now. Or it could have an arbitrary last modified time set by the creator, but that's no // different than if another process set its last modified time to something else after we // created it here. } } }
/** * Like the unix command of the same name, creates an empty file or updates the last modified * timestamp of the existing file at the given path to the current system time. */ public static void touch(Path path) throws IOException { checkNotNull(path); try { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis())); } catch (NoSuchFileException e) { try { Files.createFile(path); } catch (FileAlreadyExistsException ignore) { // The file didn't exist when we called setLastModifiedTime, but it did when we called // createFile, so something else created the file in between. The end result is // what we wanted: a new file that probably has its last modified time set to approximately // now. Or it could have an arbitrary last modified time set by the creator, but that's no // different than if another process set its last modified time to something else after we // created it here. } } }
/** * Like the unix command of the same name, creates an empty file or updates the last modified * timestamp of the existing file at the given path to the current system time. */ public static void touch(Path path) throws IOException { checkNotNull(path); try { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis())); } catch (NoSuchFileException e) { try { Files.createFile(path); } catch (FileAlreadyExistsException ignore) { // The file didn't exist when we called setLastModifiedTime, but it did when we called // createFile, so something else created the file in between. The end result is // what we wanted: a new file that probably has its last modified time set to approximately // now. Or it could have an arbitrary last modified time set by the creator, but that's no // different than if another process set its last modified time to something else after we // created it here. } } }
Files.setLastModifiedTime( dir, Files.getLastModifiedTime( file ) ); Log.debug( "Extracting plugin '{}'...", pluginName ); for ( Enumeration e = zipFile.entries(); e.hasMoreElements(); )
@Override public void run() { final FileTime now = FileTime.fromMillis( System.currentTimeMillis() ); for ( final Handler handler : this.server.getChildHandlersByClass( WebAppContext.class ) ) { final File tempDirectory = ((WebAppContext) handler).getTempDirectory(); try { Log.debug( "Updating the last modified timestamp of content in Jetty's temporary storage in: {}", tempDirectory); Files.walk( tempDirectory.toPath() ) .forEach( f -> { try { Log.trace( "Setting the last modified timestamp of file '{}' in Jetty's temporary storage to: {}", f, now); Files.setLastModifiedTime( f, now ); } catch ( IOException e ) { Log.warn( "An exception occurred while trying to update the last modified timestamp of content in Jetty's temporary storage in: {}", f, e ); } } ); } catch ( IOException e ) { Log.warn( "An exception occurred while trying to update the last modified timestamp of content in Jetty's temporary storage in: {}", tempDirectory, e ); } } } }
private void updateLastModified(final Path... paths) throws IOException { for (final Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } }
private void updateLastModified(final Path... paths) throws IOException { for (final Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } }
private void updateLastModified(final Path... paths) throws IOException { for (final Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } }
protected void setLastModified(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) { // Using Files.setLastModifiedTime() instead of File.setLastModified() // due to pre-1970 issue. See #374 for details. try { FileTime newLastModifiedTime = FileTime.fromMillis(reconstructedFileVersion.getLastModified().getTime()); Files.setLastModifiedTime(reconstructedFilesAtFinalLocation.toPath(), newLastModifiedTime); } catch (IOException e) { logger.log(Level.WARNING, "Warning: Could not set last modified date for file " + reconstructedFilesAtFinalLocation + "; Ignoring error.", e); } }
public void testTouchTime() throws IOException { Path temp = createTempFile(); assertTrue(Files.exists(temp)); Files.setLastModifiedTime(temp, FileTime.fromMillis(0)); assertEquals(0, Files.getLastModifiedTime(temp).toMillis()); MoreFiles.touch(temp); assertThat(Files.getLastModifiedTime(temp).toMillis()).isNotEqualTo(0); }
@Before public void setUp() throws Exception { base = Files.createTempDirectory("tempDir", new FileAttribute<?>[0]); aaa = Files.createTempFile(base, "aaa", null, new FileAttribute<?>[0]); bbb = Files.createTempFile(base, "bbb", null, new FileAttribute<?>[0]); ccc = Files.createTempFile(base, "ccc", null, new FileAttribute<?>[0]); // lastModified granularity is 1 sec(!) on some file systems... final long now = System.currentTimeMillis(); Files.setLastModifiedTime(aaa, FileTime.fromMillis(now)); Files.setLastModifiedTime(bbb, FileTime.fromMillis(now + 1000)); Files.setLastModifiedTime(ccc, FileTime.fromMillis(now + 2000)); }
public boolean reloadPlugin( String pluginName ) { Log.debug( "Reloading plugin '{}'..." ); final Plugin plugin = getPlugin( pluginName ); if ( plugin == null ) { Log.warn( "Unable to reload plugin '{}'. No such plugin loaded.", pluginName ); return false; } final Path path = getPluginPath( plugin ); if ( path == null ) { // When there's a plugin, there should be a path. If there isn't, our code is buggy. throw new IllegalStateException( "Unable to determine installation path of plugin: " + pluginName ); } try { Files.setLastModifiedTime( path, FileTime.fromMillis( 0 ) ); } catch ( IOException e ) { Log.warn( "Unable to reload plugin '{}'. Unable to reset the 'last modified time' of the plugin path. Try removing and restoring the plugin jar file manually." ); return false; } pluginMonitor.runNow( false ); return true; }
@Test public void getNextGamePreviewImagePathOldestFileTest() throws IOException, InterruptedException { Files.createDirectories(TMP_PREVIEWS_FOLDER); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("1.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("2.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("3.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("4.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("5.jpg")); final Path expectedOldestFile = TMP_PREVIEWS_FOLDER.resolve("3.jpg"); Files.setLastModifiedTime(expectedOldestFile, FileTime.fromMillis(0)); final Path imagePath = GamePreviewImageProvider.getNextGamePreviewImagePath(TMP_FOLDER); Assert.assertNotNull(imagePath); Assert.assertEquals(expectedOldestFile, imagePath); } }
private void updateTimeStamp() throws IOException { long remoteTimestamp = connection.getLastModified(); if (remoteTimestamp != 0) { Files.setLastModifiedTime(dest, FileTime.fromMillis(remoteTimestamp)); } }
private void updateTimeStamp() throws IOException { long remoteTimestamp = connection.getLastModified(); if (remoteTimestamp != 0) { Files.setLastModifiedTime(dest, FileTime.fromMillis(remoteTimestamp)); } }
private void updateTimeStamp() throws IOException { long remoteTimestamp = connection.getLastModified(); if (remoteTimestamp != 0) { Files.setLastModifiedTime(dest, FileTime.fromMillis(remoteTimestamp)); } }
/** * @param file * @param time * @throws IOException */ static void setLastModified(File file, long time) throws IOException { Files.setLastModifiedTime(toPath(file), FileTime.fromMillis(time)); }
/** * Test case for https://github.com/dadoonet/fscrawler/issues/379 * @throws Exception In case something is wrong */ @Test public void test_move_file() throws Exception { startCrawler(); // We should have one doc first countTestHelper(new ESSearchRequest().withIndex(getCrawlerName()), 1L, currentTestResourceDir); // We move the file logger.info(" ---> Moving file roottxtfile.txt to a tmp dir"); Files.move(currentTestResourceDir.resolve("roottxtfile.txt"), rootTmpDir.resolve("roottxtfile.txt"), StandardCopyOption.ATOMIC_MOVE); // We expect to have 0 file countTestHelper(new ESSearchRequest().withIndex(getCrawlerName()), 0L, currentTestResourceDir); // We move the file back logger.info(" ---> Moving file roottxtfile.txt from the tmp dir"); Files.move(rootTmpDir.resolve("roottxtfile.txt"), currentTestResourceDir.resolve("roottxtfile.txt"), StandardCopyOption.ATOMIC_MOVE); // We need to "touch" the file we just moved Files.setLastModifiedTime(currentTestResourceDir.resolve("roottxtfile.txt"), FileTime.from(Instant.now())); // We expect to have 1 file countTestHelper(new ESSearchRequest().withIndex(getCrawlerName()), 1L, currentTestResourceDir); }
public void setModificationDate(final long timestamp) throws AccessDeniedException { if(timestamp < 0) { return; } try { Files.setLastModifiedTime(Paths.get(path), FileTime.fromMillis(timestamp)); } catch(IOException e) { throw new LocalAccessDeniedException(String.format("Cannot change timestamp of %s", path), e); } }