| ... | @@ -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); |
| 18 | pub const File = struct { | 18 | pub 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, |
| 24 | | 23 | |
| ... | @@ -169,12 +168,10 @@ pub const CacheHash = struct { | ... | @@ -169,12 +168,10 @@ pub const CacheHash = struct { |
| 169 | } | 168 | } |
| 170 | | 169 | |
| 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(); |
| 176 | | 174 | |
| 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; |
| 180 | | 177 | |
| ... | @@ -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 mtime | 192 | 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; |
| 198 | | 198 | |
| | 199 | cache_hash_file.stat = actual_stat; |
| | 200 | |
| 199 | // TODO: check for problematic timestamp | 201 | // TODO: check for problematic timestamp |
| 200 | | 202 | |
| 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 { |
| 277 | | 279 | |
| 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 | } |
| 282 | | 284 | |
| 283 | try self.manifest_file.?.seekTo(0); | 285 | try self.manifest_file.?.seekTo(0); |