pkg_install-20090213: Fix pkg_delete -d: - ignore @dirrm commands, directories are removed already on demand - use local copy of dir before changing it, the caller expects it unmodified for the call to pkgdb_removediff -r1.46 -r1.47 pkgsrc/pkgtools/pkg_install/files/lib/lib.h
(joerg)
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lib.h,v 1.46 2009/02/02 12:35:01 joerg Exp $ */ | 1 | /* $NetBSD: lib.h,v 1.47 2009/02/13 01:31:42 joerg Exp $ */ | |
2 | 2 | |||
3 | /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ | 3 | /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ | |
4 | 4 | |||
5 | /* | 5 | /* | |
6 | * FreeBSD install - a package for the installation and maintainance | 6 | * FreeBSD install - a package for the installation and maintainance | |
7 | * of non-core utilities. | 7 | * of non-core utilities. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -298,27 +298,27 @@ int match_local_files(const char *, int, | @@ -298,27 +298,27 @@ int match_local_files(const char *, int, | |||
298 | 298 | |||
299 | /* File */ | 299 | /* File */ | |
300 | Boolean fexists(const char *); | 300 | Boolean fexists(const char *); | |
301 | Boolean isdir(const char *); | 301 | Boolean isdir(const char *); | |
302 | Boolean islinktodir(const char *); | 302 | Boolean islinktodir(const char *); | |
303 | Boolean isemptydir(const char *); | 303 | Boolean isemptydir(const char *); | |
304 | Boolean isemptyfile(const char *); | 304 | Boolean isemptyfile(const char *); | |
305 | Boolean isfile(const char *); | 305 | Boolean isfile(const char *); | |
306 | Boolean isbrokenlink(const char *); | 306 | Boolean isbrokenlink(const char *); | |
307 | Boolean isempty(const char *); | 307 | Boolean isempty(const char *); | |
308 | int URLlength(const char *); | 308 | int URLlength(const char *); | |
309 | Boolean make_preserve_name(char *, size_t, char *, char *); | 309 | Boolean make_preserve_name(char *, size_t, char *, char *); | |
310 | void remove_files(const char *, const char *); | 310 | void remove_files(const char *, const char *); | |
311 | int delete_hierarchy(char *, Boolean, Boolean); | 311 | int delete_hierarchy(const char *, Boolean, Boolean); | |
312 | int format_cmd(char *, size_t, const char *, const char *, const char *); | 312 | int format_cmd(char *, size_t, const char *, const char *, const char *); | |
313 | 313 | |||
314 | int recursive_remove(const char *, int); | 314 | int recursive_remove(const char *, int); | |
315 | 315 | |||
316 | /* pkg_io.c: Local and remote archive handling */ | 316 | /* pkg_io.c: Local and remote archive handling */ | |
317 | struct archive; | 317 | struct archive; | |
318 | struct archive_entry; | 318 | struct archive_entry; | |
319 | 319 | |||
320 | struct archive *open_archive(const char *, void **); | 320 | struct archive *open_archive(const char *, void **); | |
321 | void close_archive(void *); | 321 | void close_archive(void *); | |
322 | struct archive *find_archive(const char *, void **); | 322 | struct archive *find_archive(const char *, void **); | |
323 | 323 | |||
324 | /* Packing list */ | 324 | /* Packing list */ |
@@ -1,23 +1,23 @@ | @@ -1,23 +1,23 @@ | |||
1 | /* $NetBSD: plist.c,v 1.22 2009/02/02 12:35:01 joerg Exp $ */ | 1 | /* $NetBSD: plist.c,v 1.23 2009/02/13 01:31:42 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 | __RCSID("$NetBSD: plist.c,v 1.22 2009/02/02 12:35:01 joerg Exp $"); | 10 | __RCSID("$NetBSD: plist.c,v 1.23 2009/02/13 01:31:42 joerg Exp $"); | |
11 | 11 | |||
12 | /* | 12 | /* | |
13 | * FreeBSD install - a package for the installation and maintainance | 13 | * FreeBSD install - a package for the installation and maintainance | |
14 | * of non-core utilities. | 14 | * of non-core utilities. | |
15 | * | 15 | * | |
16 | * Redistribution and use in source and binary forms, with or without | 16 | * Redistribution and use in source and binary forms, with or without | |
17 | * modification, are permitted provided that the following conditions | 17 | * modification, are permitted provided that the following conditions | |
18 | * are met: | 18 | * are met: | |
19 | * 1. Redistributions of source code must retain the above copyright | 19 | * 1. Redistributions of source code must retain the above copyright | |
20 | * notice, this list of conditions and the following disclaimer. | 20 | * notice, this list of conditions and the following disclaimer. | |
21 | * 2. Redistributions in binary form must reproduce the above copyright | 21 | * 2. Redistributions in binary form must reproduce the above copyright | |
22 | * notice, this list of conditions and the following disclaimer in the | 22 | * notice, this list of conditions and the following disclaimer in the | |
23 | * documentation and/or other materials provided with the distribution. | 23 | * documentation and/or other materials provided with the distribution. | |
@@ -628,27 +628,27 @@ delete_package(Boolean ign_err, Boolean | @@ -628,27 +628,27 @@ delete_package(Boolean ign_err, Boolean | |||
628 | 628 | |||
629 | pkgdb_cleanup: | 629 | pkgdb_cleanup: | |
630 | if (!Fake) { | 630 | if (!Fake) { | |
631 | if (!restored) { | 631 | if (!restored) { | |
632 | errno = 0; | 632 | errno = 0; | |
633 | if (pkgdb_remove(tmp) && errno) | 633 | if (pkgdb_remove(tmp) && errno) | |
634 | perror("pkgdb_remove"); | 634 | perror("pkgdb_remove"); | |
635 | } | 635 | } | |
636 | } | 636 | } | |
637 | } | 637 | } | |
638 | break; | 638 | break; | |
639 | 639 | |||
640 | case PLIST_DIR_RM: | 640 | case PLIST_DIR_RM: | |
641 | if (NoDeleteFiles) | 641 | if (NoDeleteFiles || nukedirs) | |
642 | break; | 642 | break; | |
643 | 643 | |||
644 | (void) snprintf(tmp, sizeof(tmp), "%s%s%s/%s", | 644 | (void) snprintf(tmp, sizeof(tmp), "%s%s%s/%s", | |
645 | destdir ? destdir : "", destdir ? "/" : "", | 645 | destdir ? destdir : "", destdir ? "/" : "", | |
646 | Where, p->name); | 646 | Where, p->name); | |
647 | if (fexists(tmp)) { | 647 | if (fexists(tmp)) { | |
648 | if (!isdir(tmp)) { | 648 | if (!isdir(tmp)) { | |
649 | warnx("cannot remove `%s' as a directory\n" | 649 | warnx("cannot remove `%s' as a directory\n" | |
650 | "this packing list is incorrect - ignoring delete request", tmp); | 650 | "this packing list is incorrect - ignoring delete request", tmp); | |
651 | } else { | 651 | } else { | |
652 | if (Verbose) | 652 | if (Verbose) | |
653 | printf("Delete directory %s\n", tmp); | 653 | printf("Delete directory %s\n", tmp); | |
654 | if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) { | 654 | if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) { | |
@@ -665,56 +665,60 @@ pkgdb_cleanup: | @@ -665,56 +665,60 @@ pkgdb_cleanup: | |||
665 | default: | 665 | default: | |
666 | break; | 666 | break; | |
667 | } | 667 | } | |
668 | } | 668 | } | |
669 | pkgdb_close(); | 669 | pkgdb_close(); | |
670 | return fail; | 670 | return fail; | |
671 | } | 671 | } | |
672 | 672 | |||
673 | /* | 673 | /* | |
674 | * Selectively delete a hierarchy | 674 | * Selectively delete a hierarchy | |
675 | * Returns 1 on error, 0 else. | 675 | * Returns 1 on error, 0 else. | |
676 | */ | 676 | */ | |
677 | int | 677 | int | |
678 | delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs) | 678 | delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs) | |
679 | { | 679 | { | |
680 | char *cp1, *cp2; | 680 | char *cp1, *cp2, *tmp_dir; | |
681 | 681 | |||
682 | cp1 = cp2 = dir; | |||
683 | if (!fexists(dir)) { | 682 | if (!fexists(dir)) { | |
684 | if (!ign_err) | 683 | if (!ign_err) | |
685 | warnx("%s `%s' doesn't really exist", | 684 | warnx("%s `%s' doesn't really exist", | |
686 | isdir(dir) ? "directory" : "file", dir); | 685 | isdir(dir) ? "directory" : "file", dir); | |
687 | return !ign_err; | 686 | return !ign_err; | |
688 | } else if (nukedirs) { | 687 | } else if (nukedirs) { | |
689 | if (recursive_remove(dir, ign_err)) { | 688 | if (recursive_remove(dir, ign_err)) { | |
690 | warn("Couldn't remove %s", dir); | 689 | warn("Couldn't remove %s", dir); | |
691 | return 1; | 690 | return 1; | |
692 | } | 691 | } | |
693 | } else if (isdir(dir)) { | 692 | } else if (isdir(dir)) { | |
694 | if (rmdir(dir) && !ign_err) | 693 | if (rmdir(dir) && !ign_err) | |
695 | return 1; | 694 | return 1; | |
696 | } else { | 695 | } else { | |
697 | if (remove(dir) && !ign_err) | 696 | if (remove(dir) && !ign_err) | |
698 | return 1; | 697 | return 1; | |
699 | } | 698 | } | |
700 | 699 | |||
701 | if (!nukedirs) | 700 | if (!nukedirs) | |
702 | return 0; | 701 | return 0; | |
702 | ||||
703 | cp1 = cp2 = tmp_dir = xstrdup(dir);; | |||
704 | ||||
703 | while (cp2) { | 705 | while (cp2) { | |
704 | if ((cp2 = strrchr(cp1, '/')) != NULL) | 706 | if ((cp2 = strrchr(cp1, '/')) != NULL) | |
705 | *cp2 = '\0'; | 707 | *cp2 = '\0'; | |
706 | if (!isemptydir(dir)) | 708 | if (!isemptydir(tmp_dir)) | |
707 | return 0; | 709 | break; | |
708 | if (rmdir(dir) && !ign_err) { | 710 | if (rmdir(tmp_dir) && !ign_err) { | |
709 | if (!fexists(dir)) | 711 | if (fexists(tmp_dir)) { | |
710 | warnx("directory `%s' doesn't really exist", dir); | 712 | free(tmp_dir); | |
711 | else | |||
712 | return 1; | 713 | return 1; | |
714 | } | |||
715 | warnx("directory `%s' doesn't really exist", tmp_dir); | |||
713 | } | 716 | } | |
714 | /* back up the pathname one component */ | 717 | /* back up the pathname one component */ | |
715 | if (cp2) { | 718 | if (cp2) { | |
716 | cp1 = dir; | 719 | cp1 = tmp_dir; | |
717 | } | 720 | } | |
718 | } | 721 | } | |
722 | free(tmp_dir); | |||
719 | return 0; | 723 | return 0; | |
720 | } | 724 | } |
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: version.h,v 1.110 2009/02/11 23:42:42 joerg Exp $ */ | 1 | /* $NetBSD: version.h,v 1.111 2009/02/13 01:31:42 joerg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001 Thomas Klausner. All rights reserved. | 4 | * Copyright (c) 2001 Thomas Klausner. All rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -17,16 +17,16 @@ | @@ -17,16 +17,16 @@ | |||
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | */ | 25 | */ | |
26 | 26 | |||
27 | #ifndef _INST_LIB_VERSION_H_ | 27 | #ifndef _INST_LIB_VERSION_H_ | |
28 | #define _INST_LIB_VERSION_H_ | 28 | #define _INST_LIB_VERSION_H_ | |
29 | 29 | |||
30 | #define PKGTOOLS_VERSION "20090212" | 30 | #define PKGTOOLS_VERSION "20090213" | |
31 | 31 | |||
32 | #endif /* _INST_LIB_VERSION_H_ */ | 32 | #endif /* _INST_LIB_VERSION_H_ */ |