use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class HdfsUnderFileSystem method getFileStatus.
@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(), fs.getBlockSize());
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class CephFSUnderFileSystem method listStatus.
/**
* Each string is a name rather than a complete path.
*
* @param path the path to list
* @return An array with the statuses of the files and directories in the directory
* denoted by this path. The array will be empty if the directory is empty. Returns
* null if this path does not denote a directory
*/
@Override
@Nullable
public UfsStatus[] listStatus(String path) throws IOException {
path = stripPath(path);
String[] lst = listDirectory(path);
if (lst != null) {
UfsStatus[] status = new UfsStatus[lst.length];
for (int i = 0; i < status.length; i++) {
CephStat stat = new CephStat();
lstat(PathUtils.concatPath(path, lst[i]), stat);
if (!stat.isDir()) {
String contentHash = UnderFileSystemUtils.approximateContentHash(stat.size, stat.m_time);
status[i] = new UfsFileStatus(lst[i], contentHash, stat.size, stat.m_time, "", "", (short) stat.mode);
} else {
status[i] = new UfsDirectoryStatus(lst[i], "", "", (short) stat.mode);
}
}
return status;
}
return null;
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class LocalUnderFileSystem method getStatus.
@Override
public UfsStatus getStatus(String path) throws IOException {
String tpath = stripPath(path);
File file = new File(tpath);
try {
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()), mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
}
// Return directory status.
return new UfsDirectoryStatus(path, attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions()), file.lastModified());
} catch (FileSystemException e) {
throw new FileNotFoundException(e.getMessage());
}
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class LocalUnderFileSystem method getFileStatus.
@Override
public UfsFileStatus getFileStatus(String path) throws IOException {
String tpath = stripPath(path);
File file = new File(tpath);
try {
PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class);
if (attr.isDirectory()) {
throw new IOException(String.format("path %s is not a file", path));
}
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()), mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
} catch (FileSystemException e) {
throw new FileNotFoundException(e.getMessage());
}
}
use of alluxio.underfs.UfsFileStatus in project alluxio by Alluxio.
the class FileSystemMasterSyncMetadataTest method setAttributeOwnerGroupOnMetadataUpdate.
@Test
public void setAttributeOwnerGroupOnMetadataUpdate() throws Exception {
AlluxioURI ufsMount = setupMockUfsS3Mount();
String fname = "file";
AlluxioURI uri = new AlluxioURI("/mnt/local/" + fname);
short mode = ModeUtils.getUMask("0700").toShort();
// Mock dir1 ufs path
AlluxioURI filePath = ufsMount.join("file");
UfsFileStatus fileStatus = new UfsFileStatus("file", "", 0L, System.currentTimeMillis(), "owner1", "owner1", (short) 777, null, 100L);
Mockito.when(mUfs.getFingerprint(filePath.toString())).thenReturn(Fingerprint.create("s3", fileStatus).serialize());
Mockito.when(mUfs.exists(filePath.toString())).thenReturn(true);
Mockito.when(mUfs.isDirectory(filePath.toString())).thenReturn(false);
Mockito.when(mUfs.isFile(filePath.toString())).thenReturn(true);
Mockito.when(mUfs.getStatus(filePath.toString())).thenReturn(fileStatus);
List<FileInfo> f1 = mFileSystemMaster.listStatus(uri, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build())));
UfsFileStatus updatedStatus = new UfsFileStatus("file", "", 0, System.currentTimeMillis(), "owner2", "owner2", (short) 777, null, 100);
Mockito.when(mUfs.getStatus(filePath.toString())).thenReturn(updatedStatus);
Mockito.when(mUfs.getFingerprint(filePath.toString())).thenReturn(Fingerprint.create("s3", updatedStatus).serialize());
FileInfo res = mFileSystemMaster.getFileInfo(uri, GetStatusContext.mergeFrom(GetStatusPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build())));
assertEquals("owner2", res.getOwner());
assertEquals("owner2", res.getGroup());
}
Aggregations