Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 02b6820

Browse files
committedAug 30, 2022
deal with two error cases
1 parent f563c9a commit 02b6820

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎src/diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
445445
memset(&small_header, 0, sizeof(struct header_v21));
446446
memcpy(&small_header.magic, BSDIFF_HDR_FULLDL, 8);
447447

448-
efd = open(delta_filename, O_CREAT | O_EXCL | O_WRONLY, 00644);
448+
efd = open(delta_filename_unique, O_CREAT | O_EXCL | O_WRONLY, 00644);
449449
if (efd < 0) {
450450
close(fd);
451451
return -1;
@@ -462,6 +462,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
462462
}
463463
fclose(pf);
464464
close(fd);
465+
rename(delta_filename_unique, delta_filename);
465466
return 1;
466467
}
467468

@@ -527,7 +528,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
527528
memset(&small_header, 0, sizeof(struct header_v21));
528529
memcpy(&small_header.magic, BSDIFF_HDR_FULLDL, 8);
529530

530-
efd = open(delta_filename, O_CREAT | O_EXCL | O_WRONLY, 00644);
531+
efd = open(delta_filename_unique, O_CREAT | O_EXCL | O_WRONLY, 00644);
531532
if (efd < 0) {
532533
close(fd);
533534
munmap(old_data, old_size);
@@ -553,6 +554,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
553554
close(fd);
554555
munmap(old_data, old_size);
555556
free(I);
557+
rename(delta_filename_unique, delta_filename);
556558
return 1;
557559
}
558560

0 commit comments

Comments
 (0)
Please sign in to comment.