Skip to content

Commit

Permalink
Create fixed order on input files.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Jul 28, 2024
1 parent a150b48 commit b28eb0a
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Stream;

public final class TaskHasher {
Expand Down Expand Up @@ -43,17 +44,26 @@ private void hash(TaskInputs inputs) throws IOException {
hasher.put(value, false); //We skin unknown types (mostly file collections)
});

final Set<File> inputFiles = new HashSet<>();

for (File file : inputs.getFiles()) {
try (Stream<Path> pathStream = Files.walk(file.toPath())) {
for (Path path : pathStream.filter(Files::isRegularFile).toList()) {
logger.debug("Hashing task input file: " + path.toAbsolutePath());
hasher.putString(path.getFileName().toString());
final HashCode code = hashFunction.hashFile(path.toFile());
logger.debug("Hashing task input file hash: " + code);
hasher.putHash(code);
inputFiles.add(path.toFile());
}
}
}

final List<File> files = new ArrayList<>(inputFiles);
files.sort(Comparator.comparing(File::getAbsolutePath));

for (File file : files) {
logger.debug("Hashing task input file: " + file.getAbsolutePath());
hasher.putString(file.getName());
final HashCode code = hashFunction.hashFile(file);
logger.debug("Hashing task input file hash: " + code);
hasher.putHash(code);
}
}

public HashCode create() throws IOException {
Expand Down

0 comments on commit b28eb0a

Please sign in to comment.