tweaks: adjust some indentation after the previous change

Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
master
Michalis Kokologiannakis 2020-07-13 11:47:06 +03:00 committed by Benno Schulenberg
parent ed76a045ae
commit 14717d7449
1 changed files with 72 additions and 72 deletions

View File

@ -1597,15 +1597,15 @@ bool backup_file(char *realname, char **backupname)
bool second_attempt = FALSE; bool second_attempt = FALSE;
/* Whether a normal backup failed and we are resorting to a failsafe. */ /* Whether a normal backup failed and we are resorting to a failsafe. */
static struct timespec filetime[2]; static struct timespec filetime[2];
int backup_cflags, backup_fd, verdict; int backup_cflags, backup_fd, verdict;
FILE *original = NULL, *backup_file = NULL; FILE *original = NULL, *backup_file = NULL;
/* Remember the original file's access and modification times. */ /* Remember the original file's access and modification times. */
filetime[0].tv_sec = openfile->statinfo->st_atime; filetime[0].tv_sec = openfile->statinfo->st_atime;
filetime[1].tv_sec = openfile->statinfo->st_mtime; filetime[1].tv_sec = openfile->statinfo->st_mtime;
statusbar(_("Making backup...")); statusbar(_("Making backup..."));
/* If no backup directory was specified, we make a simple backup /* If no backup directory was specified, we make a simple backup
* by appending a tilde to the original file name. Otherwise, * by appending a tilde to the original file name. Otherwise,
@ -1661,89 +1661,89 @@ bool backup_file(char *realname, char **backupname)
backup_fd = open(*backupname, backup_cflags, S_IRUSR|S_IWUSR); backup_fd = open(*backupname, backup_cflags, S_IRUSR|S_IWUSR);
try_backup: try_backup:
if (backup_fd >= 0) if (backup_fd >= 0)
backup_file = fdopen(backup_fd, "wb"); backup_file = fdopen(backup_fd, "wb");
if (backup_file == NULL) if (backup_file == NULL)
goto backup_error; goto backup_error;
/* Try to change owner and group to those of the original file; /* Try to change owner and group to those of the original file;
* ignore errors, as a normal user cannot change the owner. */ * ignore errors, as a normal user cannot change the owner. */
IGNORE_CALL_RESULT(fchown(backup_fd, openfile->statinfo->st_uid, IGNORE_CALL_RESULT(fchown(backup_fd, openfile->statinfo->st_uid,
openfile->statinfo->st_gid)); openfile->statinfo->st_gid));
/* Set the backup's permissions to those of the original file. /* Set the backup's permissions to those of the original file.
* It is not a security issue if this fails, as we have created * It is not a security issue if this fails, as we have created
* the file with just read and write permission for the owner. */ * the file with just read and write permission for the owner. */
IGNORE_CALL_RESULT(fchmod(backup_fd, openfile->statinfo->st_mode)); IGNORE_CALL_RESULT(fchmod(backup_fd, openfile->statinfo->st_mode));
original = fopen(realname, "rb"); original = fopen(realname, "rb");
/* If we can't read from the original file, go on, since saving /* If we can't read from the original file, go on, since saving
* only the current buffer is better than saving nothing. */ * only the current buffer is better than saving nothing. */
if (original == NULL) { if (original == NULL) {
statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno)); statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno));
fclose(backup_file); fclose(backup_file);
return TRUE; return TRUE;
} }
/* Copy the existing file to the backup. */ /* Copy the existing file to the backup. */
verdict = copy_file(original, backup_file, FALSE); verdict = copy_file(original, backup_file, FALSE);
if (verdict < 0) { if (verdict < 0) {
fclose(backup_file); fclose(backup_file);
statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno)); statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno));
return FALSE; return FALSE;
} else if (verdict > 0) { } else if (verdict > 0) {
fclose(backup_file); fclose(backup_file);
goto backup_error; goto backup_error;
} }
/* Since this backup is a newly created file, explicitly sync it to /* Since this backup is a newly created file, explicitly sync it to
* permanent storage before starting to write out the actual file. */ * permanent storage before starting to write out the actual file. */
if (sync_file(backup_file) != 0) if (sync_file(backup_file) != 0)
goto backup_error; goto backup_error;
/* Set the backup's timestamps to those of the original file. /* Set the backup's timestamps to those of the original file.
* Failure is unimportant: saving the file apparently worked. */ * Failure is unimportant: saving the file apparently worked. */
IGNORE_CALL_RESULT(futimens(backup_fd, filetime)); IGNORE_CALL_RESULT(futimens(backup_fd, filetime));
if (fclose(backup_file) == 0) if (fclose(backup_file) == 0)
return TRUE; return TRUE;
backup_error: backup_error:
get_homedir(); get_homedir();
/* If the first attempt of copying the file failed, try again to HOME. */ /* If the first attempt of copying the file failed, try again to HOME. */
if (!second_attempt && homedir) { if (!second_attempt && homedir) {
unlink(*backupname); unlink(*backupname);
free(*backupname); free(*backupname);
*backupname = charalloc(strlen(homedir) + strlen(tail(realname)) + 9); *backupname = charalloc(strlen(homedir) + strlen(tail(realname)) + 9);
sprintf(*backupname, "%s/%s~XXXXXX", homedir, tail(realname)); sprintf(*backupname, "%s/%s~XXXXXX", homedir, tail(realname));
backup_fd = mkstemp(*backupname); backup_fd = mkstemp(*backupname);
backup_file = NULL; backup_file = NULL;
if (ISSET(MAKE_BACKUP)) { if (ISSET(MAKE_BACKUP)) {
warn_and_briefly_pause(_("Cannot make regular backup")); warn_and_briefly_pause(_("Cannot make regular backup"));
warn_and_briefly_pause(_("Trying again in your home directory")); warn_and_briefly_pause(_("Trying again in your home directory"));
currmenu = MMOST; currmenu = MMOST;
}
second_attempt = TRUE;
goto try_backup;
} }
/* If all attempts failed, notify the user, because if something goes second_attempt = TRUE;
* wrong during the save, the contents of the file might be lost. */ goto try_backup;
warn_and_briefly_pause(_("Cannot make backup")); }
if (!user_wants_to_proceed()) {
statusline(HUSH, _("Cannot write backup %s: %s"), /* If all attempts failed, notify the user, because if something goes
*backupname, strerror(errno)); * wrong during the save, the contents of the file might be lost. */
return FALSE; warn_and_briefly_pause(_("Cannot make backup"));
} if (!user_wants_to_proceed()) {
return TRUE; statusline(HUSH, _("Cannot write backup %s: %s"),
*backupname, strerror(errno));
return FALSE;
}
return TRUE;
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */