Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially implement cache hash API in zig #4635

Closed
wants to merge 45 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fd6bb4b
Partially implement cache hash API in zig
leroycep Mar 5, 2020
dd43235
Add `cache` method; add support for caching integers
leroycep Mar 6, 2020
d6c7948
Fix memory leak in cache_hash
leroycep Mar 6, 2020
130d51e
Support caching bools; make caching values infallible
leroycep Mar 6, 2020
6ba700d
Add filesystem base64 decoder
leroycep Mar 7, 2020
cf88f31
Use std.fs.base64_encoder in std.cache_hash
leroycep Mar 7, 2020
8c60175
Use fs.File
leroycep Mar 7, 2020
0b4067f
Rename CacheHashFile -> File
leroycep Mar 7, 2020
4bd49a5
Store fs.Dir instead of path to dir
leroycep Mar 7, 2020
0104a2c
Rename `cache` functions to `add`
leroycep Mar 7, 2020
a71b60a
Make type specific add functions
leroycep Mar 7, 2020
c3fb2be
Add slice and array support to `add` method
leroycep Mar 7, 2020
9ee0523
Rename `cache_file` -> `addFile`
leroycep Mar 7, 2020
a67bedf
Return base64 digest instead of using an out variable
leroycep Mar 7, 2020
2a04f31
Make hash digest same size as in the c API
leroycep Mar 7, 2020
6435062
Use `readAllAlloc`
leroycep Mar 7, 2020
50efd1c
Replace ArrayList in write_manifest with an array
leroycep Mar 7, 2020
f6766d1
Remove file handle from CacheHash
leroycep Mar 8, 2020
3947b2e
Remove up files created in test at end of test
leroycep Mar 8, 2020
3653268
Update cache_hash to zig master
leroycep Apr 8, 2020
4f085b0
Check if inode matches inode from manifest
leroycep Apr 8, 2020
5e44336
Remove error union from CacheHash.final
leroycep Apr 8, 2020
c3b3ee6
Remove unnecessary contents field from File
leroycep Apr 8, 2020
f630fef
Open file with exclusive lock
leroycep Apr 11, 2020
a9b0504
Check for problematic timestamps
leroycep Apr 11, 2020
31625f9
Add documentation to CacheHash API
leroycep Apr 8, 2020
2d9d71f
Put base64 alphabet into a named constant
leroycep Apr 15, 2020
b734407
Add `addFilePost` and `addFilePostFetch` functions
leroycep Apr 15, 2020
7b6016b
Make CacheHash cleanup consistent (always call `release`)
leroycep Apr 15, 2020
5487a09
Switch to using `testing.expect*` in tests
leroycep Apr 15, 2020
ce7cec2
Add test checking file changes invalidate cache
leroycep Apr 15, 2020
4204af4
Add "no file inputs" test
leroycep Apr 15, 2020
b973846
Make `CacheHash.release` return an error
leroycep Apr 15, 2020
8a8d87e
Make `addFilePost*` functions' documentation more clear
leroycep Apr 15, 2020
3d57536
Update code using deprecated ArrayList APIs
leroycep Apr 16, 2020
d207a42
Return an index from `CacheHash.addFile`
leroycep Apr 16, 2020
09e1fa0
Fix read from null pointer in CacheHash.hit
leroycep Apr 30, 2020
cb07896
Add test case for fix in previous commit
leroycep Apr 30, 2020
344a32a
Don't use `iterate` when opening manifest directory
leroycep Apr 30, 2020
9253913
Make if statement more idiomatic
leroycep Apr 30, 2020
e08edef
Change null pointer test to `addFilePost` test
leroycep May 1, 2020
b3d748f
Remove non-null assertion in `CacheHash.release()`
leroycep May 1, 2020
4a5151c
Set manifest's maximum size to Andrew's recommendation
leroycep May 1, 2020
1431e2e
Add max_file_size argument
leroycep May 2, 2020
c906e43
Fix improper initialization of CacheHashFiles
leroycep May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change null pointer test to addFilePost test
leroycep committed May 1, 2020
commit e08edef1968a59fdb9de0d340f06b45199261d3a
45 changes: 32 additions & 13 deletions lib/std/cache_hash.zig
Original file line number Diff line number Diff line change
@@ -232,7 +232,13 @@ pub const CacheHash = struct {
// reset the hash
self.blake3 = Blake3.init();
self.blake3.update(&bin_digest);

// Remove files not in the initial hash
for (self.files.items[input_file_count..]) |*file| {
file.deinit(self.alloc);
}
try self.files.resize(input_file_count);

for (self.files.items) |file| {
self.blake3.update(&file.bin_digest);
}
@@ -512,30 +518,32 @@ test "no file inputs" {
testing.expectEqual(digest1, digest2);
}

test "manifest file with extra line does not cause null pointer exeception" {
test "CacheHashes with files added after initial hash work" {
const cwd = fs.cwd();

const temp_file1 = "cache_hash_remove_file_test1.txt";
const temp_file2 = "cache_hash_remove_file_test2.txt";
const temp_manifest_dir = "cache_hash_remove_file_manifest_dir";
const temp_file1 = "cache_hash_post_file_test1.txt";
const temp_file2 = "cache_hash_post_file_test2.txt";
const temp_manifest_dir = "cache_hash_post_file_manifest_dir";

try cwd.writeFile(temp_file1, "Hello, world!\n");
try cwd.writeFile(temp_file2, "Hello world the second!\n");

var digest1: [BASE64_DIGEST_LEN]u8 = undefined;
var digest2: [BASE64_DIGEST_LEN]u8 = undefined;
var digest3: [BASE64_DIGEST_LEN]u8 = undefined;

{
var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
defer ch.release() catch unreachable;

ch.add("1234");
_ = try ch.addFile(temp_file1);
_ = try ch.addFile(temp_file2);

// There should be nothing in the cache
testing.expectEqual(@as(?[64]u8, null), try ch.hit());

_ = try ch.addFilePost(temp_file2);

digest1 = ch.final();
}
{
@@ -544,20 +552,31 @@ test "manifest file with extra line does not cause null pointer exeception" {

ch.add("1234");
_ = try ch.addFile(temp_file1);
_ = try ch.addFile(temp_file2);
{
// Remove an input file from the cache hash.
// We still have to add the input file, or else the initial cache
// hash will be different, and a different manifest file checked
const chf = ch.files.orderedRemove(1);
testing.allocator.free(chf.path.?);
}

// A file that we depend on has been updated, so the cache should not contain an entry for it
digest2 = (try ch.hit()).?;
}

// Modify the file added after initial hash
try cwd.writeFile(temp_file2, "Hello world the second, updated\n");

{
var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
defer ch.release() catch unreachable;

ch.add("1234");
_ = try ch.addFile(temp_file1);

// A file that we depend on has been updated, so the cache should not contain an entry for it
testing.expectEqual(@as(?[64]u8, null), try ch.hit());

_ = try ch.addFilePost(temp_file2);

digest3 = ch.final();
}

testing.expect(mem.eql(u8, digest1[0..], digest2[0..]));
testing.expect(!mem.eql(u8, digest1[0..], digest3[0..]));

try cwd.deleteTree(temp_manifest_dir);
try cwd.deleteFile(temp_file1);