tweaks: rename two variables, to avoid a repetitive prefix
Also, fold a condition into an assignment, for conciseness.master
parent
a322dab482
commit
292e505e01
21
src/files.c
21
src/files.c
|
@ -1580,7 +1580,7 @@ int sync_file(FILE *thefile)
|
||||||
bool make_backup_of(char *realname)
|
bool make_backup_of(char *realname)
|
||||||
{
|
{
|
||||||
FILE *original = NULL, *backup_file = NULL;
|
FILE *original = NULL, *backup_file = NULL;
|
||||||
int backup_cflags, backup_fd, verdict;
|
int creation_flags, descriptor, verdict;
|
||||||
static struct timespec filetime[2];
|
static struct timespec filetime[2];
|
||||||
bool second_attempt = FALSE;
|
bool second_attempt = FALSE;
|
||||||
char *backupname = NULL;
|
char *backupname = NULL;
|
||||||
|
@ -1631,30 +1631,27 @@ bool make_backup_of(char *realname)
|
||||||
if (unlink(backupname) < 0 && errno != ENOENT && !ISSET(INSECURE_BACKUP))
|
if (unlink(backupname) < 0 && errno != ENOENT && !ISSET(INSECURE_BACKUP))
|
||||||
goto backup_error;
|
goto backup_error;
|
||||||
|
|
||||||
if (ISSET(INSECURE_BACKUP))
|
creation_flags = O_WRONLY|O_CREAT|(ISSET(INSECURE_BACKUP) ? O_TRUNC : O_EXCL);
|
||||||
backup_cflags = O_WRONLY | O_CREAT | O_TRUNC;
|
|
||||||
else
|
|
||||||
backup_cflags = O_WRONLY | O_CREAT | O_EXCL;
|
|
||||||
|
|
||||||
/* Create the backup file (or truncate the existing one). */
|
/* Create the backup file (or truncate the existing one). */
|
||||||
backup_fd = open(backupname, backup_cflags, S_IRUSR|S_IWUSR);
|
descriptor = open(backupname, creation_flags, S_IRUSR|S_IWUSR);
|
||||||
|
|
||||||
retry_backup:
|
retry_backup:
|
||||||
if (backup_fd >= 0)
|
if (descriptor >= 0)
|
||||||
backup_file = fdopen(backup_fd, "wb");
|
backup_file = fdopen(descriptor, "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(descriptor, 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(descriptor, openfile->statinfo->st_mode));
|
||||||
|
|
||||||
original = fopen(realname, "rb");
|
original = fopen(realname, "rb");
|
||||||
|
|
||||||
|
@ -1687,7 +1684,7 @@ bool make_backup_of(char *realname)
|
||||||
|
|
||||||
/* 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(descriptor, filetime));
|
||||||
|
|
||||||
if (fclose(backup_file) == 0) {
|
if (fclose(backup_file) == 0) {
|
||||||
free(backupname);
|
free(backupname);
|
||||||
|
@ -1709,7 +1706,7 @@ bool make_backup_of(char *realname)
|
||||||
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);
|
descriptor = mkstemp(backupname);
|
||||||
backup_file = NULL;
|
backup_file = NULL;
|
||||||
|
|
||||||
second_attempt = TRUE;
|
second_attempt = TRUE;
|
||||||
|
|
Loading…
Reference in New Issue