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
|
// 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.nodeagent;
import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixUser;
import com.yahoo.vespa.hosted.node.admin.task.util.fs.ContainerFileSystem;
import com.yahoo.vespa.hosted.node.admin.task.util.fs.ContainerPath;
import java.nio.file.Path;
import java.util.Objects;
/**
* @author freva
*/
public class PathScope {
private final ContainerFileSystem containerFs;
private final String pathToVespaHome;
private final UserScope users;
public PathScope(ContainerFileSystem containerFs, String pathToVespaHome) {
this.containerFs = Objects.requireNonNull(containerFs);
this.pathToVespaHome = Objects.requireNonNull(pathToVespaHome);
this.users = containerFs.getUserPrincipalLookupService().userScope();
}
public ContainerPath of(String pathInNode) {
return of(pathInNode, users.root());
}
public ContainerPath of(String pathInNode, UnixUser user) {
return ContainerPath.fromPathInContainer(containerFs, Path.of(pathInNode), user);
}
public ContainerPath underVespaHome(String relativePath) {
if (relativePath.startsWith("/"))
throw new IllegalArgumentException("Expected a relative path to the Vespa home, got: " + relativePath);
return ContainerPath.fromPathInContainer(containerFs, Path.of(pathToVespaHome, relativePath), users.vespa());
}
public ContainerPath fromPathOnHost(Path pathOnHost) {
return ContainerPath.fromPathOnHost(containerFs, pathOnHost, users.root());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PathScope pathScope = (PathScope) o;
return containerFs.equals(pathScope.containerFs) && pathToVespaHome.equals(pathScope.pathToVespaHome) && users.equals(pathScope.users);
}
@Override
public int hashCode() {
return Objects.hash(containerFs, pathToVespaHome, users);
}
}
|