Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › Build › Cache › Manifest › populateFileHashHandle Private Function populateFileHashHandle Doc Source Private Function std.Build.Cache.Manifest.populateFileHashHandle
fn populateFileHashHandle (self : *Manifest , ch_file : *File , io_file : Io .File ) !void Params File Build/Cache.zig: 904
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945 fn populateFileHashHandle (self : *Manifest , ch_file : *File , io_file : Io .File ) !void {
const io = self .cache .io ;
const gpa = self .cache .gpa ;
const actual_stat = try io_file .stat (io );
ch_file .stat = .{
.size = actual_stat .size ,
.mtime = actual_stat .mtime ,
.inode = actual_stat .inode ,
};
if (try self .isProblematicTimestamp (ch_file .stat .mtime )) {
// The actual file has an unreliable timestamp, force it to be hashed
ch_file .stat .mtime = .zero ;
ch_file .stat .inode = 0 ;
}
if (ch_file .max_file_size ) |max_file_size | {
if (ch_file .stat .size > max_file_size ) return error .FileTooBig ;
// Hash while reading from disk, to keep the contents in the cpu
// cache while doing hashing.
const contents = try gpa .alloc (u8 , @intCast (ch_file .stat .size ));
errdefer gpa .free (contents );
var hasher = hasher_init ;
var off : usize = 0 ;
while (true ) {
const bytes_read = try io_file .readPositional (io , &.{contents [off ..]}, off );
if (bytes_read == 0 ) break ;
hasher .update (contents [off ..][0 ..bytes_read ]);
off += bytes_read ;
}
hasher .final (&ch_file .bin_digest );
ch_file .contents = contents ;
} else {
try hashFile (io , io_file , &ch_file .bin_digest );
}
self .hash .hasher .update (&ch_file .bin_digest );
}