Search in sources :

Example 6 with AclFileAttributeView

use of java.nio.file.attribute.AclFileAttributeView in project neo4j by neo4j.

the class BootloaderCommandTestBase method addConf.

protected void addConf(Setting<?> setting, String value) {
    try {
        if (!Files.exists(confFile)) {
            Files.createDirectories(confFile.getParent());
            if (IS_OS_WINDOWS) {
                Files.createFile(confFile);
                AclFileAttributeView attrs = Files.getFileAttributeView(confFile, AclFileAttributeView.class);
                attrs.setAcl(List.of(AclEntry.newBuilder().setType(AclEntryType.ALLOW).setPrincipal(attrs.getOwner()).setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.WRITE_DATA, AclEntryPermission.READ_ATTRIBUTES, AclEntryPermission.WRITE_ATTRIBUTES, AclEntryPermission.READ_NAMED_ATTRS, AclEntryPermission.WRITE_NAMED_ATTRS, AclEntryPermission.APPEND_DATA, AclEntryPermission.READ_ACL, AclEntryPermission.SYNCHRONIZE).build()));
            } else {
                Files.createFile(confFile, PosixFilePermissions.asFileAttribute(Set.of(OWNER_READ, OWNER_WRITE)));
            }
        }
        FileUtils.writeToFile(confFile, String.format("%s=%s%n", setting.name(), value), true);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : AclFileAttributeView(java.nio.file.attribute.AclFileAttributeView) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 7 with AclFileAttributeView

use of java.nio.file.attribute.AclFileAttributeView in project jimfs by google.

the class AclAttributeProviderTest method testView.

@Test
public void testView() throws IOException {
    AclFileAttributeView view = provider.view(fileLookup(), ImmutableMap.<String, FileAttributeView>of("owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
    assertNotNull(view);
    assertThat(view.name()).isEqualTo("acl");
    assertThat(view.getAcl()).isEqualTo(defaultAcl);
    view.setAcl(ImmutableList.<AclEntry>of());
    view.setOwner(FOO);
    assertThat(view.getAcl()).isEqualTo(ImmutableList.<AclEntry>of());
    assertThat(view.getOwner()).isEqualTo(FOO);
    assertThat(file.getAttribute("acl", "acl")).isEqualTo(ImmutableList.<AclEntry>of());
}
Also used : AclFileAttributeView(java.nio.file.attribute.AclFileAttributeView) Test(org.junit.Test)

Aggregations

AclFileAttributeView (java.nio.file.attribute.AclFileAttributeView)7 Path (java.nio.file.Path)3 AclEntry (java.nio.file.attribute.AclEntry)3 UserPrincipal (java.nio.file.attribute.UserPrincipal)3 IOException (java.io.IOException)2 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)2 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)2 ArrayList (java.util.ArrayList)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLEncoder (java.net.URLEncoder)1 Files (java.nio.file.Files)1 AclEntryPermission (java.nio.file.attribute.AclEntryPermission)1 FileAttribute (java.nio.file.attribute.FileAttribute)1