authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-03-08 15:11:06-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
logfffd59e6c4c349993f847e7ecdeff25741a11810
tree132a0f42e8ff2f9ec026d965505d8d69fde77e41
parent21d7430696158a3aa486d620bf7251f6134af9b9

Remove file handle from CacheHash

A file handle is not the same thing as an inode index number. Eventually the inode will be checked as well, but there needs to be a way to get the inode in `std` first.

1 files changed, 9 insertions(+), 7 deletions(-)

lib/std/cache_hash.zig+9-7
......@@ -18,7 +18,6 @@ const BASE64_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);
1818pub const File = struct {
1919 path: ?[]const u8,
2020 stat: fs.File.Stat,
21 file_handle: os.fd_t,
2221 bin_digest: [BIN_DIGEST_LEN]u8,
2322 contents: ?[]const u8,
2423
......@@ -169,12 +168,10 @@ pub const CacheHash = struct {
169168 }
170169
171170 var iter = mem.tokenize(line, " ");
172 const file_handle_str = iter.next() orelse return error.InvalidFormat;
173171 const mtime_nsec_str = iter.next() orelse return error.InvalidFormat;
174172 const digest_str = iter.next() orelse return error.InvalidFormat;
175173 const file_path = iter.rest();
176174
177 cache_hash_file.file_handle = fmt.parseInt(os.fd_t, file_handle_str, 10) catch return error.InvalidFormat;
178175 cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat;
179176 base64_decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat;
180177
......@@ -191,11 +188,16 @@ pub const CacheHash = struct {
191188 return error.CacheUnavailable;
192189 };
193190 defer this_file.close();
194 cache_hash_file.stat = try this_file.stat();
195 // TODO: check mtime
196 if (false) {} else {
191
192 const actual_stat = try this_file.stat();
193 const mtime_matches = actual_stat.mtime == cache_hash_file.stat.mtime;
194
195 // TODO: check inode
196 if (!mtime_matches) {
197197 self.manifest_dirty = true;
198198
199 cache_hash_file.stat = actual_stat;
200
199201 // TODO: check for problematic timestamp
200202
201203 var actual_digest: [BIN_DIGEST_LEN]u8 = undefined;
......@@ -277,7 +279,7 @@ pub const CacheHash = struct {
277279
278280 for (self.files.toSlice()) |file| {
279281 base64_encoder.encode(encoded_digest[0..], &file.bin_digest);
280 try contents.print("{} {} {} {}\n", .{ file.file_handle, file.stat.mtime, encoded_digest[0..], file.path });
282 try contents.print("{} {} {}\n", .{ file.stat.mtime, encoded_digest[0..], file.path });
281283 }
282284
283285 try self.manifest_file.?.seekTo(0);