aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystem.java
blob: 3329a646671172156f44db482252aa496b413ca5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.fs;

import com.yahoo.vespa.hosted.node.admin.nodeagent.UserScope;

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.WatchService;
import java.util.Set;

/**
 * @author freva
 */
public class ContainerFileSystem extends FileSystem {

    private final ContainerFileSystemProvider containerFsProvider;
    private final Path containerRootOnHost;

    ContainerFileSystem(ContainerFileSystemProvider containerFsProvider, Path containerRootOnHost) {
        this.containerFsProvider = containerFsProvider;
        this.containerRootOnHost = containerRootOnHost;
    }

    public Path containerRootOnHost() {
        return containerRootOnHost;
    }

    public void createRoot() {
        provider().createFileSystemRoot();
    }

    @Override
    public ContainerFileSystemProvider provider() {
        return containerFsProvider;
    }

    @Override
    public boolean isOpen() {
        return true;
    }

    @Override
    public boolean isReadOnly() {
        return false;
    }

    @Override
    public String getSeparator() {
        return "/";
    }

    @Override
    public Set<String> supportedFileAttributeViews() {
        return Set.of("basic", "posix", "unix", "owner");
    }

    @Override
    public ContainerUserPrincipalLookupService getUserPrincipalLookupService() {
        return containerFsProvider.userPrincipalLookupService();
    }

    @Override
    public ContainerPath getPath(String first, String... more) {
        return ContainerPath.fromPathInContainer(this, Path.of(first, more), getUserPrincipalLookupService().userScope().root());
    }

    @Override
    public void close() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Iterable<Path> getRootDirectories() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Iterable<FileStore> getFileStores() {
        throw new UnsupportedOperationException();
    }

    @Override
    public PathMatcher getPathMatcher(String syntaxAndPattern) {
        throw new UnsupportedOperationException();
    }

    @Override
    public WatchService newWatchService() {
        throw new UnsupportedOperationException();
    }

    public static ContainerFileSystem create(Path containerStorageRoot, UserScope userScope) {
        return new ContainerFileSystemProvider(containerStorageRoot, userScope).getFileSystem(null);
    }
}