commit 4b6c492110655391bfc6554d0b4968e305ef4b55 from: Stefan Sperling date: Tue Jul 22 08:47:56 2025 UTC replace ftruncate+lseek with equivalents from opentemp.c, where available commit - cf66e481a770754af14cc8eb754d916b40bfe825 commit + 4b6c492110655391bfc6554d0b4968e305ef4b55 blob - c9a965bc2a4faed953e12c6a78fc77fa2d52af85 blob + 0e07b3bfbe68530ea229a3a9839bd806b6fc995a --- gotd/session_write.c +++ gotd/session_write.c @@ -223,6 +223,7 @@ recv_packfile_received(int *pack_empty, struct imsg *i static const struct got_error * request_gotsys_conf(struct gotd_imsgev *iev) { + const struct got_error *err = NULL; struct gotd_imsg_packfile_get_content content_req; const char *refname = "refs/heads/main"; const char *path = "gotsys.conf"; @@ -230,10 +231,9 @@ request_gotsys_conf(struct gotd_imsgev *iev) size_t len; int fd = -1; - if (ftruncate(gotd_session.content_fd, 0L) == -1) - return got_error_from_errno("ftruncate"); - if (lseek(gotd_session.content_fd, 0L, SEEK_SET) == -1) - return got_error_from_errno("lseek"); + err = got_opentemp_truncatefd(gotd_session.content_fd); + if (err) + return err; len = sizeof(content_req) + strlen(refname) + strlen(path); wbuf = imsg_create(&iev->ibuf, GOTD_IMSG_PACKFILE_GET_CONTENT, blob - 67115ca0e835945a579386472c68a9561804ee5c blob + de3b5c530209dfd7fd4ee70ed891e96ad029fc17 --- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c +++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c @@ -331,10 +331,9 @@ write_gotd_conf(void) char repo_path[_POSIX_PATH_MAX]; struct timespec now; - if (ftruncate(gotd_conf_tmpfd, 0) == -1) - return got_error_from_errno("ftruncate"); - if (lseek(gotd_conf_tmpfd, 0L, SEEK_SET) == -1) - return got_error_from_errno("lseek"); + err = got_opentemp_truncatefd(gotd_conf_tmpfd); + if (err) + return err; if (clock_gettime(CLOCK_MONOTONIC, &now) == -1) return got_error_from_errno("clock_gettime"); blob - 130fd0751db295a38c8193237af56d17cbe14126 blob + 2846bbbddb83f63677ac8b3ef56540c5407ccb7f --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -39,6 +39,7 @@ #include "got_commit_graph.h" #include "got_blame.h" #include "got_privsep.h" +#include "got_opentemp.h" #include "gotwebd.h" #include "log.h" @@ -57,13 +58,8 @@ const struct got_error * got_gotweb_closefile(FILE *f) { const struct got_error *err = NULL; - - if (fseek(f, 0, SEEK_SET) == -1) - err = got_error_from_errno("fseek"); - if (ftruncate(fileno(f), 0) == -1 && err == NULL) - err = got_error_from_errno("ftruncate"); - + err = got_opentemp_truncate(f); if (fclose(f) == EOF && err == NULL) err = got_error_from_errno("fclose"); blob - 9c7043a8a45b577f89bd3fa93efc37aa4a3aad6f blob + 7833a0beab9c4e9d117d69bf91ac068c17f523a9 --- lib/object_open_io.c +++ lib/object_open_io.c @@ -32,6 +32,7 @@ #include "got_object.h" #include "got_repository.h" #include "got_path.h" +#include "got_opentemp.h" #include "got_lib_delta.h" #include "got_lib_hash.h" @@ -172,11 +173,9 @@ wrap_fd(FILE **f, int wrapped_fd) const struct got_error *err = NULL; int fd; - if (ftruncate(wrapped_fd, 0L) == -1) - return got_error_from_errno("ftruncate"); - - if (lseek(wrapped_fd, 0L, SEEK_SET) == -1) - return got_error_from_errno("lseek"); + err = got_opentemp_truncatefd(wrapped_fd); + if (err) + return err; fd = dup(wrapped_fd); if (fd == -1) @@ -758,14 +757,9 @@ open_blob(struct got_blob_object **blob, struct got_re goto done; } - if (ftruncate(outfd, 0L) == -1) { - err = got_error_from_errno("ftruncate"); + err = got_opentemp_truncatefd(outfd); + if (err) goto done; - } - if (lseek(outfd, 0L, SEEK_SET) == -1) { - err = got_error_from_errno("lseek"); - goto done; - } err = got_repo_search_packidx(&packidx, &idx, repo, id); if (err == NULL) { blob - 2484f3d63fb21e958d0acccaa36c3068b0f914f0 blob + dbfa06210469a59bc5a940787ba3ace5381315f0 --- lib/object_open_privsep.c +++ lib/object_open_privsep.c @@ -943,14 +943,9 @@ open_blob(struct got_blob_object **blob, struct got_re goto done; } - if (ftruncate(outfd, 0L) == -1) { - err = got_error_from_errno("ftruncate"); - goto done; - } - if (lseek(outfd, 0L, SEEK_SET) == -1) { - err = got_error_from_errno("lseek"); + err = got_opentemp_truncatefd(outfd); + if (err) goto done; - } err = got_repo_search_packidx(&packidx, &idx, repo, id); if (err == NULL) { blob - 92459dcbba069990e1f2f04edf7daaaf14322e9b blob + 14731673ee55811e65071b506239d1af5c93077a --- lib/repository.c +++ lib/repository.c @@ -388,6 +388,7 @@ got_repo_temp_fds_set(struct got_repository *repo, int const struct got_error * got_repo_temp_fds_get(int *fd, int *idx, struct got_repository *repo) { + const struct got_error *err = NULL; int i; *fd = -1; @@ -397,10 +398,9 @@ got_repo_temp_fds_get(int *fd, int *idx, struct got_re if (repo->tempfile_use_mask & (1 << i)) continue; if (repo->tempfiles[i] != -1) { - if (ftruncate(repo->tempfiles[i], 0L) == -1) - return got_error_from_errno("ftruncate"); - if (lseek(repo->tempfiles[i], 0L, SEEK_SET) == -1) - return got_error_from_errno("lseek"); + err = got_opentemp_truncatefd(repo->tempfiles[i]); + if (err) + return err; *fd = repo->tempfiles[i]; *idx = i; repo->tempfile_use_mask |= (1 << i); @@ -1604,14 +1604,12 @@ got_repo_cache_pack(struct got_pack **packp, struct go err = got_pack_close(&repo->packs[i]); if (err) return err; - if (ftruncate(repo->packs[i].basefd, 0L) == -1) - return got_error_from_errno("ftruncate"); - if (lseek(repo->packs[i].basefd, 0L, SEEK_SET) == -1) - return got_error_from_errno("lseek"); - if (ftruncate(repo->packs[i].accumfd, 0L) == -1) - return got_error_from_errno("ftruncate"); - if (lseek(repo->packs[i].accumfd, 0L, SEEK_SET) == -1) - return got_error_from_errno("lseek"); + err = got_opentemp_truncatefd(repo->packs[i].basefd); + if (err) + return err; + err = got_opentemp_truncatefd(repo->packs[i].accumfd); + if (err) + return err; } if (i != 0) {