use of java.nio.file.attribute.PosixFileAttributes in project cryptofs by cryptomator.
the class CryptoFileAttributeProviderTest method testReadPosixAttributes.
@Test
public void testReadPosixAttributes() throws IOException {
CryptoFileAttributeProvider prov = new CryptoFileAttributeProvider(cryptor);
PosixFileAttributes attr = prov.readAttributes(ciphertextFilePath, PosixFileAttributes.class);
Assert.assertTrue(attr instanceof PosixFileAttributes);
}
use of java.nio.file.attribute.PosixFileAttributes in project pravega by pravega.
the class FileSystemStorage method doGetStreamSegmentInfo.
protected SegmentProperties doGetStreamSegmentInfo(String streamSegmentName) throws IOException {
long traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName);
PosixFileAttributes attrs = Files.readAttributes(Paths.get(config.getRoot(), streamSegmentName), PosixFileAttributes.class);
StreamSegmentInformation information = StreamSegmentInformation.builder().name(streamSegmentName).length(attrs.size()).sealed(!(attrs.permissions().contains(OWNER_WRITE))).lastModified(new ImmutableDate(attrs.creationTime().toMillis())).build();
LoggerHelpers.traceLeave(log, "getStreamSegmentInfo", traceId, streamSegmentName);
return information;
}
use of java.nio.file.attribute.PosixFileAttributes in project jimfs by google.
the class PosixAttributeProviderTest method testAttributes.
@Test
public void testAttributes() {
PosixFileAttributes attrs = provider.readAttributes(file);
assertThat(attrs.permissions()).isEqualTo(PosixFilePermissions.fromString("rw-r--r--"));
assertThat(attrs.group()).isEqualTo(createGroupPrincipal("group"));
assertThat(attrs.fileKey()).isEqualTo(0);
}
use of java.nio.file.attribute.PosixFileAttributes in project jimfs by google.
the class PosixAttributeProviderTest method testView.
@Test
public void testView() throws IOException {
file.setAttribute("owner", "owner", createUserPrincipal("user"));
PosixFileAttributeView view = provider.view(fileLookup(), ImmutableMap.of("basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS), "owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
assertNotNull(view);
assertThat(view.name()).isEqualTo("posix");
assertThat(view.getOwner()).isEqualTo(createUserPrincipal("user"));
PosixFileAttributes attrs = view.readAttributes();
assertThat(attrs.fileKey()).isEqualTo(0);
assertThat(attrs.owner()).isEqualTo(createUserPrincipal("user"));
assertThat(attrs.group()).isEqualTo(createGroupPrincipal("group"));
assertThat(attrs.permissions()).isEqualTo(PosixFilePermissions.fromString("rw-r--r--"));
view.setOwner(createUserPrincipal("root"));
assertThat(view.getOwner()).isEqualTo(createUserPrincipal("root"));
assertThat(file.getAttribute("owner", "owner")).isEqualTo(createUserPrincipal("root"));
view.setGroup(createGroupPrincipal("root"));
assertThat(view.readAttributes().group()).isEqualTo(createGroupPrincipal("root"));
assertThat(file.getAttribute("posix", "group")).isEqualTo(createGroupPrincipal("root"));
view.setPermissions(PosixFilePermissions.fromString("rwx------"));
assertThat(view.readAttributes().permissions()).isEqualTo(PosixFilePermissions.fromString("rwx------"));
assertThat(file.getAttribute("posix", "permissions")).isEqualTo(PosixFilePermissions.fromString("rwx------"));
}
use of java.nio.file.attribute.PosixFileAttributes in project n2a by frothga.
the class SshFileSystemProvider method readAttributes.
public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
Map<String, Object> result = new HashMap<String, Object>();
PosixFileAttributes pfa = new SshFileAttributeView((SshPath) path, options).readAttributes();
for (String a : attributes.split(",")) {
if (a.contains(":"))
a = a.split(":", -1)[1];
switch(a) {
case "creationTime":
result.put(a, pfa.creationTime());
break;
case "lastModifiedTime":
case "lastChangedTime":
result.put(a, pfa.lastModifiedTime());
break;
case "lastAccessTime":
result.put(a, pfa.lastAccessTime());
break;
case "owner":
result.put(a, pfa.owner());
break;
case "group":
result.put(a, pfa.group());
break;
case "permissions":
result.put(a, pfa.permissions());
break;
case "size":
result.put(a, pfa.size());
break;
case "fileKey":
result.put(a, pfa.fileKey());
break;
case "isRegularFile":
result.put(a, pfa.isRegularFile());
break;
case "isDirectory":
result.put(a, pfa.isDirectory());
break;
case "isSymbolicLink":
result.put(a, pfa.isSymbolicLink());
break;
case "isOther":
result.put(a, pfa.isOther());
}
}
return result;
}
Aggregations