Package: bsd-mailx / 8.1.2-0.20141216cvs-2

20-Don-t-delete-temporary-file.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From: Robert Luberda <robert@debian.org>
Date: Wed, 31 Mar 2004 23:01:00 +0200
Subject: 20 Don't delete temporary file

If the external editor (called by ~e or ~v commands) fails for
some reason, don't delete the temporary file if it has been modified.
This partly fixes bug#148071.
---
 edit.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/edit.c b/edit.c
index 73cc915..d951139 100644
--- a/edit.c
+++ b/edit.c
@@ -216,7 +216,22 @@ run_editor(FILE *fp, off_t size, int type, int readonly)
 			edit = _PATH_VI;
 	}
 	if (editit(edit, tempname) == -1) {
-		(void)rm(tempname);
+		/*
+		 * Don't delete the file if user has changed it
+		 * See Debian bug#148071
+		 * robert@debian.org, 2004.03.30
+		 */
+		if ( !readonly &&
+			!stat(tempname, &statb) &&
+			(modtime != statb.st_mtime)) {
+			printf(
+				"Saved changed message in %s\n"
+				"Please note that this file is located in temporary\n"
+				"directory and may disappear without any notice\n",
+				tempname);
+		} else {
+			(void)rm(tempname);
+		}
 		goto out;
 	}
 	/*