diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-03 16:50:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-03 16:50:29 -0500 |
| commit | 81fa31c05456facea1d1963a1e7f665351fb248d (patch) | |
| tree | 8ea6dba0c5b8ec9e8ba9cdff48189da68c198dfd /src/Cache.zig | |
| parent | 850b053ea6b7d6f0f5e0e8dbcf37080ca012024f (diff) | |
| parent | d94303be2bcee33e7efba22a186fd06eaa809707 (diff) | |
| download | zig-81fa31c05456facea1d1963a1e7f665351fb248d.tar.gz zig-81fa31c05456facea1d1963a1e7f665351fb248d.zip | |
Merge pull request #10451 from ziglang/cache-mode
stage2: introduce CacheMode
Diffstat (limited to 'src/Cache.zig')
| -rw-r--r-- | src/Cache.zig | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/Cache.zig b/src/Cache.zig index 94ad947f69..a5995f64ea 100644 --- a/src/Cache.zig +++ b/src/Cache.zig @@ -47,10 +47,16 @@ pub const hasher_init: Hasher = Hasher.init(&[_]u8{0} ** Hasher.key_length); pub const File = struct { path: ?[]const u8, max_file_size: ?usize, - stat: fs.File.Stat, + stat: Stat, bin_digest: BinDigest, contents: ?[]const u8, + pub const Stat = struct { + inode: fs.File.INode, + size: u64, + mtime: i128, + }; + pub fn deinit(self: *File, allocator: Allocator) void { if (self.path) |owned_slice| { allocator.free(owned_slice); @@ -424,7 +430,11 @@ pub const Manifest = struct { if (!size_match or !mtime_match or !inode_match) { self.manifest_dirty = true; - cache_hash_file.stat = actual_stat; + cache_hash_file.stat = .{ + .size = actual_stat.size, + .mtime = actual_stat.mtime, + .inode = actual_stat.inode, + }; if (self.isProblematicTimestamp(cache_hash_file.stat.mtime)) { // The actual file has an unreliable timestamp, force it to be hashed @@ -530,7 +540,12 @@ pub const Manifest = struct { const file = try fs.cwd().openFile(ch_file.path.?, .{}); defer file.close(); - ch_file.stat = try file.stat(); + const actual_stat = try file.stat(); + ch_file.stat = .{ + .size = actual_stat.size, + .mtime = actual_stat.mtime, + .inode = actual_stat.inode, + }; if (self.isProblematicTimestamp(ch_file.stat.mtime)) { // The actual file has an unreliable timestamp, force it to be hashed @@ -615,6 +630,42 @@ pub const Manifest = struct { try self.populateFileHash(new_ch_file); } + /// Like `addFilePost` but when the file contents have already been loaded from disk. + /// On success, cache takes ownership of `resolved_path`. + pub fn addFilePostContents( + self: *Manifest, + resolved_path: []const u8, + bytes: []const u8, + stat: File.Stat, + ) error{OutOfMemory}!void { + assert(self.manifest_file != null); + + const ch_file = try self.files.addOne(self.cache.gpa); + errdefer self.files.shrinkRetainingCapacity(self.files.items.len - 1); + + ch_file.* = .{ + .path = resolved_path, + .max_file_size = null, + .stat = stat, + .bin_digest = undefined, + .contents = null, + }; + + if (self.isProblematicTimestamp(ch_file.stat.mtime)) { + // The actual file has an unreliable timestamp, force it to be hashed + ch_file.stat.mtime = 0; + ch_file.stat.inode = 0; + } + + { + var hasher = hasher_init; + hasher.update(bytes); + hasher.final(&ch_file.bin_digest); + } + + self.hash.hasher.update(&ch_file.bin_digest); + } + pub fn addDepFilePost(self: *Manifest, dir: fs.Dir, dep_file_basename: []const u8) !void { assert(self.manifest_file != null); |
