Search in sources :

Example 21 with PosixFileAttributes

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);
}
Also used : PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) Test(org.junit.Test)

Example 22 with 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;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ImmutableDate(io.pravega.common.util.ImmutableDate) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes)

Example 23 with PosixFileAttributes

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);
}
Also used : PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) Test(org.junit.Test)

Example 24 with PosixFileAttributes

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------"));
}
Also used : PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView) Test(org.junit.Test)

Example 25 with PosixFileAttributes

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;
}
Also used : HashMap(java.util.HashMap) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes)

Aggregations

PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)37 Path (java.nio.file.Path)17 IOException (java.io.IOException)13 Test (org.junit.Test)13 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)11 File (java.io.File)8 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)8 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)6 FileTime (java.nio.file.attribute.FileTime)5 HashMap (java.util.HashMap)5 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 DosFileAttributes (java.nio.file.attribute.DosFileAttributes)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 UfsDirectoryStatus (alluxio.underfs.UfsDirectoryStatus)3 UfsFileStatus (alluxio.underfs.UfsFileStatus)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3