aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-04-08 07:18:08 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-04-08 07:18:08 +0000
commit13e9c7ad8242212930aad54e71e00b1fa653532c (patch)
treebe1c1bc66fb3e0fe6dab7e0f7bd1025474dc561b
parent0e757a2f3f120abbd6186561399fc8180d7a9376 (diff)
downloadbusybox-w32-13e9c7ad8242212930aad54e71e00b1fa653532c.tar.gz
busybox-w32-13e9c7ad8242212930aad54e71e00b1fa653532c.tar.bz2
busybox-w32-13e9c7ad8242212930aad54e71e00b1fa653532c.zip
It now correctly backs up the (still corrupt) status file
-rw-r--r--archival/dpkg.c31
-rw-r--r--dpkg.c31
2 files changed, 42 insertions, 20 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index d05198cbf..b0f6adcd3 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -478,7 +478,6 @@ static int status_merge(void *status, package_t *pkgs)
478 char *line = NULL; 478 char *line = NULL;
479 package_t *pkg = 0, *statpkg = 0; 479 package_t *pkg = 0, *statpkg = 0;
480 package_t locpkg; 480 package_t locpkg;
481 int r = 0;
482 481
483 if ((fout = wfopen(new_statusfile, "w")) == NULL) { 482 if ((fout = wfopen(new_statusfile, "w")) == NULL) {
484 return 0; 483 return 0;
@@ -486,7 +485,10 @@ static int status_merge(void *status, package_t *pkgs)
486 if (getenv(udpkg_quiet) == NULL) { 485 if (getenv(udpkg_quiet) == NULL) {
487 printf("(Updating database...)\n"); 486 printf("(Updating database...)\n");
488 } 487 }
489 if ((fin = wfopen(statusfile, "r")) != NULL) { 488 /*
489 * Dont use wfopen here, handle errors ourself
490 */
491 if ((fin = fopen(statusfile, "r")) != NULL) {
490 while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) { 492 while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
491 line[strlen(line) - 1] = '\0'; /* trim newline */ 493 line[strlen(line) - 1] = '\0'; /* trim newline */
492 /* If we see a package header, find out if it's a package 494 /* If we see a package header, find out if it's a package
@@ -495,14 +497,14 @@ static int status_merge(void *status, package_t *pkgs)
495 * 497 *
496 * we also look at packages in the status cache and update 498 * we also look at packages in the status cache and update
497 * their status fields 499 * their status fields
498 */ 500 */
499 if (strstr(line, "Package: ") == line) { 501 if (strstr(line, "Package: ") == line) {
500 for (pkg = pkgs; pkg != 0 && strcmp(line + 9, 502 for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
501 pkg->package) != 0; pkg = pkg->next) ; 503 pkg->package) != 0; pkg = pkg->next) ;
502 504
503 locpkg.package = line + 9; 505 locpkg.package = line + 9;
504 statpkg = tfind(&locpkg, &status, package_compare); 506 statpkg = tfind(&locpkg, &status, package_compare);
505 507
506 /* note: statpkg should be non-zero, unless the status 508 /* note: statpkg should be non-zero, unless the status
507 * file was changed while we are processing (no locking 509 * file was changed while we are processing (no locking
508 * is currently done... 510 * is currently done...
@@ -521,6 +523,7 @@ static int status_merge(void *status, package_t *pkgs)
521 fputs(line, fout); 523 fputs(line, fout);
522 fputc('\n', fout); 524 fputc('\n', fout);
523 } 525 }
526 fclose(fin);
524 } 527 }
525 free(line); 528 free(line);
526 529
@@ -538,16 +541,24 @@ static int status_merge(void *status, package_t *pkgs)
538 fprintf(fout, "Description: %s\n", pkg->description); 541 fprintf(fout, "Description: %s\n", pkg->description);
539 fputc('\n', fout); 542 fputc('\n', fout);
540 } 543 }
541
542 fclose(fin);
543 fclose(fout); 544 fclose(fout);
544 545
545 r = rename(statusfile, bak_statusfile); 546 /*
546 if (r == 0) { 547 * Its ok if renaming statusfile fails becasue it doesnt exist
547 r = rename(new_statusfile, statusfile); 548 */
549 if (rename(statusfile, bak_statusfile) == -1) {
550 struct stat stat_buf;
551 error_msg("Couldnt create backup status file");
552 if (stat(statusfile, &stat_buf) == 0) {
553 return(EXIT_FAILURE);
554 }
548 } 555 }
549 556
550 return 0; 557 if (rename(new_statusfile, statusfile) == -1) {
558 error_msg("Couldnt create status file");
559 return(EXIT_FAILURE);
560 }
561 return(EXIT_SUCCESS);
551} 562}
552 563
553static int is_file(const char *fn) 564static int is_file(const char *fn)
diff --git a/dpkg.c b/dpkg.c
index d05198cbf..b0f6adcd3 100644
--- a/dpkg.c
+++ b/dpkg.c
@@ -478,7 +478,6 @@ static int status_merge(void *status, package_t *pkgs)
478 char *line = NULL; 478 char *line = NULL;
479 package_t *pkg = 0, *statpkg = 0; 479 package_t *pkg = 0, *statpkg = 0;
480 package_t locpkg; 480 package_t locpkg;
481 int r = 0;
482 481
483 if ((fout = wfopen(new_statusfile, "w")) == NULL) { 482 if ((fout = wfopen(new_statusfile, "w")) == NULL) {
484 return 0; 483 return 0;
@@ -486,7 +485,10 @@ static int status_merge(void *status, package_t *pkgs)
486 if (getenv(udpkg_quiet) == NULL) { 485 if (getenv(udpkg_quiet) == NULL) {
487 printf("(Updating database...)\n"); 486 printf("(Updating database...)\n");
488 } 487 }
489 if ((fin = wfopen(statusfile, "r")) != NULL) { 488 /*
489 * Dont use wfopen here, handle errors ourself
490 */
491 if ((fin = fopen(statusfile, "r")) != NULL) {
490 while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) { 492 while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
491 line[strlen(line) - 1] = '\0'; /* trim newline */ 493 line[strlen(line) - 1] = '\0'; /* trim newline */
492 /* If we see a package header, find out if it's a package 494 /* If we see a package header, find out if it's a package
@@ -495,14 +497,14 @@ static int status_merge(void *status, package_t *pkgs)
495 * 497 *
496 * we also look at packages in the status cache and update 498 * we also look at packages in the status cache and update
497 * their status fields 499 * their status fields
498 */ 500 */
499 if (strstr(line, "Package: ") == line) { 501 if (strstr(line, "Package: ") == line) {
500 for (pkg = pkgs; pkg != 0 && strcmp(line + 9, 502 for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
501 pkg->package) != 0; pkg = pkg->next) ; 503 pkg->package) != 0; pkg = pkg->next) ;
502 504
503 locpkg.package = line + 9; 505 locpkg.package = line + 9;
504 statpkg = tfind(&locpkg, &status, package_compare); 506 statpkg = tfind(&locpkg, &status, package_compare);
505 507
506 /* note: statpkg should be non-zero, unless the status 508 /* note: statpkg should be non-zero, unless the status
507 * file was changed while we are processing (no locking 509 * file was changed while we are processing (no locking
508 * is currently done... 510 * is currently done...
@@ -521,6 +523,7 @@ static int status_merge(void *status, package_t *pkgs)
521 fputs(line, fout); 523 fputs(line, fout);
522 fputc('\n', fout); 524 fputc('\n', fout);
523 } 525 }
526 fclose(fin);
524 } 527 }
525 free(line); 528 free(line);
526 529
@@ -538,16 +541,24 @@ static int status_merge(void *status, package_t *pkgs)
538 fprintf(fout, "Description: %s\n", pkg->description); 541 fprintf(fout, "Description: %s\n", pkg->description);
539 fputc('\n', fout); 542 fputc('\n', fout);
540 } 543 }
541
542 fclose(fin);
543 fclose(fout); 544 fclose(fout);
544 545
545 r = rename(statusfile, bak_statusfile); 546 /*
546 if (r == 0) { 547 * Its ok if renaming statusfile fails becasue it doesnt exist
547 r = rename(new_statusfile, statusfile); 548 */
549 if (rename(statusfile, bak_statusfile) == -1) {
550 struct stat stat_buf;
551 error_msg("Couldnt create backup status file");
552 if (stat(statusfile, &stat_buf) == 0) {
553 return(EXIT_FAILURE);
554 }
548 } 555 }
549 556
550 return 0; 557 if (rename(new_statusfile, statusfile) == -1) {
558 error_msg("Couldnt create status file");
559 return(EXIT_FAILURE);
560 }
561 return(EXIT_SUCCESS);
551} 562}
552 563
553static int is_file(const char *fn) 564static int is_file(const char *fn)