11const std = @import ("std" );
2+ const gpa = std .heap .c_allocator ;
23
34const u = @import ("index.zig" );
45
56//
67//
78
9+ const b = 1 ;
10+ const kb = b * 1024 ;
11+ const mb = kb * 1024 ;
12+
813pub const Module = struct {
914 name : []const u8 ,
1015 main : []const u8 ,
@@ -26,4 +31,40 @@ pub const Module = struct {
2631 .clean_path = try dep .clean_path (),
2732 };
2833 }
34+
35+ pub fn eql (self : Module , another : Module ) bool {
36+ return std .mem .eql (u8 , self .clean_path , another .clean_path );
37+ }
38+
39+ pub fn get_hash (self : Module , cdpath : []const u8 ) ! []const u8 {
40+ const file_list_1 = & std .ArrayList ([]const u8 ).init (gpa );
41+ try u .file_list (try u .concat (&[_ ][]const u8 {cdpath , "/" , self .clean_path }), file_list_1 );
42+
43+ const file_list_2 = & std .ArrayList ([]const u8 ).init (gpa );
44+ for (file_list_1 .items ) | item | {
45+ const _a = u .trim_prefix (item , cdpath )[1.. ];
46+ const _b = u .trim_prefix (_a , self .clean_path )[1.. ];
47+ if (_b [0 ] == '.' ) continue ;
48+ try file_list_2 .append (_b );
49+ }
50+
51+ std .sort .sort ([]const u8 , file_list_2 .items , void {}, struct {
52+ pub fn lt (context : void , lhs : []const u8 , rhs : []const u8 ) bool {
53+ return std .mem .lessThan (u8 , lhs , rhs );
54+ }
55+ }.lt );
56+
57+ const h = & std .crypto .hash .Blake3 .init (.{});
58+ for (file_list_2 .items ) | item | {
59+ const abs_path = try u .concat (&[_ ][]const u8 {cdpath , "/" , self .clean_path , "/" , item });
60+ const file = try std .fs .openFileAbsolute (abs_path , .{});
61+ defer file .close ();
62+ const input = try file .reader ().readAllAlloc (gpa , mb );
63+ h .update (input );
64+ }
65+ var out : [32 ]u8 = undefined ;
66+ h .final (& out );
67+ const hex = try std .fmt .allocPrint (gpa , "{x}" , .{out });
68+ return hex ;
69+ }
2970};
0 commit comments