|
5 | 5 | #include "refs.h"
|
6 | 6 | #include "run-command.h"
|
7 | 7 |
|
8 |
| -static int find_temp_filename(struct strbuf *name) |
| 8 | +static char *find_temp_filename(void) |
9 | 9 | {
|
10 | 10 | int fd;
|
| 11 | + struct strbuf name = STRBUF_INIT; |
11 | 12 | /*
|
12 | 13 | * Find a temporary filename that is available. This is briefly
|
13 | 14 | * racy, but unlikely to collide.
|
14 | 15 | */
|
15 |
| - fd = odb_mkstemp(name, "bundles/tmp_uri_XXXXXX"); |
| 16 | + fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX"); |
16 | 17 | if (fd < 0) {
|
17 | 18 | warning(_("failed to create temporary file"));
|
18 |
| - return -1; |
| 19 | + return NULL; |
19 | 20 | }
|
20 | 21 |
|
21 | 22 | close(fd);
|
22 |
| - unlink(name->buf); |
23 |
| - return 0; |
| 23 | + unlink(name.buf); |
| 24 | + return strbuf_detach(&name, NULL); |
24 | 25 | }
|
25 | 26 |
|
26 | 27 | static int download_https_uri_to_file(const char *file, const char *uri)
|
@@ -141,28 +142,31 @@ static int unbundle_from_file(struct repository *r, const char *file)
|
141 | 142 | int fetch_bundle_uri(struct repository *r, const char *uri)
|
142 | 143 | {
|
143 | 144 | int result = 0;
|
144 |
| - struct strbuf filename = STRBUF_INIT; |
| 145 | + char *filename; |
145 | 146 |
|
146 |
| - if ((result = find_temp_filename(&filename))) |
| 147 | + if (!(filename = find_temp_filename())) { |
| 148 | + result = -1; |
147 | 149 | goto cleanup;
|
| 150 | + } |
148 | 151 |
|
149 |
| - if ((result = copy_uri_to_file(filename.buf, uri))) { |
| 152 | + if ((result = copy_uri_to_file(filename, uri))) { |
150 | 153 | warning(_("failed to download bundle from URI '%s'"), uri);
|
151 | 154 | goto cleanup;
|
152 | 155 | }
|
153 | 156 |
|
154 |
| - if ((result = !is_bundle(filename.buf, 0))) { |
| 157 | + if ((result = !is_bundle(filename, 0))) { |
155 | 158 | warning(_("file at URI '%s' is not a bundle"), uri);
|
156 | 159 | goto cleanup;
|
157 | 160 | }
|
158 | 161 |
|
159 |
| - if ((result = unbundle_from_file(r, filename.buf))) { |
| 162 | + if ((result = unbundle_from_file(r, filename))) { |
160 | 163 | warning(_("failed to unbundle bundle from URI '%s'"), uri);
|
161 | 164 | goto cleanup;
|
162 | 165 | }
|
163 | 166 |
|
164 | 167 | cleanup:
|
165 |
| - unlink(filename.buf); |
166 |
| - strbuf_release(&filename); |
| 168 | + if (filename) |
| 169 | + unlink(filename); |
| 170 | + free(filename); |
167 | 171 | return result;
|
168 | 172 | }
|
0 commit comments