@@ -2087,6 +2087,7 @@ void release_http_pack_request(struct http_pack_request *preq)
2087
2087
preq -> packfile = NULL ;
2088
2088
}
2089
2089
preq -> slot = NULL ;
2090
+ strbuf_release (& preq -> tmpfile );
2090
2091
free (preq -> url );
2091
2092
free (preq );
2092
2093
}
@@ -2109,27 +2110,27 @@ int finish_http_pack_request(struct http_pack_request *preq)
2109
2110
lst = & ((* lst )-> next );
2110
2111
* lst = (* lst )-> next ;
2111
2112
2112
- if (!strip_suffix (preq -> tmpfile , ".pack.temp" , & len ))
2113
+ if (!strip_suffix (preq -> tmpfile . buf , ".pack.temp" , & len ))
2113
2114
die ("BUG: pack tmpfile does not end in .pack.temp?" );
2114
- tmp_idx = xstrfmt ("%.*s.idx.temp" , (int )len , preq -> tmpfile );
2115
+ tmp_idx = xstrfmt ("%.*s.idx.temp" , (int )len , preq -> tmpfile . buf );
2115
2116
2116
2117
argv_array_push (& ip .args , "index-pack" );
2117
2118
argv_array_pushl (& ip .args , "-o" , tmp_idx , NULL );
2118
- argv_array_push (& ip .args , preq -> tmpfile );
2119
+ argv_array_push (& ip .args , preq -> tmpfile . buf );
2119
2120
ip .git_cmd = 1 ;
2120
2121
ip .no_stdin = 1 ;
2121
2122
ip .no_stdout = 1 ;
2122
2123
2123
2124
if (run_command (& ip )) {
2124
- unlink (preq -> tmpfile );
2125
+ unlink (preq -> tmpfile . buf );
2125
2126
unlink (tmp_idx );
2126
2127
free (tmp_idx );
2127
2128
return -1 ;
2128
2129
}
2129
2130
2130
2131
unlink (sha1_pack_index_name (p -> sha1 ));
2131
2132
2132
- if (finalize_object_file (preq -> tmpfile , sha1_pack_name (p -> sha1 ))
2133
+ if (finalize_object_file (preq -> tmpfile . buf , sha1_pack_name (p -> sha1 ))
2133
2134
|| finalize_object_file (tmp_idx , sha1_pack_index_name (p -> sha1 ))) {
2134
2135
free (tmp_idx );
2135
2136
return -1 ;
@@ -2148,19 +2149,19 @@ struct http_pack_request *new_http_pack_request(
2148
2149
struct http_pack_request * preq ;
2149
2150
2150
2151
preq = xcalloc (1 , sizeof (* preq ));
2152
+ strbuf_init (& preq -> tmpfile , 0 );
2151
2153
preq -> target = target ;
2152
2154
2153
2155
end_url_with_slash (& buf , base_url );
2154
2156
strbuf_addf (& buf , "objects/pack/pack-%s.pack" ,
2155
2157
sha1_to_hex (target -> sha1 ));
2156
2158
preq -> url = strbuf_detach (& buf , NULL );
2157
2159
2158
- snprintf (preq -> tmpfile , sizeof (preq -> tmpfile ), "%s.temp" ,
2159
- sha1_pack_name (target -> sha1 ));
2160
- preq -> packfile = fopen (preq -> tmpfile , "a" );
2160
+ strbuf_addf (& preq -> tmpfile , "%s.temp" , sha1_pack_name (target -> sha1 ));
2161
+ preq -> packfile = fopen (preq -> tmpfile .buf , "a" );
2161
2162
if (!preq -> packfile ) {
2162
2163
error ("Unable to open local file %s for pack" ,
2163
- preq -> tmpfile );
2164
+ preq -> tmpfile . buf );
2164
2165
goto abort ;
2165
2166
}
2166
2167
@@ -2187,6 +2188,7 @@ struct http_pack_request *new_http_pack_request(
2187
2188
return preq ;
2188
2189
2189
2190
abort :
2191
+ strbuf_release (& preq -> tmpfile );
2190
2192
free (preq -> url );
2191
2193
free (preq );
2192
2194
return NULL ;
@@ -2237,48 +2239,49 @@ struct http_object_request *new_http_object_request(const char *base_url,
2237
2239
{
2238
2240
char * hex = sha1_to_hex (sha1 );
2239
2241
struct strbuf filename = STRBUF_INIT ;
2240
- char prevfile [ PATH_MAX ] ;
2242
+ struct strbuf prevfile = STRBUF_INIT ;
2241
2243
int prevlocal ;
2242
2244
char prev_buf [PREV_BUF_SIZE ];
2243
2245
ssize_t prev_read = 0 ;
2244
2246
off_t prev_posn = 0 ;
2245
2247
struct http_object_request * freq ;
2246
2248
2247
2249
freq = xcalloc (1 , sizeof (* freq ));
2250
+ strbuf_init (& freq -> tmpfile , 0 );
2248
2251
hashcpy (freq -> sha1 , sha1 );
2249
2252
freq -> localfile = -1 ;
2250
2253
2251
2254
sha1_file_name (& filename , sha1 );
2252
- snprintf (freq -> tmpfile , sizeof (freq -> tmpfile ),
2253
- "%s.temp" , filename .buf );
2255
+ strbuf_addf (& freq -> tmpfile , "%s.temp" , filename .buf );
2254
2256
2255
- snprintf ( prevfile , sizeof ( prevfile ) , "%s.prev" , filename .buf );
2256
- unlink_or_warn (prevfile );
2257
- rename (freq -> tmpfile , prevfile );
2258
- unlink_or_warn (freq -> tmpfile );
2257
+ strbuf_addf ( & prevfile , "%s.prev" , filename .buf );
2258
+ unlink_or_warn (prevfile . buf );
2259
+ rename (freq -> tmpfile . buf , prevfile . buf );
2260
+ unlink_or_warn (freq -> tmpfile . buf );
2259
2261
strbuf_release (& filename );
2260
2262
2261
2263
if (freq -> localfile != -1 )
2262
2264
error ("fd leakage in start: %d" , freq -> localfile );
2263
- freq -> localfile = open (freq -> tmpfile ,
2265
+ freq -> localfile = open (freq -> tmpfile . buf ,
2264
2266
O_WRONLY | O_CREAT | O_EXCL , 0666 );
2265
2267
/*
2266
2268
* This could have failed due to the "lazy directory creation";
2267
2269
* try to mkdir the last path component.
2268
2270
*/
2269
2271
if (freq -> localfile < 0 && errno == ENOENT ) {
2270
- char * dir = strrchr (freq -> tmpfile , '/' );
2272
+ char * dir = strrchr (freq -> tmpfile . buf , '/' );
2271
2273
if (dir ) {
2272
2274
* dir = 0 ;
2273
- mkdir (freq -> tmpfile , 0777 );
2275
+ mkdir (freq -> tmpfile . buf , 0777 );
2274
2276
* dir = '/' ;
2275
2277
}
2276
- freq -> localfile = open (freq -> tmpfile ,
2278
+ freq -> localfile = open (freq -> tmpfile . buf ,
2277
2279
O_WRONLY | O_CREAT | O_EXCL , 0666 );
2278
2280
}
2279
2281
2280
2282
if (freq -> localfile < 0 ) {
2281
- error_errno ("Couldn't create temporary file %s" , freq -> tmpfile );
2283
+ error_errno ("Couldn't create temporary file %s" ,
2284
+ freq -> tmpfile .buf );
2282
2285
goto abort ;
2283
2286
}
2284
2287
@@ -2292,7 +2295,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2292
2295
* If a previous temp file is present, process what was already
2293
2296
* fetched.
2294
2297
*/
2295
- prevlocal = open (prevfile , O_RDONLY );
2298
+ prevlocal = open (prevfile . buf , O_RDONLY );
2296
2299
if (prevlocal != -1 ) {
2297
2300
do {
2298
2301
prev_read = xread (prevlocal , prev_buf , PREV_BUF_SIZE );
@@ -2309,7 +2312,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
2309
2312
} while (prev_read > 0 );
2310
2313
close (prevlocal );
2311
2314
}
2312
- unlink_or_warn (prevfile );
2315
+ unlink_or_warn (prevfile .buf );
2316
+ strbuf_release (& prevfile );
2313
2317
2314
2318
/*
2315
2319
* Reset inflate/SHA1 if there was an error reading the previous temp
@@ -2324,7 +2328,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2324
2328
lseek (freq -> localfile , 0 , SEEK_SET );
2325
2329
if (ftruncate (freq -> localfile , 0 ) < 0 ) {
2326
2330
error_errno ("Couldn't truncate temporary file %s" ,
2327
- freq -> tmpfile );
2331
+ freq -> tmpfile . buf );
2328
2332
goto abort ;
2329
2333
}
2330
2334
}
@@ -2354,6 +2358,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2354
2358
return freq ;
2355
2359
2356
2360
abort :
2361
+ strbuf_release (& prevfile );
2357
2362
free (freq -> url );
2358
2363
free (freq );
2359
2364
return NULL ;
@@ -2381,33 +2386,33 @@ int finish_http_object_request(struct http_object_request *freq)
2381
2386
if (freq -> http_code == 416 ) {
2382
2387
warning ("requested range invalid; we may already have all the data." );
2383
2388
} else if (freq -> curl_result != CURLE_OK ) {
2384
- if (stat (freq -> tmpfile , & st ) == 0 )
2389
+ if (stat (freq -> tmpfile . buf , & st ) == 0 )
2385
2390
if (st .st_size == 0 )
2386
- unlink_or_warn (freq -> tmpfile );
2391
+ unlink_or_warn (freq -> tmpfile . buf );
2387
2392
return -1 ;
2388
2393
}
2389
2394
2390
2395
git_inflate_end (& freq -> stream );
2391
2396
git_SHA1_Final (freq -> real_sha1 , & freq -> c );
2392
2397
if (freq -> zret != Z_STREAM_END ) {
2393
- unlink_or_warn (freq -> tmpfile );
2398
+ unlink_or_warn (freq -> tmpfile . buf );
2394
2399
return -1 ;
2395
2400
}
2396
2401
if (hashcmp (freq -> sha1 , freq -> real_sha1 )) {
2397
- unlink_or_warn (freq -> tmpfile );
2402
+ unlink_or_warn (freq -> tmpfile . buf );
2398
2403
return -1 ;
2399
2404
}
2400
2405
2401
2406
sha1_file_name (& filename , freq -> sha1 );
2402
- freq -> rename = finalize_object_file (freq -> tmpfile , filename .buf );
2407
+ freq -> rename = finalize_object_file (freq -> tmpfile . buf , filename .buf );
2403
2408
strbuf_release (& filename );
2404
2409
2405
2410
return freq -> rename ;
2406
2411
}
2407
2412
2408
2413
void abort_http_object_request (struct http_object_request * freq )
2409
2414
{
2410
- unlink_or_warn (freq -> tmpfile );
2415
+ unlink_or_warn (freq -> tmpfile . buf );
2411
2416
2412
2417
release_http_object_request (freq );
2413
2418
}
@@ -2427,4 +2432,5 @@ void release_http_object_request(struct http_object_request *freq)
2427
2432
release_active_slot (freq -> slot );
2428
2433
freq -> slot = NULL ;
2429
2434
}
2435
+ strbuf_release (& freq -> tmpfile );
2430
2436
}
0 commit comments