source: trunk/base/src/port1.0/portuninstall.tcl @ 1200

Last change on this file since 1200 was 1200, checked in by torrey, 18 years ago

Resync with changes accidentally made on lamancha.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.4 KB
Line 
1# ex:ts=4
2# portuninstall.tcl
3#
4# Copyright (c) 2002 Apple Computer, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
16#    may be used to endorse or promote products derived from this software
17#    without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31
32package provide portuninstall 1.0
33package require portutil 1.0
34
35set com.apple.uninstall [target_new com.apple.uninstall uninstall_main]
36${com.apple.uninstall} set runtype always
37${com.apple.uninstall} provides uninstall
38${com.apple.uninstall} requires main
39${com.apple.uninstall} set prerun uninstall_start
40
41# define options
42options uninstall.force uninstall.nochecksum
43
44set UI_PREFIX "---> "
45
46proc uninstall_start {args} {
47    global portname portversion UI_PREFIX
48
49    if [string length [registry_exists $portname $portversion]] {
50        ui_msg "$UI_PREFIX Uninstalling $portname-$portversion"
51    }
52}
53
54proc uninstall_main {args} {
55    global portname portversion uninstall.force uninstall.nochecksum ports_force UI_PREFIX
56
57    # If global forcing is on, make it the same as a local force flag.
58    if [tbool ports_force] {
59        set uninstall.force "yes"
60    }
61
62    set rfile [registry_exists $portname $portversion]
63    if [string length $rfile] {
64        if [regexp .bz2$ $rfile] {
65            set fd [open "|bunzip2 -c $rfile" r]
66        } else {
67            set fd [open $rfile r]
68        }
69        set entry [read $fd]
70        close $fd
71
72        # First look to see if the port has registered an uninstall procedure
73        set ix [lsearch $entry pkg_uninstall]
74        if {$ix >= 0} {
75            set uninstall [lindex $entry [incr ix]]
76            if ![catch {eval $uninstall} err] {
77                pkg_uninstall $portname $portversion
78            } else {
79                ui_error "Could not evaluate pkg_uninstall procedure: $err"
80            }
81        }
82
83        # Now look for a contents list
84        set ix [lsearch $entry contents]
85        if {$ix >= 0} {
86            set contents [lindex $entry [incr ix]]
87            set uninst_err 0
88            foreach f $contents {
89                set fname [lindex $f 0]
90                set sumx [lindex $f [lsearch -regex $f MD5]]
91                set sum1 [lindex $sumx [expr [llength $sumx] - 1]]
92                if {![string match $sum1 NONE] && ![tbool uninstall.nochecksum]} {
93                    if ![catch {set sum2 [md5 $fname]}] {
94                        if ![string match $sum1 $sum2] {
95                            if ![tbool uninstall.force] {
96                                ui_info "$UI_PREFIX  Original checksum does not match for $fname, not removing"
97                                set uninst_err 1
98                                continue
99                            } else {
100                                ui_info "$UI_PREFIX  Original checksum does not match for $fname, removing anyway [force in effect]"
101                            }
102                        }
103                    }
104                }
105                ui_info "$UI_PREFIX   Uninstall is removing $fname"
106                if [file isdirectory $fname] {
107                    if [catch {exec rmdir $fname}] {
108                        if ![tbool uninstall.force] {
109                            ui_info "$UI_PREFIX  Uninstall unable to remove directory $fname (not empty?)"
110                            set uninst_err 1
111                        } else {
112                            # No, I INSIST!
113                            exec rm -rf $fname
114                        }
115                    }
116                } else {
117                    if [catch {exec rm $fname}] {
118                        ui_info "$UI_PREFIX  Uninstall unable to remove file $fname"
119                        set uninst_err 1
120                    }
121                }
122            }
123            if {!$uninst_err || [tbool uninstall.force]} {
124                registry_delete $portname $portversion
125                return 0
126            }
127        } else {
128            return -code error "Uninstall failed: Port has no contents entry"
129        }
130    }
131    return -code error "Uninstall failed: Port not registered as installed"
132}
Note: See TracBrowser for help on using the repository browser.