use of org.gradle.internal.snapshot.RegularFileSnapshot in project gradle by gradle.
the class FileSystemSnapshotSerializer method read.
@Override
public FileSystemSnapshot read(Decoder decoder) throws Exception {
SnapshotStack stack = new SnapshotStack();
stack.push();
Deque<String> pathTracker = new ArrayDeque<>();
while (true) {
EntryType type = readEntryType(decoder);
if (type == EntryType.END) {
break;
}
if (type != EntryType.DIR_CLOSE) {
String path = decoder.readString();
String internedPath = stringInterner.intern(path);
pathTracker.addLast(internedPath);
if (type == EntryType.DIR_OPEN) {
stack.push();
continue;
}
}
String internedAbsolutePath;
String internedName;
String path = pathTracker.removeLast();
if (pathTracker.isEmpty()) {
internedAbsolutePath = path;
internedName = stringInterner.intern(PathUtil.getFileName(internedAbsolutePath));
} else {
internedAbsolutePath = stringInterner.intern(toAbsolutePath(pathTracker, path));
internedName = path;
}
FileMetadata.AccessType accessType = readAccessType(decoder);
switch(type) {
case REGULAR_FILE:
HashCode contentHash = readHashCode(decoder);
long lastModified = decoder.readSmallLong();
long length = decoder.readSmallLong();
stack.add(new RegularFileSnapshot(internedAbsolutePath, internedName, contentHash, DefaultFileMetadata.file(lastModified, length, accessType)));
break;
case MISSING:
stack.add(new MissingFileSnapshot(internedAbsolutePath, internedName, accessType));
break;
case DIR_CLOSE:
HashCode merkleHash = readHashCode(decoder);
List<FileSystemLocationSnapshot> children = stack.pop();
stack.add(new DirectorySnapshot(internedAbsolutePath, internedName, accessType, merkleHash, children));
break;
default:
throw new AssertionError();
}
}
return CompositeFileSystemSnapshot.of(stack.pop());
}
use of org.gradle.internal.snapshot.RegularFileSnapshot in project gradle by gradle.
the class IgnoredPathFingerprintingStrategy method collectFingerprints.
@Override
public Map<String, FileSystemLocationFingerprint> collectFingerprints(FileSystemSnapshot roots) {
ImmutableMap.Builder<String, FileSystemLocationFingerprint> builder = ImmutableMap.builder();
HashSet<String> processedEntries = new HashSet<>();
roots.accept(snapshot -> {
snapshot.accept(new FileSystemLocationSnapshotVisitor() {
@Override
public void visitRegularFile(RegularFileSnapshot fileSnapshot) {
visitNonDirectoryEntry(snapshot);
}
@Override
public void visitMissing(MissingFileSnapshot missingSnapshot) {
visitNonDirectoryEntry(snapshot);
}
private void visitNonDirectoryEntry(FileSystemLocationSnapshot snapshot) {
String absolutePath = snapshot.getAbsolutePath();
if (processedEntries.add(absolutePath)) {
HashCode normalizedContentHash = getNormalizedContentHash(snapshot, normalizedContentHasher);
if (normalizedContentHash != null) {
builder.put(absolutePath, IgnoredPathFileSystemLocationFingerprint.create(snapshot.getType(), normalizedContentHash));
}
}
}
});
return SnapshotVisitResult.CONTINUE;
});
return builder.build();
}
use of org.gradle.internal.snapshot.RegularFileSnapshot in project gradle by gradle.
the class FileSystemSnapshotBuilder method addFile.
public void addFile(File file, String[] segments, String fileName, FileMetadata metadata) {
checkNoRootFileSnapshot("another root file", file);
HashCode contentHash = fileHasher.hash(file, metadata.getLength(), metadata.getLastModified());
RegularFileSnapshot fileSnapshot = new RegularFileSnapshot(stringInterner.intern(file.getAbsolutePath()), fileName, contentHash, metadata);
if (segments.length == 0) {
rootFileSnapshot = fileSnapshot;
} else {
DirectoryBuilder rootDir = getOrCreateRootDir(file, segments);
rootDir.addFile(segments, 0, fileSnapshot);
}
}
use of org.gradle.internal.snapshot.RegularFileSnapshot in project gradle by gradle.
the class TarBuildCacheEntryPacker method unpackDirectoryTree.
@Nullable
private TarArchiveEntry unpackDirectoryTree(TarArchiveInputStream input, TarArchiveEntry rootEntry, Map<String, FileSystemLocationSnapshot> snapshots, AtomicLong entries, File treeRoot, String treeName) throws IOException {
RelativePathParser parser = new RelativePathParser(rootEntry.getName());
DirectorySnapshotBuilder builder = MerkleDirectorySnapshotBuilder.noSortingRequired();
builder.enterDirectory(DIRECT, stringInterner.intern(treeRoot.getAbsolutePath()), stringInterner.intern(treeRoot.getName()), INCLUDE_EMPTY_DIRS);
TarArchiveEntry entry;
while ((entry = input.getNextTarEntry()) != null) {
boolean isDir = entry.isDirectory();
boolean outsideOfRoot = parser.nextPath(entry.getName(), isDir, builder::leaveDirectory);
if (outsideOfRoot) {
break;
}
entries.incrementAndGet();
File file = new File(treeRoot, parser.getRelativePath());
if (isDir) {
FileUtils.forceMkdir(file);
chmodUnpackedFile(entry, file);
String internedAbsolutePath = stringInterner.intern(file.getAbsolutePath());
String internedName = stringInterner.intern(parser.getName());
builder.enterDirectory(DIRECT, internedAbsolutePath, internedName, INCLUDE_EMPTY_DIRS);
} else {
RegularFileSnapshot fileSnapshot = unpackFile(input, entry, file, parser.getName());
builder.visitLeafElement(fileSnapshot);
}
}
parser.exitToRoot(builder::leaveDirectory);
builder.leaveDirectory();
snapshots.put(treeName, builder.getResult());
return entry;
}
Aggregations