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

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

Loosen MD5 checksum matching to cope with filenames with spaces.

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