tweaks: reshuffle some lines and adjust some indentation

master
Benno Schulenberg 2021-09-29 11:52:23 +02:00
parent e0334e861d
commit 36b6416a7b
1 changed files with 16 additions and 14 deletions

View File

@ -1791,25 +1791,27 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
/* When the user requested a backup, we do this only if the file exists and /* When the user requested a backup, we do this only if the file exists and
* isn't temporary AND the file has not been modified by someone else since * isn't temporary AND the file has not been modified by someone else since
* we opened it (or we are appending/prepending or writing a selection). */ * we opened it (or we are appending/prepending or writing a selection). */
if (ISSET(MAKE_BACKUP) && is_existing_file && openfile->statinfo && if (ISSET(MAKE_BACKUP) && is_existing_file && !S_ISFIFO(st.st_mode) &&
!S_ISFIFO(st.st_mode) && openfile->statinfo &&
(openfile->statinfo->st_mtime == st.st_mtime || (openfile->statinfo->st_mtime == st.st_mtime ||
method != OVERWRITE || openfile->mark)) { method != OVERWRITE || openfile->mark)) {
if (!make_backup_of(realname)) if (!make_backup_of(realname))
goto cleanup_and_exit; goto cleanup_and_exit;
} }
if (method == PREPEND && is_existing_file && S_ISFIFO(st.st_mode)) {
statusline(ALERT, _("Error writing %s: %s"), realname, "FIFO");
goto cleanup_and_exit;
}
/* When prepending, first copy the existing file to a temporary file. */ /* When prepending, first copy the existing file to a temporary file. */
if (method == PREPEND) { if (method == PREPEND) {
FILE *source = fopen(realname, "rb"); FILE *source = NULL;
FILE *target = NULL; FILE *target = NULL;
int verdict; int verdict;
if (is_existing_file && S_ISFIFO(st.st_mode)) {
statusline(ALERT, _("Error writing %s: %s"), realname, "FIFO");
goto cleanup_and_exit;
}
source = fopen(realname, "rb");
if (source == NULL) { if (source == NULL) {
statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno)); statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno));
goto cleanup_and_exit; goto cleanup_and_exit;
@ -1963,12 +1965,12 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
} }
if (!is_existing_file || !S_ISFIFO(st.st_mode)) if (!is_existing_file || !S_ISFIFO(st.st_mode))
/* Ensure the data has reached the disk before reporting it as written. */ /* Ensure the data has reached the disk before reporting it as written. */
if (fflush(thefile) != 0 || fsync(fileno(thefile)) != 0) { if (fflush(thefile) != 0 || fsync(fileno(thefile)) != 0) {
statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno)); statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
fclose(thefile); fclose(thefile);
goto cleanup_and_exit; goto cleanup_and_exit;
} }
#endif #endif
if (fclose(thefile) != 0) { if (fclose(thefile) != 0) {