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

Last change on this file since 1015 was 1015, checked in by kevin, 18 years ago

Remove 'register' proc.
Now targets have a handle to the target object directly. Alleviates need for
unique names, and simplifies pre-${target}/post-${target} implementation.
Will allow for future enhancement to options and variants.

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