Commit Diff


commit - 621a005dceebd02b4caeba30a35461c097640e5aa92a059ed91176b11dc1dad8
commit + 6dac328b1cd8adbdb847bcedd0b2ca9179c379b331e084a6ce8ff25a41c80ec2
blob - c61ebd2842a23a387576ff85d02408a7744667af65c2fbdd9b9058bd953f6320
blob + 791c67ff36bec9461c246bfe97c1ac4334e309f64609e2113ed4336de080e03b
--- 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 - b0044e1519e28ef0e9c047bde6dad79c0e057436ec11579c0eda65c9ffd379bb
blob + 6c25d0f031a57e203d5ba17e2d509529c99dee045046e2ea567a426f852ba9bc
--- 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 - 19bc6860d0b999f00540413b92e7b4150e0235bdbfc744f280217b255db670a5
blob + 2226caff05dd6806c9cc65d1e506f8e2edf7f1e3bd7ad2bad987d65407e95897
--- 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"
@@ -58,12 +59,7 @@ 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 - b83b3895eea4e83622af8007e44594378319a978ee854f6ec68a9f53e69df306
blob + 9a56cc93f0887155cc2fcabd1296edad9ebb86097ddb7cec82452f6379eb1324
--- 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,12 +173,10 @@ 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");
+	err = got_opentemp_truncatefd(wrapped_fd);
+	if (err)
+		return err;
 
-	if (lseek(wrapped_fd, 0L, SEEK_SET) == -1)
-		return got_error_from_errno("lseek");
-
 	fd = dup(wrapped_fd);
 	if (fd == -1)
 		return got_error_from_errno("dup");
@@ -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 - b15a8b5e15c59b2c737516a9207ca856a066d26f8dc89f17005c75ea5fc4caf0
blob + 4951c8b38af62bdf07b844695a6e6e9140c5a3b29f38a7cecc79fc14624e2a61
--- 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");
+	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 - d626a865602cb9c483e913c2691c67a353784e6b8bb0291ccaf1744a08d56fbc
blob + b0176d70d3f6b36277e37669123bb6c63db7f64668de72b484c984f98ca7fc2e
--- 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) {