blob: ca81669adccec867c0c0dde3fb80de132a3a95fe (
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
|
// 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.file;
import java.util.Optional;
// @ThreadUnsafe
public class FileAttributesCache {
private final UnixPath path;
private Optional<FileAttributes> attributes = Optional.empty();
public FileAttributesCache(UnixPath path) {
this.path = path;
}
public Optional<FileAttributes> get() {
if (attributes.isEmpty()) {
attributes = path.getAttributesIfExists();
}
return attributes;
}
public FileAttributes getOrThrow() {
return get().orElseThrow();
}
public Optional<FileAttributes> forceGet() {
attributes = Optional.empty();
return get();
}
}
|