commit 5390f96900deb1b202bbf84095e9ef6efd7673bd
parent 50ed18be176c178be7b0d4ec47e7f73b378584d0
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 18 Oct 2019 11:53:47 +0200
files: distinguish between read error and write error when prepending
This fixes https://savannah.gnu.org/bugs/?57066.
Bug existed in this form since version 2.4.3 -- in older versions
it segfaulted.
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/files.c b/src/files.c
@@ -1703,6 +1703,7 @@ bool write_file(const char *name, FILE *stream, bool tmp,
if (method == PREPEND) {
FILE *source = fopen(realname, "rb");
FILE *target = NULL;
+ int verdict;
if (source == NULL) {
statusline(ALERT, _("Error reading %s: %s"), realname,
@@ -1718,7 +1719,14 @@ bool write_file(const char *name, FILE *stream, bool tmp,
goto cleanup_and_exit;
}
- if (copy_file(source, target, TRUE) != 0) {
+ verdict = copy_file(source, target, TRUE);
+
+ if (verdict == -1) {
+ statusline(ALERT, _("Error reading %s: %s"), realname,
+ strerror(errno));
+ unlink(tempname);
+ goto cleanup_and_exit;
+ } else if (verdict == -2) {
statusline(ALERT, _("Error writing temp file: %s"),
strerror(errno));
unlink(tempname);