Skip to content

Commit

Permalink
Remove unnecessary condition
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Jan 30, 2024
1 parent 0f889b4 commit c0cd6d6
Showing 1 changed file with 27 additions and 25 deletions.
Expand Up @@ -92,29 +92,7 @@ private Optional<WorkspaceResult> loadImmutableWorkspaceIfExists(UnitOfWork work
FileSystemLocationSnapshot workspaceSnapshot = fileSystemAccess.read(immutableLocation.getAbsolutePath());
switch (workspaceSnapshot.getType()) {
case Directory:
ImmutableSortedMap<String, FileSystemSnapshot> outputSnapshots = outputSnapshotter.snapshotOutputs(work, immutableLocation);

// Verify output hashes
ImmutableListMultimap<String, HashCode> outputHashes = calculateOutputHashes(outputSnapshots);
ImmutableWorkspaceMetadata metadata = workspaceMetadataStore.loadWorkspaceMetadata(immutableLocation);
if (!metadata.getOutputPropertyHashes().equals(outputHashes)) {
throw new IllegalStateException(
"Immutable workspace contents have been modified: " + immutableLocation.getAbsolutePath() + ". " +
"These workspace directories are not supposed to be modified once they are created. " +
"Deleting the directory in question can allow the content to be recreated.");
}

OriginMetadata originMetadata = metadata.getOriginMetadata();
ExecutionOutputState afterExecutionOutputState = new DefaultExecutionOutputState(true, outputSnapshots, originMetadata, true);
return Optional.of(
new WorkspaceResult(
CachingResult.shortcutResult(
Duration.ZERO,
Execution.skipped(UP_TO_DATE, work),
afterExecutionOutputState,
null,
originMetadata),
immutableLocation));
return Optional.of(loadImmutableWorkspace(work, immutableLocation));
case RegularFile:
throw new IllegalStateException(
"Immutable workspace is occupied by a file: " + immutableLocation.getAbsolutePath() + ". " +
Expand All @@ -126,6 +104,31 @@ private Optional<WorkspaceResult> loadImmutableWorkspaceIfExists(UnitOfWork work
}
}

private WorkspaceResult loadImmutableWorkspace(UnitOfWork work, File immutableLocation) {
ImmutableSortedMap<String, FileSystemSnapshot> outputSnapshots = outputSnapshotter.snapshotOutputs(work, immutableLocation);

// Verify output hashes
ImmutableListMultimap<String, HashCode> outputHashes = calculateOutputHashes(outputSnapshots);
ImmutableWorkspaceMetadata metadata = workspaceMetadataStore.loadWorkspaceMetadata(immutableLocation);
if (!metadata.getOutputPropertyHashes().equals(outputHashes)) {
throw new IllegalStateException(
"Immutable workspace contents have been modified: " + immutableLocation.getAbsolutePath() + ". " +
"These workspace directories are not supposed to be modified once they are created. " +
"Deleting the directory in question can allow the content to be recreated.");
}

OriginMetadata originMetadata = metadata.getOriginMetadata();
ExecutionOutputState afterExecutionOutputState = new DefaultExecutionOutputState(true, outputSnapshots, originMetadata, true);
return new WorkspaceResult(
CachingResult.shortcutResult(
Duration.ZERO,
Execution.skipped(UP_TO_DATE, work),
afterExecutionOutputState,
null,
originMetadata),
immutableLocation);
}

private WorkspaceResult executeInTemporaryWorkspace(UnitOfWork work, C context, ImmutableWorkspace workspace) {
return workspace.withTemporaryWorkspace(temporaryWorkspace -> {
WorkspaceContext workspaceContext = new WorkspaceContext(context, temporaryWorkspace, null, true);
Expand Down Expand Up @@ -209,8 +212,7 @@ public WorkspaceResult executeMoveOr(Function<FileSystemException, WorkspaceResu
if (immutableLocation.isDirectory()) {
LOGGER.debug("Could not move temporary workspace ({}) to immutable location ({}), assuming it was moved in place concurrently",
temporaryWorkspace.getAbsolutePath(), immutableLocation.getAbsolutePath(), moveWorkspaceException);
WorkspaceResult existingImmutableResult = loadImmutableWorkspaceIfExists(work, immutableLocation)
.orElseThrow(() -> unableToMoveBecause(new IOException("Immutable workspace gone missing")));
WorkspaceResult existingImmutableResult = loadImmutableWorkspace(work, immutableLocation);
removeTemporaryWorkspace();
return existingImmutableResult;
} else {
Expand Down

0 comments on commit c0cd6d6

Please sign in to comment.