[146699] trunk/base/src/macports1.0/reclaim.tcl

cal at macports.org cal at macports.org
Tue Mar 15 08:43:50 PDT 2016


Revision: 146699
          https://trac.macports.org/changeset/146699
Author:   cal at macports.org
Date:     2016-03-15 08:43:50 -0700 (Tue, 15 Mar 2016)
Log Message:
-----------
base: reclaim: Fix signals being swallowed

Modified Paths:
--------------
    trunk/base/src/macports1.0/reclaim.tcl

Modified: trunk/base/src/macports1.0/reclaim.tcl
===================================================================
--- trunk/base/src/macports1.0/reclaim.tcl	2016-03-15 15:41:03 UTC (rev 146698)
+++ trunk/base/src/macports1.0/reclaim.tcl	2016-03-15 15:43:50 UTC (rev 146699)
@@ -137,9 +137,11 @@
             set variants [lindex $port 3]
 
             # Get mport reference
-            if {[catch {set mport [mportopen_installed $name $version $revision $variants {}]} error]} {
+            try -pass_signal {
+                set mport [mportopen_installed $name $version $revision $variants {}]
+            } catch {{*} eCode eMessage} {
                 $progress intermission
-                ui_warn [msgcat::mc "Failed to open port %s from registry: %s" $name $error]
+                ui_warn [msgcat::mc "Failed to open port %s from registry: %s" $name $eMessage]
                 continue
             }
 
@@ -207,7 +209,7 @@
                             set root_length [string length "${root_dist}/"]
                             set home_length [string length "${home_dist}/"]
 
-                            try {
+                            try -pass_signal {
                                 ui_info [msgcat::mc "Deleting unused file %s" $f]
                                 file delete -- $f
 
@@ -225,7 +227,7 @@
                                     }
 
                                     ui_info [msgcat::mc "Deleting empty directory %s" $directory]
-                                    try {
+                                    try -pass_signal {
                                         file delete -- $directory
                                     } catch {{*} eCode eMessage} {
                                         ui_warn [msgcat::mc "Could not delete empty directory %s: %s" $directory $eMesage]
@@ -258,19 +260,6 @@
         return 0
     }
 
-    proc close_file {file} {
-
-        # Closes the file, handling error catching if needed.
-        #
-        # Args: 
-        #           file - The file handler
-        # Returns:
-        #           None
-        if {[catch {close $file} error]} {
-            ui_error "something went wrong when closing file, $file."
-        }
-    }
-
     proc is_inactive {port} {
 
         # Determines whether a port is inactive or not.
@@ -298,12 +287,12 @@
         #           A multidimensional list where each port is a sublist, i.e., [{first port info} {second port info} {...}]
         #           Indexes of each sublist are: 0 = name, 1 = version, 2 = revision, 3 = variants, 4 = activity, and 5 = epoch.
         
-        if {[catch {set installed [registry::installed]} result]} {
+        try -pass_signal {
+            return [registry::installed]
+        } catch {*} {
             ui_error "no installed ports found."
             return {}
         }
-
-        return $installed
     }
 
     proc update_last_run {} {
@@ -317,10 +306,16 @@
 
         ui_debug "Updating last run information."
 
-        set path    [file join ${macports::portdbpath} last_reclaim]
-        set fd      [open $path w]
-        puts $fd    [clock seconds]
-        close_file $fd
+        set path [file join ${macports::portdbpath} last_reclaim]
+        set fd -1
+        try -pass_signal {
+            set fd [open $path w]
+            puts $fd [clock seconds]
+        } finally {
+            if {$fd != -1} {
+                close $fd
+            }
+        }
     }
 
     proc check_last_run {} {
@@ -336,18 +331,21 @@
 
         set path [file join ${macports::portdbpath} last_reclaim]
 
-        if {[file exists $path]} {
-
-            set fd      [open $path r]
-            set time    [gets $fd]
-            close_file $fd
-
-            if {$time ne ""} {
-                if {[clock seconds] - $time > 1209600} {
-                    ui_warn "You haven't run 'port reclaim' in two weeks. It's recommended you run this every two weeks to reclaim disk space."
-                }
+        set fd -1
+        set time ""
+        try -pass_signal {
+            set fd [open $path r]
+            set time [gets $fd]
+        } finally {
+            if {$fd != -1} {
+                close $fd
             }
         }
+        if {$time ne ""} {
+            if {[clock seconds] - $time > 1209600} {
+                ui_warn "You haven't run 'port reclaim' in two weeks. It's recommended you run this every two weeks to reclaim disk space."
+            }
+        }
     }
 
     proc uninstall_inactive {} {
@@ -392,8 +390,10 @@
                         ui_msg "Uninstalling: $name"
 
                         # Note: 'uninstall' takes a name, version, revision, variants and an options list. 
-                        if {[catch {registry_uninstall::uninstall $name [lindex $port 1] [lindex $port 2] [lindex $port 3] {}} error]} {
-                            ui_error "something went wrong when uninstalling $name"
+                        try -pass_signal {
+                            registry_uninstall::uninstall $name [lindex $port 1] [lindex $port 2] [lindex $port 3] {}
+                        } catch {{*} eCode eMessage} {
+                            ui_error "Error uninstalling $name: $eMessage"
                         }
                     }
                 } else {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160315/486a2aa2/attachment.html>


More information about the macports-changes mailing list