@Override public long getAccessTime() { return fileStatus.getAccessTime(); }
@Override public long accessTime() { return status.getAccessTime(); }
@Override public long getAccessTime() { return myFs.getAccessTime(); }
@Override public long getAccessTime() { return realStatus.getAccessTime(); }
public int compare(PathData o1, PathData o2) { Long o1Time = (isUseAtime() ? o1.stat.getAccessTime() : o1.stat.getModificationTime()); Long o2Time = (isUseAtime() ? o2.stat.getAccessTime() : o2.stat.getModificationTime()); return o2Time.compareTo(o1Time) * (isOrderReverse() ? -1 : 1); } };
public static void cleanHistoryFile(FileSystem fs,Path dataPath) throws IOException { long cleantimes=System.currentTimeMillis()-1000l*3600*24*7; if(!fs.exists(dataPath)) { return ; } FileStatus[] list=fs.listStatus(dataPath); if(list==null) { return ; } ArrayList<Path> toremove=new ArrayList<Path>(); for(FileStatus s:list) { long lasttimes=Math.max(s.getAccessTime(), s.getModificationTime()); if(lasttimes<cleantimes) { toremove.add(s.getPath()); } } for(Path p:toremove) { System.out.println("clean :"+p.toString()); fs.delete(p, true); } }
/** * Returns a string representation of a Hadoop {@link FileStatus}. * * @param fs Hadoop {@link FileStatus} * @return its string representation */ public static String toStringHadoopFileStatus(FileStatus fs) { StringBuilder sb = new StringBuilder(); sb.append("HadoopFileStatus: Path: ").append(fs.getPath()); sb.append(" , Length: ").append(fs.getLen()); // Use isDir instead of isDirectory for compatibility with hadoop 1. sb.append(" , IsDir: ").append(fs.isDir()); sb.append(" , BlockReplication: ").append(fs.getReplication()); sb.append(" , BlockSize: ").append(fs.getBlockSize()); sb.append(" , ModificationTime: ").append(fs.getModificationTime()); sb.append(" , AccessTime: ").append(fs.getAccessTime()); sb.append(" , Permission: ").append(fs.getPermission()); sb.append(" , Owner: ").append(fs.getOwner()); sb.append(" , Group: ").append(fs.getGroup()); return sb.toString(); }
/** * @param file to check * @return loggable information about the file */ private String getFileStats(Path file, FileSystem fs) throws IOException { FileStatus status = fs.getFileStatus(file); return "File" + file + ", mtime:" + status.getModificationTime() + ", atime:" + status.getAccessTime(); }
private void processDir(FileStatus status, FileSystem fs, FileData fd) throws IOException { long accessTime = status.getAccessTime(); long updateTime = status.getModificationTime(); if (accessTime > fd.lastAccessTime) { fd.minFileSize = fileLen; accessTime = currentStatus.getAccessTime(); updateTime = currentStatus.getModificationTime(); if (accessTime > fd.lastAccessTime) {
private FileStatus cloneStatus() throws IOException { return new FileStatus(status.getLen(), status.isDirectory(), status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), null, null, null, status.isSymlink() ? status.getSymlink() : null, status.getPath()); } }
/** * Copy constructor. * * @param other FileStatus to copy */ public FileStatus(FileStatus other) throws IOException { // It's important to call the getters here instead of directly accessing the // members. Subclasses like ViewFsFileStatus can override the getters. this(other.getLen(), other.isDirectory(), other.getReplication(), other.getBlockSize(), other.getModificationTime(), other.getAccessTime(), other.getPermission(), other.getOwner(), other.getGroup(), (other.isSymlink() ? other.getSymlink() : null), other.getPath()); }
protected FileStatus swizzleFileStatus(FileStatus orig, boolean isParam) { FileStatus ret = new FileStatus(orig.getLen(), orig.isDir(), orig.getReplication(), orig.getBlockSize(), orig.getModificationTime(), orig.getAccessTime(), orig.getPermission(), orig.getOwner(), orig.getGroup(), isParam ? swizzleParamPath(orig.getPath()) : swizzleReturnPath(orig.getPath())); return ret; }
/** {@inheritDoc} */ @Override public T2<Long, Long> times(String path) throws IOException { FileStatus status = get().getFileStatus(new Path(path)); return new T2<>(status.getModificationTime(), status.getAccessTime()); }
/** * Replace the scheme of the input {@link FileStatus} if it matches the string to replace. */ public static FileStatus replaceScheme(FileStatus st, String replace, String replacement) { if (replace != null && replace.equals(replacement)) { return st; } try { return new FileStatus(st.getLen(), st.isDir(), st.getReplication(), st.getBlockSize(), st.getModificationTime(), st.getAccessTime(), st.getPermission(), st.getOwner(), st.getGroup(), st.isSymlink() ? st.getSymlink() : null, replaceScheme(st.getPath(), replace, replacement)); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
public void touch(MockFile file) { if (fileStatusMap.containsKey(file)) { FileStatus fileStatus = fileStatusMap.get(file); FileStatus fileStatusNew = new FileStatus(fileStatus.getLen(), fileStatus.isDirectory(), fileStatus.getReplication(), fileStatus.getBlockSize(), fileStatus.getModificationTime() + 1, fileStatus.getAccessTime(), fileStatus.getPermission(), fileStatus.getOwner(), fileStatus.getGroup(), fileStatus.getPath()); fileStatusMap.put(file, fileStatusNew); } }
null, properties(s), s.getAccessTime(), s.getModificationTime() ) : false, properties(s), s.getAccessTime(), s.getModificationTime() );
public void touch(MockFile file) { if (fileStatusMap.containsKey(file)) { FileStatus fileStatus = fileStatusMap.get(file); FileStatus fileStatusNew = new FileStatus(fileStatus.getLen(), fileStatus.isDirectory(), fileStatus.getReplication(), fileStatus.getBlockSize(), fileStatus.getModificationTime() + 1, fileStatus.getAccessTime(), fileStatus.getPermission(), fileStatus.getOwner(), fileStatus.getGroup(), fileStatus.getPath()); fileStatusMap.put(file, fileStatusNew); } }
/** * Constructor * @param stat a file status * @param locations a file's block locations */ public LocatedFileStatus(FileStatus stat, BlockLocation[] locations) { this(stat.getLen(), stat.isDirectory(), stat.getReplication(), stat.getBlockSize(), stat.getModificationTime(), stat.getAccessTime(), stat.getPermission(), stat.getOwner(), stat.getGroup(), null, stat.getPath(), stat.hasAcl(), stat.isEncrypted(), stat.isErasureCoded(), locations); if (stat.isSymlink()) { try { setSymlink(stat.getSymlink()); } catch (IOException e) { throw new RuntimeException("Unexpected exception", e); } } }
/** * @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()); }
assertTrue(status.getAccessTime() >= now); assertTrue(status.getModificationTime() >= now); assertEquals(accessTime, status.getAccessTime()); assertEquals(modificationTime, status.getModificationTime()); assertEquals(accessTime, files[0].getAccessTime()); assertEquals(modificationTime, files[0].getModificationTime());