@Override public void setTimes(Path p, long mtime, long atime ) throws IOException { fs.setTimes(p, mtime, atime); }
private void updateTime(PathData item) throws IOException { long time = System.currentTimeMillis(); if (timestamp != null) { try { time = dateFormat.parse(timestamp).getTime(); } catch (ParseException e) { throw new IllegalArgumentException( "Unable to parse the specified timestamp " + timestamp, e); } } if (changeModTime ^ changeAccessTime) { long atime = changeModTime ? -1 : time; long mtime = changeAccessTime ? -1 : time; item.fs.setTimes(item.path, mtime, atime); } else { item.fs.setTimes(item.path, time, time); } } }
public static boolean renameAndSetModifyTime(final FileSystem fs, final Path src, final Path dest) throws IOException { // set the modify time for TimeToLive Cleaner fs.setTimes(src, EnvironmentEdgeManager.currentTime(), -1); return fs.rename(src, dest); }
@Override public boolean touch(URI uri) throws IOException { Path path = new Path(uri); if (!exists(uri)) { FSDataOutputStream fos = _hadoopFS.create(path); fos.close(); } else { _hadoopFS.setTimes(path, System.currentTimeMillis(), -1); } return true; }
@Override public void setTimes(Path f, long mtime, long atime) throws IOException { checkPath(f); fsImpl.setTimes(f, mtime, atime); }
public void setTimes(Path p, long mtime, long atime) throws java.io.IOException { this.underlyingFs.setTimes(replaceScheme(p, this.replacementScheme, this.underlyingScheme), mtime, atime); }
@Override protected void putResourceImpl(String resPath, ContentWriter content, long ts) throws IOException { logger.trace("res path : {}. ", resPath); Path p = getRealHDFSPath(resPath); logger.trace("put resource : {}. ", p.toUri()); FSDataOutputStream out = null; try { out = fs.create(p, true); content.write(out); } catch (Exception e) { throw new IOException("Put resource fail", e); } finally { IOUtils.closeQuietly(out); fs.setTimes(p, ts, -1); } }
protected Path uploadFileIfNecessary(FileSystem localFS, Path localPath, FileSystem destFS) throws IOException { // Fast path for local FS -- DistributedCache + local JobRunner seems copy/link files automatically if (destFS.equals(localFS)) { log.debug("Skipping file upload for {} (destination filesystem {} equals local filesystem)", localPath, destFS); return localPath; } Path destPath = new Path(destFS.getHomeDirectory() + "/" + HDFS_TMP_LIB_DIR + "/" + localPath.getName()); Stats fileStats = null; try { fileStats = compareModtimes(localFS, localPath, destFS, destPath); } catch (IOException e) { log.warn("Unable to read or stat file: localPath={}, destPath={}, destFS={}", localPath, destPath, destFS); } if (!fileStats.isRemoteCopyCurrent()) { log.debug("Copying {} to {}", localPath, destPath); destFS.copyFromLocalFile(localPath, destPath); if (null != fileStats.local) { final long mtime = fileStats.local.getModificationTime(); log.debug("Setting modtime on {} to {}", destPath, mtime); destFS.setTimes(destPath, mtime, -1); // -1 means leave atime alone } } return destPath; }
fs.setTimes(dst, localFile.lastModified(), -1);
@Override public void setTimes(final Path f, final long mtime, final long atime) throws AccessControlException, FileNotFoundException, IOException { InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(f), true); res.targetFileSystem.setTimes(res.remainingPath, mtime, atime); }
/** * Moves a copied path into a persistent location managed by gobblin-distcp. This method is used when an already * copied file cannot be successfully published. In future runs, instead of re-copying the file, distcp will use the * persisted file. * * @param state {@link State} containing job information. * @param file {@link org.apache.gobblin.data.management.copy.CopyEntity} from which input {@link Path} originated. * @param path {@link Path} to persist. * @return true if persist was successful. * @throws IOException */ public boolean persistFile(State state, CopyableFile file, Path path) throws IOException { if (!this.persistDir.isPresent()) { return false; } String guid = computeGuid(state, file); Path guidPath = new Path(this.persistDir.get(), guid); if (!this.fs.exists(guidPath)) { this.fs.mkdirs(guidPath, new FsPermission(FsAction.ALL, FsAction.READ, FsAction.NONE)); } Path targetPath = new Path(guidPath, shortenPathName(file.getOrigin().getPath(), 250 - guid.length())); log.info(String.format("Persisting file %s with guid %s to location %s.", path, guid, targetPath)); if (this.fs.rename(path, targetPath)) { this.fs.setTimes(targetPath, System.currentTimeMillis(), -1); return true; } return false; }
fileSystem.setTimes(uploadPath, localCoprocessorFile.lastModified(), -1);
/** {@inheritDoc} */ @Override public void setTimes(IgfsPath path, long modificationTime, long accessTime) throws IgniteException { try { // We don't use FileSystem#getUsed() since it counts only the files // in the filesystem root, not all the files recursively. fileSystemForUser().setTimes(convert(path), modificationTime, accessTime); } catch (IOException e) { throw handleSecondaryFsError(e, "Failed set times for path: " + path); } }
/** * @throws Exception If failed. */ @Test public void testSetTimes() throws Exception { Path fsHome = new Path(primaryFsUri); final Path file = new Path(fsHome, "/heartbeatTs"); fs.create(file).close(); FileStatus status = fs.getFileStatus(file); assertTrue(status.getAccessTime() > 0); assertTrue(status.getModificationTime() > 0); long mtime = System.currentTimeMillis() - 5000; long atime = System.currentTimeMillis() - 4000; fs.setTimes(file, mtime, atime); status = fs.getFileStatus(file); assertEquals(mtime, status.getModificationTime()); assertEquals(atime, status.getAccessTime()); mtime -= 5000; fs.setTimes(file, mtime, -1); status = fs.getFileStatus(file); assertEquals(mtime, status.getModificationTime()); assertEquals(atime, status.getAccessTime()); atime -= 5000; fs.setTimes(file, -1, atime); status = fs.getFileStatus(file); assertEquals(mtime, status.getModificationTime()); assertEquals(atime, status.getAccessTime()); }
throws IOException { if (shouldPreserve(FileAttribute.TIMESTAMPS)) { target.fs.setTimes( target.path, src.stat.getModificationTime(),
fs.createNewFile(fileName); fs.setTimes(fileName, createTime - ttl - 1, -1); LOG.debug("Creating " + getFileStats(fileName, fs)); fs.createNewFile(saved); fs.setTimes(saved, createTime - ttl / 2, -1); LOG.debug("Creating " + getFileStats(saved, fs)); for (FileStatus stat : fs.listStatus(archivedHfileDir)) {
@Test public void testTTLCleaner() throws IOException, InterruptedException { FileSystem fs = UTIL.getDFSCluster().getFileSystem(); Path root = UTIL.getDataTestDirOnTestFS(); Path file = new Path(root, "file"); fs.createNewFile(file); long createTime = System.currentTimeMillis(); assertTrue("Test file not created!", fs.exists(file)); TimeToLiveHFileCleaner cleaner = new TimeToLiveHFileCleaner(); // update the time info for the file, so the cleaner removes it fs.setTimes(file, createTime - 100, -1); Configuration conf = UTIL.getConfiguration(); conf.setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 100); cleaner.setConf(conf); assertTrue("File not set deletable - check mod time:" + getFileStats(file, fs) + " with create time:" + createTime, cleaner.isFileDeletable(fs.getFileStatus(file))); }
fileSystem.setTimes(uploadPath, localCoprocessorFile.lastModified(), -1);
@Override public void setTimes(Path p, long mtime, long atime) throws IOException { try { underlyingFs.setTimes(p, mtime, atime); } catch(FSError e) { throw propagateFSError(e); } }