Revision
90075
Author
cal@macports.org
Date
2012-02-20 17:52:09 -0800 (Mon, 20 Feb 2012)

Log Message

Only copy com.apple.dt.Xcode.plist to temporary user directory if newer

This prevents permission errors occuring when using bash-completion and
port(1) without sudo in environments where the macports user doesn't
have permission to read the file and/or can't write to the temporary
home.

Modified Paths

Diff

Modified: trunk/base/src/macports1.0/macports.tcl (90074 => 90075)


--- trunk/base/src/macports1.0/macports.tcl	2012-02-21 01:33:44 UTC (rev 90074)
+++ trunk/base/src/macports1.0/macports.tcl	2012-02-21 01:52:09 UTC (rev 90075)
@@ -1184,14 +1184,24 @@
     set user_plist "${user_home}/Library/Preferences/com.apple.dt.Xcode.plist"
     set target_dir "${target_homedir}/Library/Preferences"
     if {[file isfile $user_plist]} {
-        if {[catch {
-                file mkdir "${target_homedir}/Library/Preferences"
+        if {![file isdirectory "${target_dir}"]} {
+            ui_debug "Creating Library/Preferences in temporary home: ${target_dir}"
+            if {[catch {file mkdir "${target_dir}"} result]} {
+                ui_warn "Failed to create Library/Preferences in temporary home directory: $result"
+            }
+        }
+        if {![file isfile "${target_dir}/com.apple.dt.Xcode.plist"] || [file mtime "${user_plist}"] >
+            [file mtime "${target_dir}/com.apple.dt.Xcode.plist"]} {
+            ui_debug "Copying $user_plist to temporary home directory ${target_dir}"
+            if {[catch {
                 file copy -force $user_plist $target_dir
                 if {[getuid] == 0} {
+                    ui_debug "Attempding to chown() com.apple.dt.Xcode.plist in temporary home"
                     file attributes "${target_dir}/com.apple.dt.Xcode.plist" -owner $macportsuser
                 }
-        } result]} {
-            ui_warn "Failed to copy com.apple.dt.Xcode.plist to temporary home directory: $result"
+            } result]} {
+                ui_warn "Failed to copy com.apple.dt.Xcode.plist to temporary home directory: $result"
+            }
         }
     }
 }