Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort DirectoryNode children to ensure validity. #8008

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import build.bazel.remote.execution.v2.Digest;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.ActionInputHelper;
import com.google.devtools.build.lib.actions.FileArtifactValue;
Expand All @@ -34,6 +35,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;

/**
Expand All @@ -46,7 +48,7 @@ interface Visitor {
void visitDirectory(PathFragment dirname, List<FileNode> files, List<DirectoryNode> dirs);
}

abstract static class Node {
abstract static class Node implements Comparable<Node> {
private final String pathSegment;

Node(String pathSegment) {
Expand All @@ -57,6 +59,11 @@ String getPathSegment() {
return pathSegment;
}

@Override
public int compareTo(Node other) {
return pathSegment.compareTo(other.pathSegment);
}

@Override
public int hashCode() {
return pathSegment.hashCode();
Expand Down Expand Up @@ -108,7 +115,7 @@ public boolean equals(Object o) {
}

static class DirectoryNode extends Node {
private final List<Node> children = new ArrayList<>();
private final SortedSet<Node> children = Sets.newTreeSet();

DirectoryNode(String pathSegment) {
super(pathSegment);
Expand Down