@@ -2083,6 +2083,7 @@ void release_http_pack_request(struct http_pack_request *preq)
2083
2083
preq -> packfile = NULL ;
2084
2084
}
2085
2085
preq -> slot = NULL ;
2086
+ strbuf_release (& preq -> tmpfile );
2086
2087
free (preq -> url );
2087
2088
free (preq );
2088
2089
}
@@ -2105,27 +2106,27 @@ int finish_http_pack_request(struct http_pack_request *preq)
2105
2106
lst = & ((* lst )-> next );
2106
2107
* lst = (* lst )-> next ;
2107
2108
2108
- if (!strip_suffix (preq -> tmpfile , ".pack.temp" , & len ))
2109
+ if (!strip_suffix (preq -> tmpfile . buf , ".pack.temp" , & len ))
2109
2110
BUG ("pack tmpfile does not end in .pack.temp?" );
2110
- tmp_idx = xstrfmt ("%.*s.idx.temp" , (int )len , preq -> tmpfile );
2111
+ tmp_idx = xstrfmt ("%.*s.idx.temp" , (int )len , preq -> tmpfile . buf );
2111
2112
2112
2113
argv_array_push (& ip .args , "index-pack" );
2113
2114
argv_array_pushl (& ip .args , "-o" , tmp_idx , NULL );
2114
- argv_array_push (& ip .args , preq -> tmpfile );
2115
+ argv_array_push (& ip .args , preq -> tmpfile . buf );
2115
2116
ip .git_cmd = 1 ;
2116
2117
ip .no_stdin = 1 ;
2117
2118
ip .no_stdout = 1 ;
2118
2119
2119
2120
if (run_command (& ip )) {
2120
- unlink (preq -> tmpfile );
2121
+ unlink (preq -> tmpfile . buf );
2121
2122
unlink (tmp_idx );
2122
2123
free (tmp_idx );
2123
2124
return -1 ;
2124
2125
}
2125
2126
2126
2127
unlink (sha1_pack_index_name (p -> sha1 ));
2127
2128
2128
- if (finalize_object_file (preq -> tmpfile , sha1_pack_name (p -> sha1 ))
2129
+ if (finalize_object_file (preq -> tmpfile . buf , sha1_pack_name (p -> sha1 ))
2129
2130
|| finalize_object_file (tmp_idx , sha1_pack_index_name (p -> sha1 ))) {
2130
2131
free (tmp_idx );
2131
2132
return -1 ;
@@ -2144,19 +2145,19 @@ struct http_pack_request *new_http_pack_request(
2144
2145
struct http_pack_request * preq ;
2145
2146
2146
2147
preq = xcalloc (1 , sizeof (* preq ));
2148
+ strbuf_init (& preq -> tmpfile , 0 );
2147
2149
preq -> target = target ;
2148
2150
2149
2151
end_url_with_slash (& buf , base_url );
2150
2152
strbuf_addf (& buf , "objects/pack/pack-%s.pack" ,
2151
2153
sha1_to_hex (target -> sha1 ));
2152
2154
preq -> url = strbuf_detach (& buf , NULL );
2153
2155
2154
- snprintf (preq -> tmpfile , sizeof (preq -> tmpfile ), "%s.temp" ,
2155
- sha1_pack_name (target -> sha1 ));
2156
- preq -> packfile = fopen (preq -> tmpfile , "a" );
2156
+ strbuf_addf (& preq -> tmpfile , "%s.temp" , sha1_pack_name (target -> sha1 ));
2157
+ preq -> packfile = fopen (preq -> tmpfile .buf , "a" );
2157
2158
if (!preq -> packfile ) {
2158
2159
error ("Unable to open local file %s for pack" ,
2159
- preq -> tmpfile );
2160
+ preq -> tmpfile . buf );
2160
2161
goto abort ;
2161
2162
}
2162
2163
@@ -2183,6 +2184,7 @@ struct http_pack_request *new_http_pack_request(
2183
2184
return preq ;
2184
2185
2185
2186
abort :
2187
+ strbuf_release (& preq -> tmpfile );
2186
2188
free (preq -> url );
2187
2189
free (preq );
2188
2190
return NULL ;
@@ -2233,48 +2235,49 @@ struct http_object_request *new_http_object_request(const char *base_url,
2233
2235
{
2234
2236
char * hex = sha1_to_hex (sha1 );
2235
2237
struct strbuf filename = STRBUF_INIT ;
2236
- char prevfile [ PATH_MAX ] ;
2238
+ struct strbuf prevfile = STRBUF_INIT ;
2237
2239
int prevlocal ;
2238
2240
char prev_buf [PREV_BUF_SIZE ];
2239
2241
ssize_t prev_read = 0 ;
2240
2242
off_t prev_posn = 0 ;
2241
2243
struct http_object_request * freq ;
2242
2244
2243
2245
freq = xcalloc (1 , sizeof (* freq ));
2246
+ strbuf_init (& freq -> tmpfile , 0 );
2244
2247
hashcpy (freq -> sha1 , sha1 );
2245
2248
freq -> localfile = -1 ;
2246
2249
2247
2250
sha1_file_name (the_repository , & filename , sha1 );
2248
- snprintf (freq -> tmpfile , sizeof (freq -> tmpfile ),
2249
- "%s.temp" , filename .buf );
2251
+ strbuf_addf (& freq -> tmpfile , "%s.temp" , filename .buf );
2250
2252
2251
- snprintf ( prevfile , sizeof ( prevfile ) , "%s.prev" , filename .buf );
2252
- unlink_or_warn (prevfile );
2253
- rename (freq -> tmpfile , prevfile );
2254
- unlink_or_warn (freq -> tmpfile );
2253
+ strbuf_addf ( & prevfile , "%s.prev" , filename .buf );
2254
+ unlink_or_warn (prevfile . buf );
2255
+ rename (freq -> tmpfile . buf , prevfile . buf );
2256
+ unlink_or_warn (freq -> tmpfile . buf );
2255
2257
strbuf_release (& filename );
2256
2258
2257
2259
if (freq -> localfile != -1 )
2258
2260
error ("fd leakage in start: %d" , freq -> localfile );
2259
- freq -> localfile = open (freq -> tmpfile ,
2261
+ freq -> localfile = open (freq -> tmpfile . buf ,
2260
2262
O_WRONLY | O_CREAT | O_EXCL , 0666 );
2261
2263
/*
2262
2264
* This could have failed due to the "lazy directory creation";
2263
2265
* try to mkdir the last path component.
2264
2266
*/
2265
2267
if (freq -> localfile < 0 && errno == ENOENT ) {
2266
- char * dir = strrchr (freq -> tmpfile , '/' );
2268
+ char * dir = strrchr (freq -> tmpfile . buf , '/' );
2267
2269
if (dir ) {
2268
2270
* dir = 0 ;
2269
- mkdir (freq -> tmpfile , 0777 );
2271
+ mkdir (freq -> tmpfile . buf , 0777 );
2270
2272
* dir = '/' ;
2271
2273
}
2272
- freq -> localfile = open (freq -> tmpfile ,
2274
+ freq -> localfile = open (freq -> tmpfile . buf ,
2273
2275
O_WRONLY | O_CREAT | O_EXCL , 0666 );
2274
2276
}
2275
2277
2276
2278
if (freq -> localfile < 0 ) {
2277
- error_errno ("Couldn't create temporary file %s" , freq -> tmpfile );
2279
+ error_errno ("Couldn't create temporary file %s" ,
2280
+ freq -> tmpfile .buf );
2278
2281
goto abort ;
2279
2282
}
2280
2283
@@ -2288,7 +2291,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2288
2291
* If a previous temp file is present, process what was already
2289
2292
* fetched.
2290
2293
*/
2291
- prevlocal = open (prevfile , O_RDONLY );
2294
+ prevlocal = open (prevfile . buf , O_RDONLY );
2292
2295
if (prevlocal != -1 ) {
2293
2296
do {
2294
2297
prev_read = xread (prevlocal , prev_buf , PREV_BUF_SIZE );
@@ -2305,7 +2308,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
2305
2308
} while (prev_read > 0 );
2306
2309
close (prevlocal );
2307
2310
}
2308
- unlink_or_warn (prevfile );
2311
+ unlink_or_warn (prevfile .buf );
2312
+ strbuf_release (& prevfile );
2309
2313
2310
2314
/*
2311
2315
* Reset inflate/SHA1 if there was an error reading the previous temp
@@ -2320,7 +2324,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2320
2324
lseek (freq -> localfile , 0 , SEEK_SET );
2321
2325
if (ftruncate (freq -> localfile , 0 ) < 0 ) {
2322
2326
error_errno ("Couldn't truncate temporary file %s" ,
2323
- freq -> tmpfile );
2327
+ freq -> tmpfile . buf );
2324
2328
goto abort ;
2325
2329
}
2326
2330
}
@@ -2350,6 +2354,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2350
2354
return freq ;
2351
2355
2352
2356
abort :
2357
+ strbuf_release (& prevfile );
2353
2358
free (freq -> url );
2354
2359
free (freq );
2355
2360
return NULL ;
@@ -2377,32 +2382,32 @@ int finish_http_object_request(struct http_object_request *freq)
2377
2382
if (freq -> http_code == 416 ) {
2378
2383
warning ("requested range invalid; we may already have all the data." );
2379
2384
} else if (freq -> curl_result != CURLE_OK ) {
2380
- if (stat (freq -> tmpfile , & st ) == 0 )
2385
+ if (stat (freq -> tmpfile . buf , & st ) == 0 )
2381
2386
if (st .st_size == 0 )
2382
- unlink_or_warn (freq -> tmpfile );
2387
+ unlink_or_warn (freq -> tmpfile . buf );
2383
2388
return -1 ;
2384
2389
}
2385
2390
2386
2391
git_inflate_end (& freq -> stream );
2387
2392
git_SHA1_Final (freq -> real_sha1 , & freq -> c );
2388
2393
if (freq -> zret != Z_STREAM_END ) {
2389
- unlink_or_warn (freq -> tmpfile );
2394
+ unlink_or_warn (freq -> tmpfile . buf );
2390
2395
return -1 ;
2391
2396
}
2392
2397
if (hashcmp (freq -> sha1 , freq -> real_sha1 )) {
2393
- unlink_or_warn (freq -> tmpfile );
2398
+ unlink_or_warn (freq -> tmpfile . buf );
2394
2399
return -1 ;
2395
2400
}
2396
2401
sha1_file_name (the_repository , & filename , freq -> sha1 );
2397
- freq -> rename = finalize_object_file (freq -> tmpfile , filename .buf );
2402
+ freq -> rename = finalize_object_file (freq -> tmpfile . buf , filename .buf );
2398
2403
strbuf_release (& filename );
2399
2404
2400
2405
return freq -> rename ;
2401
2406
}
2402
2407
2403
2408
void abort_http_object_request (struct http_object_request * freq )
2404
2409
{
2405
- unlink_or_warn (freq -> tmpfile );
2410
+ unlink_or_warn (freq -> tmpfile . buf );
2406
2411
2407
2412
release_http_object_request (freq );
2408
2413
}
@@ -2422,4 +2427,5 @@ void release_http_object_request(struct http_object_request *freq)
2422
2427
release_active_slot (freq -> slot );
2423
2428
freq -> slot = NULL ;
2424
2429
}
2430
+ strbuf_release (& freq -> tmpfile );
2425
2431
}
0 commit comments