Skip to content

Commit 23b6d00

Browse files
derrickstoleegitster
authored andcommitted
bundle-uri: use plain string in find_temp_filename()
The find_temp_filename() method was created in 53a5089 (bundle-uri: create basic file-copy logic, 2022-08-09) and uses odb_mkstemp() to create a temporary filename. The odb_mkstemp() method uses a strbuf in its interface, but we do not need to continue carrying a strbuf throughout the bundle URI code. Convert the find_temp_filename() method to use a 'char *' and modify its only caller. This makes sense that we don't actually need to modify this filename directly later, so using a strbuf is overkill. This change will simplify the data structure for tracking a bundle list to use plain strings instead of strbufs. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f677f62 commit 23b6d00

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

bundle-uri.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55
#include "refs.h"
66
#include "run-command.h"
77

8-
static int find_temp_filename(struct strbuf *name)
8+
static char *find_temp_filename(void)
99
{
1010
int fd;
11+
struct strbuf name = STRBUF_INIT;
1112
/*
1213
* Find a temporary filename that is available. This is briefly
1314
* racy, but unlikely to collide.
1415
*/
15-
fd = odb_mkstemp(name, "bundles/tmp_uri_XXXXXX");
16+
fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
1617
if (fd < 0) {
1718
warning(_("failed to create temporary file"));
18-
return -1;
19+
return NULL;
1920
}
2021

2122
close(fd);
22-
unlink(name->buf);
23-
return 0;
23+
unlink(name.buf);
24+
return strbuf_detach(&name, NULL);
2425
}
2526

2627
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)
141142
int fetch_bundle_uri(struct repository *r, const char *uri)
142143
{
143144
int result = 0;
144-
struct strbuf filename = STRBUF_INIT;
145+
char *filename;
145146

146-
if ((result = find_temp_filename(&filename)))
147+
if (!(filename = find_temp_filename())) {
148+
result = -1;
147149
goto cleanup;
150+
}
148151

149-
if ((result = copy_uri_to_file(filename.buf, uri))) {
152+
if ((result = copy_uri_to_file(filename, uri))) {
150153
warning(_("failed to download bundle from URI '%s'"), uri);
151154
goto cleanup;
152155
}
153156

154-
if ((result = !is_bundle(filename.buf, 0))) {
157+
if ((result = !is_bundle(filename, 0))) {
155158
warning(_("file at URI '%s' is not a bundle"), uri);
156159
goto cleanup;
157160
}
158161

159-
if ((result = unbundle_from_file(r, filename.buf))) {
162+
if ((result = unbundle_from_file(r, filename))) {
160163
warning(_("failed to unbundle bundle from URI '%s'"), uri);
161164
goto cleanup;
162165
}
163166

164167
cleanup:
165-
unlink(filename.buf);
166-
strbuf_release(&filename);
168+
if (filename)
169+
unlink(filename);
170+
free(filename);
167171
return result;
168172
}

0 commit comments

Comments
 (0)