@Override public UfsFileStatus getFileStatus(String path) throws IOException { Path tPath = new Path(path); FileSystem hdfs = getFs(); FileStatus fs = hdfs.getFileStatus(tPath); String contentHash = UnderFileSystemUtils.approximateContentHash(fs.getLen(), fs.getModificationTime()); return new UfsFileStatus(path, contentHash, fs.getLen(), fs.getModificationTime(), fs.getOwner(), fs.getGroup(), fs.getPermission().toShort()); }
@Override public UfsFileStatus getFileStatus(String path) throws IOException { String tpath = stripPath(path); File file = new File(tpath); PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class); String contentHash = UnderFileSystemUtils.approximateContentHash(file.length(), file.lastModified()); return new UfsFileStatus(path, contentHash, file.length(), file.lastModified(), attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions())); }
@Override public UfsStatus[] listStatus(String path) throws IOException { path = stripPath(path); File file = new File(path); File[] files = file.listFiles(); if (files != null) { UfsStatus[] rtn = new UfsStatus[files.length]; int i = 0; for (File f : files) { // TODO(adit): do we need extra call for attributes? PosixFileAttributes attr = Files.readAttributes(Paths.get(f.getPath()), PosixFileAttributes.class); short mode = FileUtils.translatePosixPermissionToMode(attr.permissions()); UfsStatus retStatus; if (f.isDirectory()) { retStatus = new UfsDirectoryStatus(f.getName(), attr.owner().getName(), attr.group().getName(), mode, f.lastModified()); } else { String contentHash = UnderFileSystemUtils.approximateContentHash(f.length(), f.lastModified()); retStatus = new UfsFileStatus(f.getName(), contentHash, f.length(), f.lastModified(), attr.owner().getName(), attr.group().getName(), mode); } rtn[i++] = retStatus; } return rtn; } else { return null; } }
@Override public UfsStatus getStatus(String path) throws IOException { String tpath = stripPath(path); File file = new File(tpath); PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class); if (file.isFile()) { // Return file status. String contentHash = UnderFileSystemUtils.approximateContentHash(file.length(), file.lastModified()); return new UfsFileStatus(path, contentHash, file.length(), file.lastModified(), attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions())); } // Return directory status. return new UfsDirectoryStatus(path, attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions()), file.lastModified()); }
@Override public UfsStatus getStatus(String path) throws IOException { Path tPath = new Path(path); FileSystem hdfs = getFs(); FileStatus fs = hdfs.getFileStatus(tPath); if (!fs.isDir()) { // Return file status. String contentHash = UnderFileSystemUtils.approximateContentHash(fs.getLen(), fs.getModificationTime()); return new UfsFileStatus(path, contentHash, fs.getLen(), fs.getModificationTime(), fs.getOwner(), fs.getGroup(), fs.getPermission().toShort()); } // Return directory status. return new UfsDirectoryStatus(path, fs.getOwner(), fs.getGroup(), fs.getPermission().toShort(), fs.getModificationTime()); }
@Override @Nullable public UfsStatus[] listStatus(String path) throws IOException { FileStatus[] files = listStatusInternal(path); if (files == null) { return null; } UfsStatus[] rtn = new UfsStatus[files.length]; int i = 0; for (FileStatus status : files) { // only return the relative path, to keep consistent with java.io.File.list() UfsStatus retStatus; if (!status.isDir()) { String contentHash = UnderFileSystemUtils .approximateContentHash(status.getLen(), status.getModificationTime()); retStatus = new UfsFileStatus(status.getPath().getName(), contentHash, status.getLen(), status.getModificationTime(), status.getOwner(), status.getGroup(), status.getPermission().toShort()); } else { retStatus = new UfsDirectoryStatus(status.getPath().getName(), status.getOwner(), status.getGroup(), status.getPermission().toShort(), status.getModificationTime()); } rtn[i++] = retStatus; } return rtn; }