Commit Diff


commit - ef899790595636e3d4729e14971ad2843156dba9
commit + fc2a50f28951c340fb573e7fcb0646ddf93fde8f
blob - d19284b7528b98bca22ac529c892d3a3d20f34e9
blob + 7578e3c914d6acd6881cd996f0fbd10c94745f47
--- got/got.c
+++ got/got.c
@@ -518,7 +518,7 @@ collect_import_msg(char **logmsg, char **logmsg_path, 
 		return got_error_from_errno("asprintf");
 
 	err = got_opentemp_named_fd(logmsg_path, &fd,
-	    GOT_TMPDIR_STR "/got-importmsg");
+	    GOT_TMPDIR_STR "/got-importmsg", "");
 	if (err)
 		goto done;
 
@@ -7166,7 +7166,7 @@ get_tag_message(char **tagmsg, char **tagmsg_path, con
 		goto done;
 	}
 
-	err = got_opentemp_named_fd(tagmsg_path, &fd, template);
+	err = got_opentemp_named_fd(tagmsg_path, &fd, template, "");
 	if (err)
 		goto done;
 
@@ -8442,7 +8442,7 @@ collect_commit_logmsg(struct got_pathlist_head *commit
 	if (asprintf(&template, "%s/logmsg", a->worktree_path) == -1)
 		return got_error_from_errno("asprintf");
 
-	err = got_opentemp_named_fd(&a->logmsg_path, &fd, template);
+	err = got_opentemp_named_fd(&a->logmsg_path, &fd, template, "");
 	if (err)
 		goto done;
 
@@ -10732,7 +10732,7 @@ histedit_edit_logmsg(struct got_histedit_list_entry *h
 		goto done;
 
 	err = got_opentemp_named_fd(&logmsg_path, &fd,
-	    GOT_TMPDIR_STR "/got-logmsg");
+	    GOT_TMPDIR_STR "/got-logmsg", "");
 	if (err)
 		goto done;
 
@@ -10978,7 +10978,7 @@ histedit_edit_script(struct got_histedit_list *histedi
 	FILE *f = NULL;
 	char *path = NULL;
 
-	err = got_opentemp_named(&path, &f, "got-histedit");
+	err = got_opentemp_named(&path, &f, "got-histedit", "");
 	if (err)
 		return err;
 
blob - fd228f5e11199922a6911d4ffe3d24fed00cd1cc
blob + c785f4694dfc78b3ad5b5064cb0471be8ad70fae
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -905,7 +905,7 @@ recv_packfile(struct gotd_client *client)
 		goto done;
 	}
 
-	err = got_opentemp_named_fd(&pack_path, &packfd, basepath);
+	err = got_opentemp_named_fd(&pack_path, &packfd, basepath, "");
 	if (err)
 		goto done;
 
@@ -917,7 +917,7 @@ recv_packfile(struct gotd_client *client)
 		basepath = NULL;
 		goto done;
 	}
-	err = got_opentemp_named_fd(&idx_path, &idxfd, basepath);
+	err = got_opentemp_named_fd(&idx_path, &idxfd, basepath, "");
 	if (err)
 		goto done;
 
blob - 5df60c352cb02c68869dfd77742c78669f368df6
blob + 8c49224c3f3618922f155e0671044215eba5d031
--- include/got_opentemp.h
+++ include/got_opentemp.h
@@ -33,10 +33,12 @@ FILE *got_opentemp(void);
 
 /* Open a new temporary file for writing.
  * The file is visible in the filesystem. */
-const struct got_error *got_opentemp_named(char **, FILE **, const char *);
+const struct got_error *got_opentemp_named(char **, FILE **, const char *,
+    const char *);
 
 /* Like got_opentemp_named() but returns a file descriptor instead of a FILE. */
-const struct got_error *got_opentemp_named_fd(char **, int *, const char *);
+const struct got_error *got_opentemp_named_fd(char **, int *, const char *,
+    const char *);
 
 /* Truncate a file. This is useful for re-using open temporary files. */
 const struct got_error *got_opentemp_truncate(FILE *);
blob - aa587f957a502cfe88805538dd3b94c05b174498
blob + ddbcb7a24e9176cc112a20f881d069c75b749a37
--- lib/diff3.c
+++ lib/diff3.c
@@ -221,7 +221,7 @@ diffreg(BUF **d, const char *path1, const char *path2,
 	}
 
 	err = got_opentemp_named(&outpath, &outfile,
-	    GOT_TMPDIR_STR "/got-diffreg");
+	    GOT_TMPDIR_STR "/got-diffreg", "");
 	if (err)
 		goto done;
 
blob - 933f60daff9dfba84b076bb4d53e03af1d48831b
blob + fa7413ae8411122c7687d51f8121007fc1d7dc5c
--- lib/fetch.c
+++ lib/fetch.c
@@ -186,7 +186,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struc
 			err = got_error_from_errno("asprintf");
 			goto done;
 		}
