[64626] trunk/base/src/registry2.0/portimage.tcl

jmr at macports.org jmr at macports.org
Thu Mar 11 05:42:51 PST 2010


Revision: 64626
          http://trac.macports.org/changeset/64626
Author:   jmr at macports.org
Date:     2010-03-11 05:42:47 -0800 (Thu, 11 Mar 2010)
Log Message:
-----------
fix deactivation of replaced ports when their files conflict during activation with reg2

Modified Paths:
--------------
    trunk/base/src/registry2.0/portimage.tcl

Modified: trunk/base/src/registry2.0/portimage.tcl
===================================================================
--- trunk/base/src/registry2.0/portimage.tcl	2010-03-11 12:49:27 UTC (rev 64625)
+++ trunk/base/src/registry2.0/portimage.tcl	2010-03-11 13:42:47 UTC (rev 64626)
@@ -419,7 +419,6 @@
         set name $port
     }
 
-    set deactivated [list]
     set backups [list]
     # This is big and hairy and probably could be done better.
     # First, we need to check the source file, make sure it exists
@@ -429,6 +428,7 @@
     #  we remove the file from the file_map, take ownership of it, and
     #  clobber it
     if {$use_reg2} {
+        array set todeactivate {}
         try {
             registry::write {
                 foreach file $imagefiles {
@@ -449,36 +449,37 @@
                         array unset portinfo
                         array set portinfo [lindex $result 1]
                         if {[info exists portinfo(replaced_by)] && [lsearch -exact -nocase $portinfo(replaced_by) [$port name]] != -1} {
-                            lappend deactivated $owner
-                            # XXX this is bad, deactivate does another write transaction (probably deadlocks)
-                            deactivate [$owner name] "" [list ports_nodepcheck 1]
-                            set owner {}
+                            # we'll deactivate the owner later, but before activating our files
+                            set todeactivate($owner) yes
+                            set owner "replaced"
                         }
                     }
 
-                    if { [string is true -strict $force] } {
-                        # if we're forcing the activation, then we move any existing
-                        # files to a backup file, both in the filesystem and in the
-                        # registry
-                        if { [file exists $file] } {
-                            set bakfile "${file}${baksuffix}"
-                            ui_warn "File $file already exists.  Moving to: $bakfile."
-                            file rename -force -- $file $bakfile
-                            lappend backups $file
+                    if {$owner != "replaced"} {
+                        if { [string is true -strict $force] } {
+                            # if we're forcing the activation, then we move any existing
+                            # files to a backup file, both in the filesystem and in the
+                            # registry
+                            if { [file exists $file] } {
+                                set bakfile "${file}${baksuffix}"
+                                ui_warn "File $file already exists.  Moving to: $bakfile."
+                                file rename -force -- $file $bakfile
+                                lappend backups $file
+                            }
+                            if { $owner != {} } {
+                                $owner deactivate [list $file]
+                                $owner activate [list $file] [list "${file}${baksuffix}"]
+                            }
+                        } else {
+                            # if we're not forcing the activation, then we bail out if
+                            # we find any files that already exist, or have entries in
+                            # the registry
+                            if { $owner != {} && $owner != $port } {
+                                throw registry::image-error "Image error: $file is being used by the active [$owner name] port.  Please deactivate this port first, or use 'port -f activate [$port name]' to force the activation."
+                            } elseif { $owner == {} && [file exists $file] } {
+                                throw registry::image-error "Image error: $file already exists and does not belong to a registered port.  Unable to activate port [$port name]. Use 'port -f activate [$port name]' to force the activation."
+                            }
                         }
-                        if { $owner != {} } {
-                            $owner deactivate [list $file]
-                            $owner activate [list $file] [list "${file}${baksuffix}"]
-                        }
-                    } else {
-                        # if we're not forcing the activation, then we bail out if
-                        # we find any files that already exist, or have entries in
-                        # the registry
-                        if { $owner != {} && $owner != $port } {
-                            throw registry::image-error "Image error: $file is being used by the active [$owner name] port.  Please deactivate this port first, or use 'port -f activate [$port name]' to force the activation."
-                        } elseif { $owner == {} && [file exists $file] } {
-                            throw registry::image-error "Image error: $file already exists and does not belong to a registered port.  Unable to activate port [$port name]. Use 'port -f activate [$port name]' to force the activation."
-                        }
                     }
 
                     # Split out the filename's subpaths and add them to the
@@ -498,14 +499,21 @@
                     # Also add the filename to the imagefile list.
                     lappend files $file
                 }
+            }
 
-                # Sort the list in forward order, removing duplicates.
-                # Since the list is sorted in forward order, we're sure that
-                # directories are before their elements.
-                # We don't have to do this as mentioned above, but it makes the
-                # debug output of activate make more sense.
-                set theList [lsort -increasing -unique $files]
+            # deactivate ports replaced_by this one
+            foreach owner [array names todeactivate] {
+                deactivate [$owner name] "" [list ports_nodepcheck 1]
+            }
 
+            # Sort the list in forward order, removing duplicates.
+            # Since the list is sorted in forward order, we're sure that
+            # directories are before their elements.
+            # We don't have to do this as mentioned above, but it makes the
+            # debug output of activate make more sense.
+            set theList [lsort -increasing -unique $files]
+
+            registry::write {
                 # Activate it, and catch errors so we can roll-back
                 try {
                     $port activate $imagefiles
@@ -531,14 +539,17 @@
                 file rename -force -- "${file}${baksuffix}" $file
             }
             # reactivate deactivated ports
-            foreach entry $deactivated {
-                set pvers "[$entry version]_[$entry revision][$entry variants]"
-                activate [$entry name] $pvers ""
+            foreach entry [array names todeactivate] {
+                if {[$entry state] == "imaged"} {
+                    set pvers "[$entry version]_[$entry revision][$entry variants]"
+                    activate [$entry name] $pvers ""
+                }
             }
             throw
         }
     } else {
         # registry1.0
+        set deactivated [list]
         foreach file $imagefiles {
             set srcfile "${imagedir}${file}"
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100311/c319f4a7/attachment.html>


More information about the macports-changes mailing list