@@ -1093,12 +1093,7 @@ fn unpackResource(
1093
1093
1094
1094
.git = > .git_pack ,
1095
1095
1096
- .dir = > | dir | return f .recursiveDirectoryCopy (dir , tmp_directory .handle ) catch | err | {
1097
- return f .fail (f .location_tok , try eb .printString (
1098
- "unable to copy directory '{s}': {s}" ,
1099
- .{ uri_path , @errorName (err ) },
1100
- ));
1101
- },
1096
+ .dir = > | dir | return try f .recursiveDirectoryCopy (dir , tmp_directory .handle , uri_path ),
1102
1097
};
1103
1098
1104
1099
switch (file_type ) {
@@ -1132,64 +1127,94 @@ fn unpackResource(
1132
1127
});
1133
1128
return unpackTarball (f , tmp_directory .handle , dcp .reader ());
1134
1129
},
1135
- .git_pack = > unpackGitPack (f , tmp_directory .handle , resource ) catch | err | switch (err ) {
1136
- error .FetchFailed = > return error .FetchFailed ,
1137
- error .OutOfMemory = > return error .OutOfMemory ,
1138
- else = > | e | return f .fail (f .location_tok , try eb .printString (
1139
- "unable to unpack git files: {s}" ,
1140
- .{@errorName (e )},
1141
- )),
1142
- },
1130
+ .git_pack = > try unpackGitPack (f , tmp_directory .handle , resource ),
1143
1131
}
1144
1132
}
1145
1133
1146
1134
const Unpack = @import ("Unpack.zig" );
1147
1135
1148
1136
fn unpackTarball (f : * Fetch , out_dir : fs.Dir , reader : anytype ) RunError ! void {
1149
- const eb = & f .error_bundle ;
1150
- const gpa = f .arena .child_allocator ;
1151
-
1152
- var unpack = Unpack { .allocator = gpa , .root = out_dir };
1137
+ var unpack = Unpack .init (f .arena .child_allocator , out_dir );
1153
1138
defer unpack .deinit ();
1154
- unpack .tarball (reader ) catch | err | return f .fail (
1155
- f .location_tok ,
1156
- try eb .printString (
1157
- "unable to unpack tarball to temporary directory: {s}" ,
1158
- .{@errorName (err )},
1159
- ),
1139
+ unpack .tarball (reader ) catch | err | return f .failMsg (
1140
+ err ,
1141
+ "unable to unpack tarball to temporary directory: {s}" ,
1142
+ .{@errorName (err )},
1160
1143
);
1161
- if (unpack .hasErrors ()) {
1162
- try unpack .bundleErrors (eb , try f .srcLoc (f .location_tok ));
1163
- return error .FetchFailed ;
1164
- }
1144
+ try f .checkUnpackErrors (& unpack );
1165
1145
}
1166
1146
1167
- fn unpackGitPack (f : * Fetch , out_dir : fs.Dir , resource : * Resource ) anyerror ! void {
1168
- const eb = & f .error_bundle ;
1169
- const gpa = f .arena .child_allocator ;
1147
+ fn unpackGitPack (f : * Fetch , out_dir : fs.Dir , resource : * Resource ) RunError ! void {
1148
+ var unpack = Unpack .init (f .arena .child_allocator , out_dir );
1149
+ defer unpack .deinit ();
1150
+
1170
1151
const want_oid = resource .git .want_oid ;
1171
1152
const reader = resource .git .fetch_stream .reader ();
1153
+ unpack .gitPack (want_oid , reader ) catch | err | return f .failMsg (
1154
+ err ,
1155
+ "unable to unpack git files: {s}" ,
1156
+ .{@errorName (err )},
1157
+ );
1158
+ try f .checkUnpackErrors (& unpack );
1159
+ }
1172
1160
1173
- var unpack = Unpack { .allocator = gpa , .root = out_dir };
1161
+ fn recursiveDirectoryCopy (f : * Fetch , dir : fs.Dir , out_dir : fs.Dir , uri_path : []const u8 ) RunError ! void {
1162
+ var unpack = Unpack .init (f .arena .child_allocator , out_dir );
1174
1163
defer unpack .deinit ();
1175
- try unpack .gitPack (want_oid , reader );
1176
- if (unpack .hasErrors ()) {
1177
- try unpack .bundleErrors (eb , try f .srcLoc (f .location_tok ));
1178
- return error .FetchFailed ;
1179
- }
1164
+ unpack .directory (dir ) catch | err | return f .failMsg (
1165
+ err ,
1166
+ "unable to copy directory '{s}': {s}" ,
1167
+ .{ uri_path , @errorName (err ) },
1168
+ );
1169
+ try f .checkUnpackErrors (& unpack );
1180
1170
}
1181
1171
1182
- fn recursiveDirectoryCopy (f : * Fetch , dir : fs.Dir , tmp_dir : fs.Dir ) anyerror ! void {
1172
+ fn failMsg (f : * Fetch , err : anyerror , comptime fmt : [] const u8 , args : anytype ) RunError {
1183
1173
const eb = & f .error_bundle ;
1184
- const gpa = f .arena .child_allocator ;
1174
+ switch (err ) {
1175
+ error .OutOfMemory = > return error .OutOfMemory ,
1176
+ else = > return f .fail (f .location_tok , try eb .printString (fmt , args )),
1177
+ }
1178
+ }
1185
1179
1186
- var unpack = Unpack { .allocator = gpa , .root = tmp_dir };
1187
- defer unpack .deinit ();
1188
- try unpack .directory (dir );
1189
- if (unpack .hasErrors ()) {
1190
- try unpack .bundleErrors (eb , try f .srcLoc (f .location_tok ));
1191
- return error .FetchFailed ;
1180
+ fn checkUnpackErrors (f : * Fetch , unpack : * Unpack ) RunError ! void {
1181
+ if (! unpack .hasErrors ()) return ;
1182
+
1183
+ const eb = & f .error_bundle ;
1184
+ const notes_len : u32 = @intCast (unpack .errors .items .len );
1185
+ try eb .addRootErrorMessage (.{
1186
+ .msg = try eb .addString ("unable to unpack" ),
1187
+ .src_loc = try f .srcLoc (f .location_tok ),
1188
+ .notes_len = notes_len ,
1189
+ });
1190
+ const notes_start = try eb .reserveNotes (notes_len );
1191
+ for (unpack .errors .items , notes_start .. ) | item , note_i | {
1192
+ switch (item ) {
1193
+ .unable_to_create_sym_link = > | info | {
1194
+ eb .extra .items [note_i ] = @intFromEnum (try eb .addErrorMessage (.{
1195
+ .msg = try eb .printString ("unable to create symlink from '{s}' to '{s}': {s}" , .{
1196
+ info .sym_link_path , info .target_path , @errorName (info .code ),
1197
+ }),
1198
+ }));
1199
+ },
1200
+ .unable_to_create_file = > | info | {
1201
+ eb .extra .items [note_i ] = @intFromEnum (try eb .addErrorMessage (.{
1202
+ .msg = try eb .printString ("unable to create file '{s}': {s}" , .{
1203
+ info .file_name , @errorName (info .code ),
1204
+ }),
1205
+ }));
1206
+ },
1207
+ .unsupported_file_type = > | info | {
1208
+ eb .extra .items [note_i ] = @intFromEnum (try eb .addErrorMessage (.{
1209
+ .msg = try eb .printString ("file '{s}' has unsupported type '{c}'" , .{
1210
+ info .file_name , info .file_type ,
1211
+ }),
1212
+ }));
1213
+ },
1214
+ }
1192
1215
}
1216
+
1217
+ return error .FetchFailed ;
1193
1218
}
1194
1219
1195
1220
pub fn renameTmpIntoCache (
0 commit comments