diff src/secure_save.c @ 313:a955b7fd626b

Secure save now unlinks temporary file on error by default. It will prevent left-behind temporary files, but also prevent potential data recovery from partially written files (it should not be a problem here).
author zas_
date Fri, 11 Apr 2008 16:46:21 +0000
parents 8a6650589829
children 4b2d7f9af171
line wrap: on
line diff
--- a/src/secure_save.c	Fri Apr 11 16:04:37 2008 +0000
+++ b/src/secure_save.c	Fri Apr 11 16:46:21 2008 +0000
@@ -83,6 +83,7 @@
 
 	ssi->secure_save = TRUE;
 	ssi->preserve_perms = TRUE;
+	ssi->unlink_on_error = TRUE;
 
 	ssi->file_name = g_strdup(file_name);
 	if (!ssi->file_name) {
@@ -106,7 +107,7 @@
 	} else {
 		if (!S_ISREG(st.st_mode)) {
 			/* Not a regular file, secure_save is disabled. */
-			ssi->secure_save = 0;
+			ssi->secure_save = FALSE;
 		} else {
 #ifdef HAVE_ACCESS
 			/* XXX: access() do not work with setuid programs. */
@@ -297,7 +298,11 @@
 	ret = 0;	/* Success. */
 
 free:
-	if (ssi->tmp_file_name) g_free(ssi->tmp_file_name);
+	if (ssi->tmp_file_name)
+		{
+		if (ret && ssi->unlink_on_error) unlink(ssi->tmp_file_name);
+		g_free(ssi->tmp_file_name);
+		}
 	if (ssi->file_name) g_free(ssi->file_name);
 	if (ssi) g_free(ssi);