Index: src/mlx/update.py
===================================================================
--- src/mlx/update.py	(revision 781)
+++ src/mlx/update.py	(revision 785)
@@ -10,4 +10,5 @@
 import subprocess
 import hashlib
+import traceback
 
 if os.name=="nt":
@@ -291,31 +292,12 @@
             sum.update(path)
             toremoveDir = getToremoveDir(toremoveDir, directory)
-            os.rename(path, os.path.join(toremoveDir, sum.hexdigest()))
+            targetPath = os.path.join(toremoveDir, sum.hexdigest())
+            try:
+                os.remove(targetPath)
+            except:
+                pass
+            os.rename(path, targetPath)
         except Exception, e:
             print "Cannot remove file " + path + ": " + utf2unicode(str(e))
-
-#------------------------------------------------------------------------------
-
-def removeFiles(directory, listener, removed, count):
-    """Remove the given files."""
-    toremoveDir = None
-    
-    listener.startRemoving()
-
-    removed.sort(reverse = True)
-    for path in removed:
-        removePath = createLocalPath(directory, path)
-        removeFile(toremoveDir, directory, removePath)
-
-        removeDirectory = os.path.dirname(removePath)
-        try:
-            os.removedirs(removeDirectory)
-        except:
-            pass
-
-        count += 1
-        listener.removed(path, count)
-
-    return count
 
 #------------------------------------------------------------------------------
@@ -338,9 +320,4 @@
         updateURL += "/" + os.name
 
-        removeCount = 0
-        if localRemoved:
-            removeCount = removeFiles(directory, listener,
-                                      localRemoved, removeCount)
-        
         for (path, size, sum) in modifiedAndNew:
             targetFile = createLocalPath(directory, path)
@@ -375,6 +352,21 @@
             count += 1
             listener.renamed(path, count)
-
-        removeFiles(directory, listener, removed, removeCount)
+        
+        listener.startRemoving()
+        count = 0
+        removed += localRemoved
+        removed.sort(reverse = True)
+        for path in removed:            
+            removePath = createLocalPath(directory, path)
+            removeFile(toremoveDir, directory, removePath)
+
+            removeDirectory = os.path.dirname(removePath)
+            try:
+                os.removedirs(removeDirectory)
+            except:
+                pass
+
+            count += 1
+            listener.removed(path, count)
 
         listener.writingManifest()
@@ -386,6 +378,10 @@
         listener.done()
     except Exception, e:
+        exc = traceback.format_exc()
+        print >> sys.stderr, utf2unicode(exc)
+        
         error = utf2unicode(str(e))
         print >> sys.stderr, "Error:", error
+
         listener.failed(error)
 
@@ -535,21 +531,30 @@
 def update(directory, updateURL, listener, fromGUI = False):
     """Perform the update."""
-    result = prepareUpdate(directory, updateURL, listener)
-    if result is None:
-        return
-
-    (manifest, updateManifest, modifiedAndNew, removed) = result        
-    localRemoved = getToremoveFiles(directory)
-
-    if not modifiedAndNew and not removed and not localRemoved:
-        listener.done()
-        return
-
-    if fromGUI and not isDirectoryWritable(directory):
-        if listener.needSudo():
-            sudoUpdate(directory, updateURL, listener, updateManifest)
-    else:
-        updateFiles(directory, updateURL, listener, updateManifest,
-                    modifiedAndNew, removed, localRemoved)
+    try:
+        result = prepareUpdate(directory, updateURL, listener)
+        if result is None:
+            return
+
+        (manifest, updateManifest, modifiedAndNew, removed) = result        
+        localRemoved = getToremoveFiles(directory)
+
+        if not modifiedAndNew and not removed and not localRemoved:
+            listener.done()
+            return
+
+        if fromGUI and not isDirectoryWritable(directory):
+            if listener.needSudo():
+                sudoUpdate(directory, updateURL, listener, updateManifest)
+        else:
+            updateFiles(directory, updateURL, listener, updateManifest,
+                        modifiedAndNew, removed, localRemoved)
+    except Exception, e:
+        exc = traceback.format_exc()
+        print >> sys.stderr, utf2unicode(exc)
+        
+        error = utf2unicode(str(e))
+        print >> sys.stderr, "Update error:", error
+        
+        listener.failed(error)
 
 #------------------------------------------------------------------------------
@@ -557,21 +562,25 @@
 def updateProcess():
     """This is called in the child process, when we need a child process."""
-    clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    
-    clientSocket.connect(("127.0.0.1", int(sys.argv[1])))
-
-    directory = os.path.dirname(sys.argv[0])
-
-    manifest = readLocalManifest(directory)
-    
-    updateManifest = Manifest()
-    with open(sys.argv[2], "rt") as f:
-        updateManifest.readFrom(f)
-
-    (modifiedAndNew, removed) = manifest.compare(updateManifest)
-    localRemoved = getToremoveFiles(directory)
-
-    updateFiles(directory, sys.argv[3],
-                ClientListener(clientSocket),
-                updateManifest, modifiedAndNew, removed, localRemoved)
+    try:
+        clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    
+        clientSocket.connect(("127.0.0.1", int(sys.argv[1])))
+
+        directory = os.path.dirname(sys.argv[0])
+
+        manifest = readLocalManifest(directory)
+
+        updateManifest = Manifest()
+        with open(sys.argv[2], "rt") as f:
+            updateManifest.readFrom(f)
+
+        (modifiedAndNew, removed) = manifest.compare(updateManifest)
+        localRemoved = getToremoveFiles(directory)
+
+        updateFiles(directory, sys.argv[3],
+                    ClientListener(clientSocket),
+                    updateManifest, modifiedAndNew, removed, localRemoved)
+    except:
+        exc = traceback.format_exc()
+        print >> sys.stderr, utf2unicode(exc)
 
 #------------------------------------------------------------------------------
