Lines 388-394
create_backup (char const *to, const struct stat *to_st, bool leave_original)
Link Here
|
388 |
|
388 |
|
389 |
try_makedirs_errno = ENOENT; |
389 |
try_makedirs_errno = ENOENT; |
390 |
safe_unlink (bakname); |
390 |
safe_unlink (bakname); |
391 |
while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0) |
391 |
while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0) |
392 |
{ |
392 |
{ |
393 |
if (errno != try_makedirs_errno) |
393 |
if (errno != try_makedirs_errno) |
394 |
pfatal ("Can't create file %s", quotearg (bakname)); |
394 |
pfatal ("Can't create file %s", quotearg (bakname)); |
Lines 579-588
create_file (char const *file, int open_flags, mode_t mode,
Link Here
|
579 |
static void |
579 |
static void |
580 |
copy_to_fd (const char *from, int tofd) |
580 |
copy_to_fd (const char *from, int tofd) |
581 |
{ |
581 |
{ |
|
|
582 |
int from_flags = O_RDONLY | O_BINARY; |
582 |
int fromfd; |
583 |
int fromfd; |
583 |
ssize_t i; |
584 |
ssize_t i; |
584 |
|
585 |
|
585 |
if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0) |
586 |
if (! follow_symlinks) |
|
|
587 |
from_flags |= O_NOFOLLOW; |
588 |
if ((fromfd = safe_open (from, from_flags, 0)) < 0) |
586 |
pfatal ("Can't reopen file %s", quotearg (from)); |
589 |
pfatal ("Can't reopen file %s", quotearg (from)); |
587 |
while ((i = read (fromfd, buf, bufsize)) != 0) |
590 |
while ((i = read (fromfd, buf, bufsize)) != 0) |
588 |
{ |
591 |
{ |
Lines 625-630
copy_file (char const *from, char const *to, struct stat *tost,
Link Here
|
625 |
else |
628 |
else |
626 |
{ |
629 |
{ |
627 |
assert (S_ISREG (mode)); |
630 |
assert (S_ISREG (mode)); |
|
|
631 |
if (! follow_symlinks) |
632 |
to_flags |= O_NOFOLLOW; |
628 |
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode, |
633 |
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode, |
629 |
to_dir_known_to_exist); |
634 |
to_dir_known_to_exist); |
630 |
copy_to_fd (from, tofd); |
635 |
copy_to_fd (from, tofd); |
Lines 640-648
copy_file (char const *from, char const *to, struct stat *tost,
Link Here
|
640 |
void |
645 |
void |
641 |
append_to_file (char const *from, char const *to) |
646 |
append_to_file (char const *from, char const *to) |
642 |
{ |
647 |
{ |
|
|
648 |
int to_flags = O_WRONLY | O_APPEND | O_BINARY; |
643 |
int tofd; |
649 |
int tofd; |
644 |
|
650 |
|
645 |
if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0) |
651 |
if (! follow_symlinks) |
|
|
652 |
to_flags |= O_NOFOLLOW; |
653 |
if ((tofd = safe_open (to, to_flags, 0)) < 0) |
646 |
pfatal ("Can't reopen file %s", quotearg (to)); |
654 |
pfatal ("Can't reopen file %s", quotearg (to)); |
647 |
copy_to_fd (from, tofd); |
655 |
copy_to_fd (from, tofd); |
648 |
if (close (tofd) != 0) |
656 |
if (close (tofd) != 0) |
649 |
- |
|
|