use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class LocalUnderFileSystem method listStatus.
@Override
public UfsStatus[] listStatus(String path) throws IOException {
path = stripPath(path);
File file = new File(path);
// By default, exists follows symlinks. If the symlink is invalid .exists() returns false
File[] files = mSkipBrokenSymlinks ? file.listFiles(File::exists) : 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, mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
}
rtn[i++] = retStatus;
}
return rtn;
} else {
return null;
}
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class CephFSUnderFileSystem method getFileStatus.
/**
* Gets stat information on a file. This does not fill owner or group, as
* Ceph's support for these is a bit different.
*
* @param path The path to stat
* @return FileStatus object containing the stat information
* @throws FileNotFoundException if the path could not be resolved
*/
@Override
public UfsFileStatus getFileStatus(String path) throws IOException {
path = stripPath(path);
CephStat stat = new CephStat();
lstat(path, stat);
String contentHash = UnderFileSystemUtils.approximateContentHash(stat.size, stat.m_time);
return new UfsFileStatus(path, contentHash, stat.size, stat.m_time, "", "", (short) stat.mode);
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class UnderFileSystemCommonOperations method createThenGetExistingStatusTest.
/**
* Test for getting existing status.
*/
@RelatedS3Operations(operations = {})
public void createThenGetExistingStatusTest() throws IOException {
String testFile = PathUtils.concatPath(mTopLevelTestDirectory, "testFile");
createTestBytesFile(testFile);
UfsStatus status = mUfs.getExistingStatus(testFile);
if (!(status instanceof UfsFileStatus)) {
throw new IOException("Failed to get ufs file status");
}
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class WebUnderFileSystem method getStatus.
/**
* Get the file status of a http url.
*
* @param path the http url
* @param fileName the file name
* @return a UfsStatus object related to the http url
*/
private UfsStatus getStatus(String path, String fileName) throws IOException {
long contentLength = 0;
long lastModified = new Date().getTime();
Header[] headers = HttpUtils.head(path, mTimeout);
if (headers == null) {
throw new IOException("Failed to getStatus: " + path);
}
for (Header header : headers) {
String headerName = header.getName();
if (headerName.equalsIgnoreCase("Content-Length")) {
contentLength = Long.parseLong(header.getValue());
} else if (headerName.equalsIgnoreCase("Last-Modified")) {
lastModified = parseTimestamp(header.getValue(), mUfsConf.getString(PropertyKey.UNDERFS_WEB_HEADER_LAST_MODIFIED));
}
}
if (isFile(path)) {
// Return file status.
String contentHash = UnderFileSystemUtils.approximateContentHash(contentLength, lastModified);
return new UfsFileStatus(fileName == null ? path : fileName, contentHash, contentLength, lastModified, "", "", (short) 288, mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
}
// Return directory status.
return new UfsDirectoryStatus(fileName == null ? path : fileName, "", "", (short) 800, lastModified);
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class HdfsUnderFileSystem method getStatus.
@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(), fs.getBlockSize());
}
// Return directory status.
return new UfsDirectoryStatus(path, fs.getOwner(), fs.getGroup(), fs.getPermission().toShort(), fs.getModificationTime());
}
Aggregations