@@ -108,6 +108,39 @@ static unsigned char get_dtype(struct dirent *e, struct strbuf *path)
108
108
return dtype ;
109
109
}
110
110
111
+ static void dir_stats (struct strbuf * buf , const char * path )
112
+ {
113
+ DIR * dir = opendir (path );
114
+ struct dirent * e ;
115
+ struct stat e_stat ;
116
+ struct strbuf file_path = STRBUF_INIT ;
117
+ size_t base_path_len ;
118
+
119
+ if (!dir )
120
+ return ;
121
+
122
+ strbuf_addstr (buf , "Contents of " );
123
+ strbuf_add_absolute_path (buf , path );
124
+ strbuf_addstr (buf , ":\n" );
125
+
126
+ strbuf_add_absolute_path (& file_path , path );
127
+ strbuf_addch (& file_path , '/' );
128
+ base_path_len = file_path .len ;
129
+
130
+ while ((e = readdir (dir )) != NULL )
131
+ if (!is_dot_or_dotdot (e -> d_name ) && e -> d_type == DT_REG ) {
132
+ strbuf_setlen (& file_path , base_path_len );
133
+ strbuf_addstr (& file_path , e -> d_name );
134
+ if (!stat (file_path .buf , & e_stat ))
135
+ strbuf_addf (buf , "%-70s %16" PRIuMAX "\n" ,
136
+ e -> d_name ,
137
+ (uintmax_t )e_stat .st_size );
138
+ }
139
+
140
+ strbuf_release (& file_path );
141
+ closedir (dir );
142
+ }
143
+
111
144
static int count_files (struct strbuf * path )
112
145
{
113
146
DIR * dir = opendir (path -> buf );
@@ -221,7 +254,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
221
254
char * * argv_copy = NULL ;
222
255
int stdout_fd = -1 , archiver_fd = -1 ;
223
256
char * cache_server_url = NULL , * shared_cache = NULL ;
224
- struct strbuf buf = STRBUF_INIT ;
257
+ struct strbuf buf = STRBUF_INIT , path = STRBUF_INIT ;
225
258
int res , i ;
226
259
struct archive_dir archive_dirs [] = {
227
260
{ ".git" , 0 },
@@ -293,6 +326,52 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
293
326
}
294
327
}
295
328
329
+ if (shared_cache ) {
330
+ size_t path_len ;
331
+
332
+ strbuf_reset (& buf );
333
+ strbuf_addf (& path , "%s/pack" , shared_cache );
334
+ strbuf_reset (& buf );
335
+ strbuf_addstr (& buf , "--add-virtual-file=packs-cached.txt:" );
336
+ dir_stats (& buf , path .buf );
337
+ strvec_push (& archiver_args , buf .buf );
338
+
339
+ strbuf_reset (& buf );
340
+ strbuf_addstr (& buf , "--add-virtual-file=objects-cached.txt:" );
341
+ loose_objs_stats (& buf , shared_cache );
342
+ strvec_push (& archiver_args , buf .buf );
343
+
344
+ strbuf_reset (& path );
345
+ strbuf_addf (& path , "%s/info" , shared_cache );
346
+ path_len = path .len ;
347
+
348
+ if (is_directory (path .buf )) {
349
+ DIR * dir = opendir (path .buf );
350
+ struct dirent * e ;
351
+
352
+ while ((e = readdir (dir ))) {
353
+ if (!strcmp ("." , e -> d_name ) || !strcmp (".." , e -> d_name ))
354
+ continue ;
355
+ if (e -> d_type == DT_DIR )
356
+ continue ;
357
+
358
+ strbuf_reset (& buf );
359
+ strbuf_addf (& buf , "--add-virtual-file=info/%s:" , e -> d_name );
360
+
361
+ strbuf_setlen (& path , path_len );
362
+ strbuf_addch (& path , '/' );
363
+ strbuf_addstr (& path , e -> d_name );
364
+
365
+ if (strbuf_read_file (& buf , path .buf , 0 ) < 0 ) {
366
+ res = error_errno (_ ("could not read '%s'" ), path .buf );
367
+ goto diagnose_cleanup ;
368
+ }
369
+ strvec_push (& archiver_args , buf .buf );
370
+ }
371
+ closedir (dir );
372
+ }
373
+ }
374
+
296
375
strvec_pushl (& archiver_args , "--prefix=" ,
297
376
oid_to_hex (the_hash_algo -> empty_tree ), "--" , NULL );
298
377
0 commit comments