use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class LocalUnderFileSystemTest method testBrokenSymlinkSkip.
@Test
public void testBrokenSymlinkSkip() throws IOException {
InstancedConfiguration c = new InstancedConfiguration(sConf.copyProperties());
c.set(PropertyKey.UNDERFS_LOCAL_SKIP_BROKEN_SYMLINKS, true);
mLocalUfs = UnderFileSystem.Factory.create(mLocalUfsRoot, UnderFileSystemConfiguration.defaults(c));
Path linkPath = createNonExistentSymlink();
assertTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS));
assertFalse(Files.exists(linkPath));
UfsStatus[] statuses = mLocalUfs.listStatus(mLocalUfsRoot);
assertNotNull(statuses);
assertEquals(0, statuses.length);
}
use of alluxio.underfs.UfsStatus 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.UfsStatus in project alluxio by Alluxio.
the class FileSystemAclIntegrationTest method directoryPermissionForUfs.
/**
* Tests the directory permission propagation to UFS.
*/
@Test
public void directoryPermissionForUfs() throws IOException {
// Skip non-local and non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(sUfs) || UnderFileSystemUtils.isHdfs(sUfs));
Path dir = new Path("/root/directoryPermissionForUfsDir");
sTFS.mkdirs(dir);
FileStatus fs = sTFS.getFileStatus(dir);
String defaultOwner = fs.getOwner();
Short dirMode = fs.getPermission().toShort();
FileStatus parentFs = sTFS.getFileStatus(dir.getParent());
Short parentMode = parentFs.getPermission().toShort();
UfsStatus ufsStatus = sUfs.getDirectoryStatus(PathUtils.concatPath(sUfsRoot, dir));
Assert.assertEquals(defaultOwner, ufsStatus.getOwner());
Assert.assertEquals((int) dirMode, (int) ufsStatus.getMode());
Assert.assertEquals((int) parentMode, (int) sUfs.getDirectoryStatus(PathUtils.concatPath(sUfsRoot, dir.getParent())).getMode());
short newMode = (short) 0755;
FsPermission newPermission = new FsPermission(newMode);
sTFS.setPermission(dir, newPermission);
Assert.assertEquals((int) newMode, (int) sUfs.getDirectoryStatus(PathUtils.concatPath(sUfsRoot, dir)).getMode());
}
use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class FileSystemAclIntegrationTest method changeNonexistentOwnerAndGroupForHdfs.
/**
* Test for {@link FileSystem#setOwner(Path, String, String)} with HDFS UFS. It will test
* changing both owner and group of file using TFS and propagate the change to UFS.
*/
@Test
public void changeNonexistentOwnerAndGroupForHdfs() throws Exception {
// Skip non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isHdfs(sUfs));
Path fileC = new Path("/chownfileC-hdfs");
final String testOwner = "test-user1";
final String testGroup = "test-group1";
create(sTFS, fileC);
FileStatus fs = sTFS.getFileStatus(fileC);
String defaultOwner = fs.getOwner();
String defaultGroup = fs.getGroup();
Assert.assertEquals(defaultOwner, sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileC)).getOwner());
// Group can different because HDFS user to group mapping can be different from that in Alluxio.
Assert.assertNotEquals(defaultOwner, testOwner);
Assert.assertNotEquals(defaultGroup, testGroup);
sTFS.setOwner(fileC, testOwner, testGroup);
fs = sTFS.getFileStatus(fileC);
Assert.assertEquals(testOwner, fs.getOwner());
Assert.assertEquals(testGroup, fs.getGroup());
UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileC));
Assert.assertEquals(testOwner, ufsStatus.getOwner());
Assert.assertEquals(testGroup, ufsStatus.getGroup());
}
use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class FileSystemAclIntegrationTest method swiftGetPermission.
@Test
public void swiftGetPermission() throws Exception {
Assume.assumeTrue(UnderFileSystemUtils.isSwift(sUfs));
Path fileA = new Path("/swiftGetPermissionFile");
create(sTFS, fileA);
Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, fileA)));
UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA));
Assert.assertNotEquals("", ufsStatus.getOwner());
Assert.assertNotEquals("", ufsStatus.getGroup());
Assert.assertEquals((short) 0700, ufsStatus.getMode());
}
Aggregations