From: Omar Polo Subject: gotwebd: inline got_output_file_blob To: gameoftrees@openbsd.org Date: Fri, 13 Jan 2023 11:36:00 +0100 Since the refactoring that split got_open_blob_for_output out of it, got_output_file_blob remained just a simple loop that outputs chunks read from a blob. IMHO it's better suited in gotweb.c along with the rest of the outputting routines instead that in got_operations.c, and also slightly gets in the way of another upcoming refactoring of the handling of the response code. no functional changes intended. ok? diff /home/op/w/got commit - 4f473d21fd465f8b323c36a3ff05d5941c4e5ab8 path + /home/op/w/got blob - 40a3d01e7cd04fb81ec28b32b86bd6b7c74fec5c file + gotwebd/got_operations.c --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -955,48 +955,6 @@ const struct got_error * return error; } -const struct got_error * -got_output_file_blob(struct request *c) -{ - const struct got_error *error = NULL; - struct querystring *qs = c->t->qs; - struct got_blob_object *blob = NULL; - size_t len; - int binary, fd = -1; - const uint8_t *buf; - - error = got_open_blob_for_output(&blob, &fd, &binary, c); - if (error) - return error; - - if (binary) - error = gotweb_render_content_type_file(c, - "application/octet-stream", qs->file, NULL); - else - error = gotweb_render_content_type(c, "text/plain"); - - if (error) { - log_warnx("%s: %s", __func__, error->msg); - goto done; - } - - for (;;) { - error = got_object_blob_read_block(&len, blob); - if (error) - goto done; - if (len == 0) - break; - buf = got_object_blob_get_read_buf(blob); - fcgi_gen_binary_response(c, buf, len); - } - done: - if (close(fd) == -1 && error == NULL) - error = got_error_from_errno("close"); - if (blob) - got_object_blob_close(blob); - return error; -} - int got_output_blob_by_lines(struct template *tp, struct got_blob_object *blob, int (*cb)(struct template *, const char *, size_t)) blob - 9571e03a832b18e48cc16b0c1904e3b0d2d687b5 file + gotwebd/gotweb.c --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -168,14 +168,40 @@ gotweb_process_request(struct request *c) } if (qs->action == BLOBRAW) { + const uint8_t *buf; + size_t len; + int binary; + error = got_get_repo_commits(c, 1); if (error) goto done; - error = got_output_file_blob(c); + + error2 = got_open_blob_for_output(&blob, &fd, &binary, c); + if (error2) + goto render; + + if (binary) + error = gotweb_render_content_type_file(c, + "application/octet-stream", qs->file, NULL); + else + error = gotweb_render_content_type(c, "text/plain"); + if (error) { log_warnx("%s: %s", __func__, error->msg); - goto err; + goto done; } + + for (;;) { + error = got_object_blob_read_block(&len, blob); + if (error) + goto done; + if (len == 0) + break; + buf = got_object_blob_get_read_buf(blob); + if (fcgi_gen_binary_response(c, buf, len) == -1) + goto done; + } + goto done; } blob - aaf5713ca50e3eadba54e18b2b8fef2cbcb1f7ee file + gotwebd/gotwebd.h --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -520,7 +520,6 @@ const struct got_error *got_output_file_blob(struct re int (*)(struct template *, struct got_tree_entry *)); const struct got_error *got_open_blob_for_output(struct got_blob_object **, int *, int *, struct request *); -const struct got_error *got_output_file_blob(struct request *); int got_output_blob_by_lines(struct template *, struct got_blob_object *, int (*)(struct template *, const char *, size_t)); const struct got_error *got_output_file_blame(struct request *,