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.
This commit is contained in:
LeRoyce Pearson 2020-03-08 15:11:06 -06:00 committed by Andrew Kelley
parent 21d7430696
commit fffd59e6c4

View File

@ -18,7 +18,6 @@ const BASE64_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);
pub const File = struct { pub const File = struct {
path: ?[]const u8, path: ?[]const u8,
stat: fs.File.Stat, stat: fs.File.Stat,
file_handle: os.fd_t,
bin_digest: [BIN_DIGEST_LEN]u8, bin_digest: [BIN_DIGEST_LEN]u8,
contents: ?[]const u8, contents: ?[]const u8,
@ -169,12 +168,10 @@ pub const CacheHash = struct {
} }
var iter = mem.tokenize(line, " "); var iter = mem.tokenize(line, " ");
const file_handle_str = iter.next() orelse return error.InvalidFormat;
const mtime_nsec_str = iter.next() orelse return error.InvalidFormat; const mtime_nsec_str = iter.next() orelse return error.InvalidFormat;
const digest_str = iter.next() orelse return error.InvalidFormat; const digest_str = iter.next() orelse return error.InvalidFormat;
const file_path = iter.rest(); const file_path = iter.rest();
cache_hash_file.file_handle = fmt.parseInt(os.fd_t, file_handle_str, 10) catch return error.InvalidFormat;
cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat; cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat;
base64_decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat; base64_decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat;
@ -191,11 +188,16 @@ pub const CacheHash = struct {
return error.CacheUnavailable; return error.CacheUnavailable;
}; };
defer this_file.close(); defer this_file.close();
cache_hash_file.stat = try this_file.stat();
// TODO: check mtime const actual_stat = try this_file.stat();
if (false) {} else { const mtime_matches = actual_stat.mtime == cache_hash_file.stat.mtime;
// TODO: check inode
if (!mtime_matches) {
self.manifest_dirty = true; self.manifest_dirty = true;
cache_hash_file.stat = actual_stat;
// TODO: check for problematic timestamp // TODO: check for problematic timestamp
var actual_digest: [BIN_DIGEST_LEN]u8 = undefined; var actual_digest: [BIN_DIGEST_LEN]u8 = undefined;
@ -277,7 +279,7 @@ pub const CacheHash = struct {
for (self.files.toSlice()) |file| { for (self.files.toSlice()) |file| {
base64_encoder.encode(encoded_digest[0..], &file.bin_digest); base64_encoder.encode(encoded_digest[0..], &file.bin_digest);
try contents.print("{} {} {} {}\n", .{ file.file_handle, file.stat.mtime, encoded_digest[0..], file.path }); try contents.print("{} {} {}\n", .{ file.stat.mtime, encoded_digest[0..], file.path });
} }
try self.manifest_file.?.seekTo(0); try self.manifest_file.?.seekTo(0);