2 # $OpenBSD: SharedItems.pm,v 1.24 2010/06/18 09:05:03 espie Exp $
4 # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 package OpenBSD::SharedItems;
24 use OpenBSD::PackageInfo;
25 use OpenBSD::PackingList;
28 sub find_items_in_installed_packages
31 my $db = OpenBSD::SharedItemsRecorder->new;
32 $state->status->what("Read")->object("shared items");
33 $state->progress->for_list("Read shared items", [installed_packages()],
36 my $plist = OpenBSD::PackingList->from_installation($e,
37 \&OpenBSD::PackingList::SharedItemsOnly) or next;
38 return if !defined $plist;
39 $plist->record_shared($db, $e);
46 my ($recorder, $state) = @_;
48 my $remaining = find_items_in_installed_packages($state);
50 $state->progress->clear;
51 $state->status->what("Clean");
52 $state->progress->set_header("Clean shared items");
53 my $h = $recorder->{dirs};
54 my $u = $recorder->{users};
55 my $g = $recorder->{groups};
57 $total += keys %$h if defined $h;
58 $total += keys %$u if defined $u;
59 $total += keys %$g if defined $g;
62 for my $d (sort {$b cmp $a} keys %$h) {
63 $state->progress->show($done, $total);
64 my $realname = $state->{destdir}.$d;
65 if ($remaining->{dirs}->{$realname}) {
66 for my $i (@{$h->{$d}}) {
67 $state->log->set_context($i->{pkgname});
71 for my $i (@{$h->{$d}}) {
72 $state->log->set_context($i->{pkgname});
75 if (!rmdir $realname) {
76 $state->log("Error deleting directory #1: #2",
78 unless $state->{dirs_okay}->{$d};
83 while (my ($user, $pkgname) = each %$u) {
84 $state->progress->show($done, $total);
85 next if $remaining->{users}->{$user};
86 if ($state->{extra}) {
87 $state->system(OpenBSD::Paths->userdel, '--',
90 $state->log->set_context($pkgname);
91 $state->log("You should also run /usr/sbin/userdel #1", $user);
95 while (my ($group, $pkgname) = each %$g) {
96 $state->progress->show($done, $total);
97 next if $remaining->{groups}->{$group};
98 if ($state->{extra}) {
99 $state->system(OpenBSD::Paths->groupdel, '--',
102 $state->log->set_context($pkgname);
103 $state->log("You should also run /usr/sbin/groupdel #1", $group);
107 if ($state->verbose >= 2) {
108 $state->progress->next;
110 $state->progress->clear;
114 package OpenBSD::PackingElement;
123 package OpenBSD::PackingElement::Mandir;
126 my ($self, $state) = @_;
127 my $fullname = $state->{destdir}.$self->fullname;
128 $state->log("You may wish to remove #1 from man.conf", $fullname);
129 for my $f (OpenBSD::Paths->man_cruft) {
130 unlink("$fullname/$f");
134 package OpenBSD::PackingElement::Fontdir;
137 my ($self, $state) = @_;
138 my $fullname = $state->{destdir}.$self->fullname;
139 $state->log("You may wish to remove #1 from your font path", $fullname);
140 for my $f (OpenBSD::Paths->font_cruft) {
141 unlink("$fullname/$f");
145 package OpenBSD::PackingElement::Infodir;
148 my ($self, $state) = @_;
149 my $fullname = $state->{destdir}.$self->fullname;
150 for my $f (OpenBSD::Paths->info_cruft) {
151 unlink("$fullname/$f");