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);...@@ -18,7 +18,6 @@ const BASE64_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);
18pub const File = struct {18pub const File = struct {
19 path: ?[]const u8,19 path: ?[]const u8,
20 stat: fs.File.Stat,20 stat: fs.File.Stat,
21 file_handle: os.fd_t,
22 bin_digest: [BIN_DIGEST_LEN]u8,21 bin_digest: [BIN_DIGEST_LEN]u8,
23 contents: ?[]const u8,22 contents: ?[]const u8,
2423
...@@ -169,12 +168,10 @@ pub const CacheHash = struct {...@@ -169,12 +168,10 @@ pub const CacheHash = struct {
169 }168 }
170169
171 var iter = mem.tokenize(line, " ");170 var iter = mem.tokenize(line, " ");
172 const file_handle_str = iter.next() orelse return error.InvalidFormat;
173 const mtime_nsec_str = iter.next() orelse return error.InvalidFormat;171 const mtime_nsec_str = iter.next() orelse return error.InvalidFormat;
174 const digest_str = iter.next() orelse return error.InvalidFormat;172 const digest_str = iter.next() orelse return error.InvalidFormat;
175 const file_path = iter.rest();173 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;
178 cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat;175 cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat;
179 base64_decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat;176 base64_decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat;
180177
...@@ -191,11 +188,16 @@ pub const CacheHash = struct {...@@ -191,11 +188,16 @@ pub const CacheHash = struct {
191 return error.CacheUnavailable;188 return error.CacheUnavailable;
192 };189 };
193 defer this_file.close();190 defer this_file.close();
194 cache_hash_file.stat = try this_file.stat();191
195 // TODO: check mtime192 const actual_stat = try this_file.stat();
196 if (false) {} else {193 const mtime_matches = actual_stat.mtime == cache_hash_file.stat.mtime;
194
195 // TODO: check inode
196 if (!mtime_matches) {
197 self.manifest_dirty = true;197 self.manifest_dirty = true;
198198
199 cache_hash_file.stat = actual_stat;
200
199 // TODO: check for problematic timestamp201 // TODO: check for problematic timestamp
200202
201 var actual_digest: [BIN_DIGEST_LEN]u8 = undefined;203 var actual_digest: [BIN_DIGEST_LEN]u8 = undefined;
...@@ -277,7 +279,7 @@ pub const CacheHash = struct {...@@ -277,7 +279,7 @@ pub const CacheHash = struct {
277279
278 for (self.files.toSlice()) |file| {280 for (self.files.toSlice()) |file| {
279 base64_encoder.encode(encoded_digest[0..], &file.bin_digest);281 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 });
281 }283 }
282284
283 try self.manifest_file.?.seekTo(0);285 try self.manifest_file.?.seekTo(0);