aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@oath.com>2018-01-30 00:16:20 +0100
committerHåkon Hallingstad <hakon@oath.com>2018-01-30 00:16:20 +0100
commitdd6de3c18ed9f5a6d89f843b8a0835c8e8480a9d (patch)
treeba1010d94236d797fc2b27f8072674eedce9c705 /node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java
parent0e6ec009fcce1796b4d9ad0ad7accaa403221930 (diff)
Implement directory resource
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java52
1 files changed, 3 insertions, 49 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java
index d8b8aadfff7..18d2a2e3aa9 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSync.java
@@ -7,8 +7,6 @@ import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
import java.util.logging.Logger;
/**
@@ -39,58 +37,14 @@ public class FileSync {
public boolean convergeTo(TaskContext taskContext, PartialFileData partialFileData) {
FileAttributesCache currentAttributes = new FileAttributesCache(path);
- boolean modifiedSystem = false;
+ boolean modifiedSystem = maybeUpdateContent(taskContext, partialFileData.getContent(), currentAttributes);
- modifiedSystem |= maybeUpdateContent(taskContext, partialFileData.getContent(), currentAttributes);
-
- modifiedSystem |= convergeAttribute(
- taskContext,
- "owner",
- partialFileData.getOwner(),
- () -> currentAttributes.get().owner(),
- path::setOwner);
-
- modifiedSystem |= convergeAttribute(
- taskContext,
- "group",
- partialFileData.getGroup(),
- () -> currentAttributes.get().group(),
- path::setGroup);
-
- modifiedSystem |= convergeAttribute(
- taskContext,
- "permissions",
- partialFileData.getPermissions(),
- () -> currentAttributes.get().permissions(),
- path::setPermissions);
+ AttributeSync attributeSync = new AttributeSync(path.toPath()).with(partialFileData);
+ modifiedSystem |= attributeSync.converge(taskContext, currentAttributes);
return modifiedSystem;
}
- private boolean convergeAttribute(TaskContext taskContext,
- String attributeName,
- Optional<String> wantedValue,
- Supplier<String> currentValueSupplier,
- Consumer<String> valueSetter) {
- if (!wantedValue.isPresent()) {
- return false;
- }
-
- String currentValue = currentValueSupplier.get();
- if (Objects.equals(wantedValue.get(), currentValue)) {
- return false;
- } else {
- String actionDescription = String.format("Changing %s of %s from %s to %s",
- attributeName,
- path,
- currentValue,
- wantedValue.get());
- taskContext.logSystemModification(logger, actionDescription);
- valueSetter.accept(wantedValue.get());
- return true;
- }
- }
-
private boolean maybeUpdateContent(TaskContext taskContext,
Optional<String> content,
FileAttributesCache currentAttributes) {