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

Last change on this file since 1066 was 1066, checked in by jkh, 18 years ago

Add a -f[orce] flag for making certain things happen unconditionally when
the port system is trying to be more clever than you are and not succeeding.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.2 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
40# define options
41options uninstall.force uninstall.nochecksum
42
43set UI_PREFIX "---> "
44
45proc uninstall_main {args} {
46    global portname portversion uninstall.force uninstall.nochecksum ports_force UI_PREFIX
47
48    # If global forcing is on, make it the same as a local force flag.
49    if [tbool ports_force] {
50        set uninstall.force "yes"
51    }
52
53    set rfile [registry_exists $portname $portversion]
54    if [string length $rfile] {
55        ui_msg "$UI_PREFIX Uninstalling $portname-$portversion"
56        if [regexp .bz2$ $rfile] {
57            set fd [open "|bunzip2 -c $rfile" r]
58        } else {
59            set fd [open $rfile r]
60        }
61        set entry [read $fd]
62        close $fd
63
64        # First look to see if the port has registered an uninstall procedure
65        set ix [lsearch $entry pkg_uninstall]
66        if {$ix >= 0} {
67            set uninstall [lindex $entry [incr ix]]
68            if ![catch {eval $uninstall} err] {
69                pkg_uninstall $portname $portversion
70            } else {
71                ui_error "Could not evaluate pkg_uninstall procedure: $err"
72            }
73        }
74
75        # Now look for a contents list
76        set ix [lsearch $entry contents]
77        if {$ix >= 0} {
78            set contents [lindex $entry [incr ix]]
79            set uninst_err 0
80            foreach f $contents {
81                set fname [lindex $f 0]
82                set sumx [lindex $f [lsearch -regex $f MD5]]
83                set sum1 [lindex $sumx [expr [llength $sumx] - 1]]
84                if {![string match $sum1 NONE] && ![tbool uninstall.nochecksum]} {
85                    if ![catch {set sum2 [md5 $fname]}] {
86                        if ![string match $sum1 $sum2] {
87                            if ![tbool uninstall.force] {
88                                ui_info "$UI_PREFIX  Original checksum does not match for $fname, not removing"
89                                set uninst_err 1
90                                continue
91                            } else {
92                                ui_info "$UI_PREFIX  Original checksum does not match for $fname, removing anyway [force in effect]"
93                            }
94                        }
95                    }
96                }
97                ui_info "$UI_PREFIX   Uninstall is removing $fname"
98                if [file isdirectory $fname] {
99                    if [catch {exec rmdir $fname}] {
100                        if ![tbool uninstall.force] {
101                            ui_info "$UI_PREFIX  Uninstall unable to remove directory $fname (not empty?)"
102                            set uninst_err 1
103                        } else {
104                            # No, I INSIST!
105                            exec rm -rf $fname
106                        }
107                    }
108                } else {
109                    if [catch {exec rm $fname}] {
110                        ui_info "$UI_PREFIX  Uninstall unable to remove file $fname"
111                        set uninst_err 1
112                    }
113                }
114            }
115            if {!$uninst_err || [tbool uninstall.force]} {
116                registry_delete $portname $portversion
117                return 0
118            }
119        } else {
120            return -code error "Uninstall failed: Port has no contents entry"
121        }
122    }
123    return -code error "Uninstall failed: Port not registered as installed"
124}
Note: See TracBrowser for help on using the repository browser.