-		err = got_opentemp_named_fd(&tmppackpath, &packfd, path);
+		err = got_opentemp_named_fd(&tmppackpath, &packfd, path, "");
 		free(path);
 		if (err)
 			goto done;
@@ -207,7 +207,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struc
 			err = got_error_from_errno("asprintf");
 			goto done;
 		}
-		err = got_opentemp_named_fd(&tmpidxpath, &idxfd, path);
+		err = got_opentemp_named_fd(&tmpidxpath, &idxfd, path, "");
 		free(path);
 		if (err)
 			goto done;
blob - 3b36523bb3fec9888a0551282782e8ec8d39d163
blob + 6edf50f52da0daa282b26ccb4fa82b57283d55bc
--- lib/object_create.c
+++ lib/object_create.c
@@ -68,7 +68,7 @@ create_object_file(struct got_object_id *id, FILE *con
 	if (err)
 		return err;
 
-	err = got_opentemp_named(&tmppath, &tmpfile, objpath);
+	err = got_opentemp_named(&tmppath, &tmpfile, objpath, "");
 	if (err) {
 		char *parent_path;
 		if (!(err->code == GOT_ERR_ERRNO && errno == ENOENT))
@@ -80,7 +80,7 @@ create_object_file(struct got_object_id *id, FILE *con
 		free(parent_path);
 		if (err)
 			goto done;
-		err = got_opentemp_named(&tmppath, &tmpfile, objpath);
+		err = got_opentemp_named(&tmppath, &tmpfile, objpath, "");
 		if (err)
 			goto done;
 	}
blob - c65936153fe14c9cfc2a0ca03e30d461c2610e3b
blob + df1d59c09c18d172241755b8756c1c74925ae5b3
--- lib/opentemp.c
+++ lib/opentemp.c
@@ -65,21 +65,22 @@ got_opentemp(void)
 }
 
 const struct got_error *
-got_opentemp_named(char **path, FILE **outfile, const char *basepath)
+got_opentemp_named(char **path, FILE **outfile, const char *basepath,
+    const char *suffix)
 {
 	const struct got_error *err = NULL;
 	int fd;
 
 	*outfile = NULL;
 
-	if (asprintf(path, "%s-XXXXXX", basepath) == -1) {
+	if (asprintf(path, "%s-XXXXXX%s", basepath, suffix) == -1) {
 		*path = NULL;
 		return got_error_from_errno("asprintf");
 	}
 
-	fd = mkstemp(*path);
+	fd = mkstemps(*path, strlen(suffix));
 	if (fd == -1) {
-		err = got_error_from_errno2("mkstemp", *path);
+		err = got_error_from_errno2("mkstemps", *path);
 		free(*path);
 		*path = NULL;
 		return err;
@@ -96,19 +97,20 @@ got_opentemp_named(char **path, FILE **outfile, const 
 }
 
 const struct got_error *
-got_opentemp_named_fd(char **path, int *outfd, const char *basepath)
+got_opentemp_named_fd(char **path, int *outfd, const char *basepath,
+    const char *suffix)
 {
 	const struct got_error *err = NULL;
 	int fd;
 
 	*outfd = -1;
 
-	if (asprintf(path, "%s-XXXXXX", basepath) == -1) {
+	if (asprintf(path, "%s-XXXXXX%s", basepath, suffix) == -1) {
 		*path = NULL;
 		return got_error_from_errno("asprintf");
 	}
 
-	fd = mkstemp(*path);
+	fd = mkstemps(*path, strlen(suffix));
 	if (fd == -1) {
 		err = got_error_from_errno("mkstemp");
 		free(*path);
blob - c0fc6a3072c20b18fa7a9f239b1869878c328691
blob + 2ff96da7823c45ecb7b30768597f413f7aef1b9e
--- lib/patch.c
+++ lib/patch.c
@@ -714,7 +714,8 @@ open_blob(char **path, FILE **fp, const char *blobid,
 	if (err)
 		goto done;
 
-	err = got_opentemp_named(path, fp, GOT_TMPDIR_STR "/got-patch-blob");
+	err = got_opentemp_named(path, fp, GOT_TMPDIR_STR "/got-patch-blob",
+	    "");
 	if (err)
 		goto done;
 
@@ -846,7 +847,7 @@ apply_patch(int *overlapcnt, struct got_worktree *work
 	} else if (p->xbit)
 		mode |= (S_IXUSR | S_IXGRP | S_IXOTH);
 
-	err = got_opentemp_named(&tmppath, &tmpfile, template);
+	err = got_opentemp_named(&tmppath, &tmpfile, template, "");
 	if (err)
 		goto done;
 	outfd = fileno(tmpfile);
@@ -903,7 +904,7 @@ apply_patch(int *overlapcnt, struct got_worktree *work
 			tmpfile = t;
 		}
 
-		err = got_opentemp_named(&mergepath, &mergefile, template);
+		err = got_opentemp_named(&mergepath, &mergefile, template, "");
 		if (err)
 			goto done;
 		outfd = fileno(mergefile);
blob - a3c9e0c37c610e0cdcde51ed5596edaecdbafd53
blob + 4ed86484703f323b382b8d0b79090c341cec8335
--- lib/reference.c
+++ lib/reference.c
@@ -1188,7 +1188,7 @@ got_ref_write(struct got_reference *ref, struct got_re
 		goto done;
 	}
 
-	err = got_opentemp_named(&tmppath, &f, path);
+	err = got_opentemp_named(&tmppath, &f, path, "");
 	if (err) {
 		char *parent;
 		if (!(err->code == GOT_ERR_ERRNO && errno == ENOENT))
@@ -1200,7 +1200,7 @@ got_ref_write(struct got_reference *ref, struct got_re
 		free(parent);
 		if (err)
 			goto done;
-		err = got_opentemp_named(&tmppath, &f, path);
+		err = got_opentemp_named(&tmppath, &f, path, "");
 		if (err)
 			goto done;
 	}
@@ -1296,7 +1296,7 @@ delete_packed_ref(struct got_reference *delref, struct
 	if (packed_refs_path == NULL)
 		return got_error_from_errno("got_repo_get_path_packed_refs");
 
-	err = got_opentemp_named(&tmppath, &tmpf, packed_refs_path);
+	err = got_opentemp_named(&tmppath, &tmpf, packed_refs_path, "");
 	if (err)
 		goto done;
 
blob - 600aae154a6488a127d0f703ea93de4a403dfa9a
blob + 1fd814ec776b8eef26d2461d00dce965bdbbcd96
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -163,7 +163,7 @@ got_repo_pack_objects(FILE **packfile, struct got_obje
 		err = got_error_from_errno("asprintf");
 		goto done;
 	}
-	err = got_opentemp_named_fd(&tmpfile_path, &packfd, path);
+	err = got_opentemp_named_fd(&tmpfile_path, &packfd, path, "");
 	if (err)
 		goto done;
 
@@ -293,7 +293,7 @@ got_repo_index_pack(FILE *packfile, struct got_object_
 		err = got_error_from_errno("asprintf");
 		goto done;
 	}
-	err = got_opentemp_named_fd(&tmpidxpath, &idxfd, path);
+	err = got_opentemp_named_fd(&tmpidxpath, &idxfd, path, "");
 	free(path);
 	if (err)
 		goto done;
blob - 3f930a7220e7a5403eeafb5e3c5ceaee7636551f
blob + bb6f7b48aba8f212300f99f8f6124870d2f9b8f4
--- lib/sigs.c
+++ lib/sigs.c
@@ -273,7 +273,7 @@ got_sigs_verify_tag_ssh(char **msg, struct got_tag_obj
 	*msg = NULL;
 
 	error = got_opentemp_named(&tmppath, &tmpsig,
-	    GOT_TMPDIR_STR "/got-tagsig");
+	    GOT_TMPDIR_STR "/got-tagsig", "");
 	if (error)
 		goto done;
 
blob - 253ca4d2df8501d6a156e3e410a44b4ba19cff25
blob + 17d5e53de83220c7a4c9c4b686378fdc234de517
--- lib/worktree.c
+++ lib/worktree.c
@@ -92,7 +92,7 @@ update_meta_file(const char *path_got, const char *nam
 		goto done;
 	}
 
-	err = got_opentemp_named(&tmppath, &tmpfile, path);
+	err = got_opentemp_named(&tmppath, &tmpfile, path, "");
 	if (err)
 		goto done;
 
@@ -554,15 +554,15 @@ merge_binary_file(int *overlapcnt, int merged_fd,
 			goto done;
 		}
 		err = got_opentemp_named_fd(&path_orig, &fd_orig,
-		    base_path_orig);
+		    base_path_orig, "");
 		if (err)
 			goto done;
 		err = got_opentemp_named_fd(&path_deriv, &fd_deriv,
-		    base_path_deriv);
+		    base_path_deriv, "");
 		if (err)
 			goto done;
 		err = got_opentemp_named_fd(&path_deriv2, &fd_deriv2,
-		    base_path_deriv2);
+		    base_path_deriv2, "");
 		if (err)
 			goto done;
 		err = copy_file_to_fd(&size_orig, f_orig, fd_orig);
@@ -662,7 +662,7 @@ merge_file(int *local_changes_subsumed, struct got_wor
 		goto done;
 	}
 
-	err = got_opentemp_named_fd(&merged_path, &merged_fd, base_path);
+	err = got_opentemp_named_fd(&merged_path, &merged_fd, base_path, "");
 	if (err)
 		goto done;
 
@@ -772,7 +772,7 @@ install_symlink_conflict(const char *deriv_target,
 		goto done;
 	}
 
-	err = got_opentemp_named(&path, &f, "got-symlink-conflict");
+	err = got_opentemp_named(&path, &f, "got-symlink-conflict", "");
 	if (err)
 		goto done;
 
@@ -990,7 +990,8 @@ merge_blob(int *local_changes_subsumed, struct got_wor
 			goto done;
 		}
 
-		err = got_opentemp_named(&blob_orig_path, &f_orig, base_path);
+		err = got_opentemp_named(&blob_orig_path, &f_orig,
+		    base_path, "");
 		if (err)
 			goto done;
 		err = got_object_blob_dump_to_file(NULL, NULL, NULL, f_orig,
@@ -1017,7 +1018,7 @@ merge_blob(int *local_changes_subsumed, struct got_wor
 		goto done;
 	}
 
-	err = got_opentemp_named(&blob_deriv_path, &f_deriv, base_path);
+	err = got_opentemp_named(&blob_deriv_path, &f_deriv, base_path, "");
 	if (err)
 		goto done;
 	err = got_object_blob_dump_to_file(NULL, NULL, NULL, f_deriv,
@@ -1433,7 +1434,7 @@ install_blob(struct got_worktree *worktree, const char
 				goto done;
 			} else {
 				err = got_opentemp_named_fd(&tmppath, &fd,
-				    ondisk_path);
+				    ondisk_path, "");
 				if (err)
 					goto done;
 				update = 1;
@@ -2467,7 +2468,7 @@ sync_fileindex(struct got_fileindex *fileindex, const 
 	struct timespec timeout;
 
 	err = got_opentemp_named(&new_fileindex_path, &new_index,
-	    fileindex_path);
+	    fileindex_path, "");
 	if (err)
 		goto done;
 
@@ -4550,7 +4551,7 @@ create_patched_content(char **path_outfile, int revers
 	if (err)
 		goto done;
 
-	err = got_opentemp_named(&path1, &f1, "got-patched-blob");
+	err = got_opentemp_named(&path1, &f1, "got-patched-blob", "");
 	if (err)
 		goto done;
 
@@ -4563,7 +4564,8 @@ create_patched_content(char **path_outfile, int revers
 	if (err)
 		goto done;
 
-	err = got_opentemp_named(path_outfile, &outfile, "got-patched-content");
+	err = got_opentemp_named(path_outfile, &outfile, "got-patched-content",
+	    "");
 	if (err)
 		goto done;
 
@@ -6152,7 +6154,7 @@ got_worktree_commit(struct got_object_id **new_commit_
 	cc_arg.diff_header_shown = 0;
 	if (show_diff) {
 		err = got_opentemp_named(&diff_path, &cc_arg.diff_outfile,
-		    GOT_TMPDIR_STR "/got-diff");
+		    GOT_TMPDIR_STR "/got", ".diff");
 		if (err)
 			goto done;
 		cc_arg.f1 = got_opentemp();
@@ -8609,7 +8611,7 @@ create_unstaged_content(char **path_unstaged_content,
 	if (err)
 		goto done;
 
-	err = got_opentemp_named(&path1, &f1, "got-unstage-blob-base");
+	err = got_opentemp_named(&path1, &f1, "got-unstage-blob-base", "");
 	if (err)
 		goto done;
 
@@ -8622,7 +8624,7 @@ create_unstaged_content(char **path_unstaged_content,
 	if (err)
 		goto done;
 
-	err = got_opentemp_named(&path2, &f2, "got-unstage-blob-staged");
+	err = got_opentemp_named(&path2, &f2, "got-unstage-blob-staged", "");
 	if (err)
 		goto done;
 
@@ -8636,11 +8638,11 @@ create_unstaged_content(char **path_unstaged_content,
 		goto done;
 
 	err = got_opentemp_named(path_unstaged_content, &outfile,
-	    "got-unstaged-content");
+	    "got-unstaged-content", "");
 	if (err)
 		goto done;
 	err = got_opentemp_named(path_new_staged_content, &rejectfile,
-	    "got-new-staged-content");
+	    "got-new-staged-content", "");
 	if (err)
 		goto done;
 
@@ -8799,7 +8801,8 @@ unstage_hunks(struct got_object_id *staged_blob_id,
 			goto done;
 		}
 
-		err = got_opentemp_named(&blob_base_path, &f_base, base_path);
+		err = got_opentemp_named(&blob_base_path, &f_base,
+		    base_path, "");
 		if (err)
 			goto done;
 		err = got_object_blob_dump_to_file(NULL, NULL, NULL, f_base,