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

Last change on this file since 3220 was 3220, checked in by landonf (Landon Fuller), 17 years ago

Fix all conditionals that are missing braces
Submitted by: Jason Corley <jcorley1@…>

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1# et:ts=4
2# portuninstall.tcl
3#
4# Copyright (c) 2002 - 2003 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]
36target_runtype ${com.apple.uninstall} always
37target_provides ${com.apple.uninstall} uninstall
38target_requires ${com.apple.uninstall} main
39target_prerun ${com.apple.uninstall} 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 [format [msgcat::mc "Uninstalling %s-%s"] $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 [format [msgcat::mc "Could not evaluate pkg_uninstall procedure: %s"] $err]
80            }
81        }
82
83        # Now look for a contents list
84        set ix [lsearch $entry contents]
85        if {$ix >= 0} {
86            set contents [lsort -decreasing [lindex $entry [incr ix]]]
87            set uninst_err 0
88            foreach f $contents {
89                set fname [lindex $f 0]
90                set md5index [lsearch -regex [lrange $f 1 end] MD5]
91                if {$md5index != -1} {
92                        set sumx [lindex $f [expr $md5index + 1]]
93                } else {
94                        # XXX There is no MD5 listed, set sumx to an empty
95                        # list, causing the next conditional to return a
96                        # checksum error
97                        set sumx {}
98                }
99                set sum1 [lindex $sumx [expr [llength $sumx] - 1]]
100                if {![string match $sum1 NONE] && ![tbool uninstall.nochecksum]} {
101                    if {![catch {set sum2 [md5 $fname]}]} {
102                        if {![string match $sum1 $sum2]} {
103                            if {![tbool uninstall.force]} {
104                                ui_info "$UI_PREFIX  [format [msgcat::mc "Original checksum does not match for %s, not removing"] $fname]"
105                                set uninst_err 1
106                                continue
107                            } else {
108                                ui_info "$UI_PREFIX  [format [msgcat::mc "Original checksum does not match for %s, removing anyway [force in effect]"] $fname]"
109                            }
110                        }
111                    }
112                }
113                ui_info "$UI_PREFIX [format [msgcat::mc "Uninstall is removing %s"] $fname]"
114                if {[file isdirectory $fname]} {
115                    if {[catch {file delete -- $fname} result]} {
116                        # A non-empty directory is not a fatal error
117                        if {$result != "error deleting \"$fname\": directory not empty"} {
118                            ui_info "$UI_PREFIX  [format [msgcat::mc "Uninstall unable to remove directory %s (not empty?)"] $fname]"
119                        }
120                    }
121                } else {
122                    if {[catch {file delete -- $fname}]} {
123                        ui_info "$UI_PREFIX  [format [msgcat::mc "Uninstall unable to remove file %s"] $fname]"
124                        set uninst_err 1
125                    }
126                }
127            }
128            if {!$uninst_err || [tbool uninstall.force]} {
129                registry_delete $portname $portversion
130                return 0
131            }
132        } else {
133            return -code error [msgcat::mc "Uninstall failed: Port has no contents entry"]
134        }
135    }
136    return -code error [msgcat::mc "Uninstall failed: Port not registered as installed"]
137}
Note: See TracBrowser for help on using the repository browser.