| @@ -1,27 +1,27 @@ | | | @@ -1,27 +1,27 @@ |
1 | /* $NetBSD: plist.c,v 1.17.4.11 2008/08/25 18:31:14 joerg Exp $ */ | | 1 | /* $NetBSD: plist.c,v 1.17.4.12 2008/08/25 18:43:04 joerg Exp $ */ |
2 | | | 2 | |
3 | #if HAVE_CONFIG_H | | 3 | #if HAVE_CONFIG_H |
4 | #include "config.h" | | 4 | #include "config.h" |
5 | #endif | | 5 | #endif |
6 | #include <nbcompat.h> | | 6 | #include <nbcompat.h> |
7 | #if HAVE_SYS_CDEFS_H | | 7 | #if HAVE_SYS_CDEFS_H |
8 | #include <sys/cdefs.h> | | 8 | #include <sys/cdefs.h> |
9 | #endif | | 9 | #endif |
10 | #ifndef lint | | 10 | #ifndef lint |
11 | #if 0 | | 11 | #if 0 |
12 | static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp"; | | 12 | static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp"; |
13 | #else | | 13 | #else |
14 | __RCSID("$NetBSD: plist.c,v 1.17.4.11 2008/08/25 18:31:14 joerg Exp $"); | | 14 | __RCSID("$NetBSD: plist.c,v 1.17.4.12 2008/08/25 18:43:04 joerg Exp $"); |
15 | #endif | | 15 | #endif |
16 | #endif | | 16 | #endif |
17 | | | 17 | |
18 | /* | | 18 | /* |
19 | * FreeBSD install - a package for the installation and maintainance | | 19 | * FreeBSD install - a package for the installation and maintainance |
20 | * of non-core utilities. | | 20 | * of non-core utilities. |
21 | * | | 21 | * |
22 | * Redistribution and use in source and binary forms, with or without | | 22 | * Redistribution and use in source and binary forms, with or without |
23 | * modification, are permitted provided that the following conditions | | 23 | * modification, are permitted provided that the following conditions |
24 | * are met: | | 24 | * are met: |
25 | * 1. Redistributions of source code must retain the above copyright | | 25 | * 1. Redistributions of source code must retain the above copyright |
26 | * notice, this list of conditions and the following disclaimer. | | 26 | * notice, this list of conditions and the following disclaimer. |
27 | * 2. Redistributions in binary form must reproduce the above copyright | | 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -564,84 +564,85 @@ delete_package(Boolean ign_err, Boolean | | | @@ -564,84 +564,85 @@ delete_package(Boolean ign_err, Boolean |
564 | int restored = 0; /* restored from preserve? */ | | 564 | int restored = 0; /* restored from preserve? */ |
565 | | | 565 | |
566 | if (p->next && p->next->type == PLIST_COMMENT) { | | 566 | if (p->next && p->next->type == PLIST_COMMENT) { |
567 | if (strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) { | | 567 | if (strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) { |
568 | char *cp, buf[LegibleChecksumLen]; | | 568 | char *cp, buf[LegibleChecksumLen]; |
569 | | | 569 | |
570 | if ((cp = MD5File(tmp, buf)) != NULL) { | | 570 | if ((cp = MD5File(tmp, buf)) != NULL) { |
571 | /* Mismatch? */ | | 571 | /* Mismatch? */ |
572 | if (strcmp(cp, p->next->name + ChecksumHeaderLen) != 0) { | | 572 | if (strcmp(cp, p->next->name + ChecksumHeaderLen) != 0) { |
573 | printf("original MD5 checksum failed, %s: %s\n", | | 573 | printf("original MD5 checksum failed, %s: %s\n", |
574 | Force ? "deleting anyway" : "not deleting", tmp); | | 574 | Force ? "deleting anyway" : "not deleting", tmp); |
575 | if (!Force) { | | 575 | if (!Force) { |
576 | fail = FAIL; | | 576 | fail = FAIL; |
577 | continue; | | 577 | goto pkgdb_cleanup; |
578 | } | | 578 | } |
579 | } | | 579 | } |
580 | } | | 580 | } |
581 | } else if (strncmp(p->next->name, SYMLINK_HEADER, SymlinkHeaderLen) == 0) { | | 581 | } else if (strncmp(p->next->name, SYMLINK_HEADER, SymlinkHeaderLen) == 0) { |
582 | char buf[MaxPathSize + SymlinkHeaderLen]; | | 582 | char buf[MaxPathSize + SymlinkHeaderLen]; |
583 | int cc; | | 583 | int cc; |
584 | | | 584 | |
585 | (void) strlcpy(buf, SYMLINK_HEADER, | | 585 | (void) strlcpy(buf, SYMLINK_HEADER, |
586 | sizeof(buf)); | | 586 | sizeof(buf)); |
587 | if ((cc = readlink(tmp, &buf[SymlinkHeaderLen], | | 587 | if ((cc = readlink(tmp, &buf[SymlinkHeaderLen], |
588 | sizeof(buf) - SymlinkHeaderLen - 1)) < 0) { | | 588 | sizeof(buf) - SymlinkHeaderLen - 1)) < 0) { |
589 | warn("can't readlink `%s'", tmp); | | 589 | warn("can't readlink `%s'", tmp); |
590 | continue; | | 590 | goto pkgdb_cleanup; |
591 | } | | 591 | } |
592 | buf[SymlinkHeaderLen + cc] = 0x0; | | 592 | buf[SymlinkHeaderLen + cc] = 0x0; |
593 | if (strcmp(buf, p->next->name) != 0) { | | 593 | if (strcmp(buf, p->next->name) != 0) { |
594 | if ((cc = readlink(&buf[SymlinkHeaderLen], &buf[SymlinkHeaderLen], | | 594 | if ((cc = readlink(&buf[SymlinkHeaderLen], &buf[SymlinkHeaderLen], |
595 | sizeof(buf) - SymlinkHeaderLen)) < 0) { | | 595 | sizeof(buf) - SymlinkHeaderLen)) < 0) { |
596 | printf("symlink %s is not same as recorded value, %s: %s\n", | | 596 | printf("symlink %s is not same as recorded value, %s: %s\n", |
597 | buf, Force ? "deleting anyway" : "not deleting", tmp); | | 597 | buf, Force ? "deleting anyway" : "not deleting", tmp); |
598 | if (!Force) { | | 598 | if (!Force) { |
599 | fail = FAIL; | | 599 | fail = FAIL; |
600 | continue; | | 600 | goto pkgdb_cleanup; |
601 | } | | 601 | } |
602 | } | | 602 | } |
603 | buf[SymlinkHeaderLen + cc] = 0x0; | | 603 | buf[SymlinkHeaderLen + cc] = 0x0; |
604 | if (strcmp(buf, p->next->name) != 0) { | | 604 | if (strcmp(buf, p->next->name) != 0) { |
605 | printf("symlink %s is not same as recorded value, %s: %s\n", | | 605 | printf("symlink %s is not same as recorded value, %s: %s\n", |
606 | buf, Force ? "deleting anyway" : "not deleting", tmp); | | 606 | buf, Force ? "deleting anyway" : "not deleting", tmp); |
607 | if (!Force) { | | 607 | if (!Force) { |
608 | fail = FAIL; | | 608 | fail = FAIL; |
609 | continue; | | 609 | goto pkgdb_cleanup; |
610 | } | | 610 | } |
611 | } | | 611 | } |
612 | } | | 612 | } |
613 | } | | 613 | } |
614 | } | | 614 | } |
615 | if (Verbose && !NoDeleteFiles) | | 615 | if (Verbose && !NoDeleteFiles) |
616 | printf("Delete file %s\n", tmp); | | 616 | printf("Delete file %s\n", tmp); |
617 | if (!Fake && !NoDeleteFiles) { | | 617 | if (!Fake && !NoDeleteFiles) { |
618 | if (delete_hierarchy(tmp, ign_err, nukedirs)) | | 618 | if (delete_hierarchy(tmp, ign_err, nukedirs)) |
619 | fail = FAIL; | | 619 | fail = FAIL; |
620 | if (preserve && name) { | | 620 | if (preserve && name) { |
621 | char tmp2[MaxPathSize]; | | 621 | char tmp2[MaxPathSize]; |
622 | | | 622 | |
623 | if (make_preserve_name(tmp2, MaxPathSize, name, tmp)) { | | 623 | if (make_preserve_name(tmp2, MaxPathSize, name, tmp)) { |
624 | if (fexists(tmp2)) { | | 624 | if (fexists(tmp2)) { |
625 | if (rename(tmp2, tmp)) | | 625 | if (rename(tmp2, tmp)) |
626 | warn("preserve: unable to restore %s as %s", | | 626 | warn("preserve: unable to restore %s as %s", |
627 | tmp2, tmp); | | 627 | tmp2, tmp); |
628 | else | | 628 | else |
629 | restored = 1; | | 629 | restored = 1; |
630 | } | | 630 | } |
631 | } | | 631 | } |
632 | } | | 632 | } |
633 | } | | 633 | } |
634 | | | 634 | |
| | | 635 | pkgdb_cleanup: |
635 | if (!Fake) { | | 636 | if (!Fake) { |
636 | if (!restored) { | | 637 | if (!restored) { |
637 | errno = 0; | | 638 | errno = 0; |
638 | if (pkgdb_remove(tmp) && errno) | | 639 | if (pkgdb_remove(tmp) && errno) |
639 | perror("pkgdb_remove"); | | 640 | perror("pkgdb_remove"); |
640 | } | | 641 | } |
641 | } | | 642 | } |
642 | } | | 643 | } |
643 | break; | | 644 | break; |
644 | | | 645 | |
645 | case PLIST_DIR_RM: | | 646 | case PLIST_DIR_RM: |
646 | if (NoDeleteFiles) | | 647 | if (NoDeleteFiles) |
647 | break; | | 648 | break; |