Changeset 788:805d2ae4d025 for src/mlx


Ignore:
Timestamp:
06/16/16 17:43:30 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
transplant_source:
©žtè««ˆÿ8GÅâ‹ô£-!sG
Message:

Made the update procedure more resilient to errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/update.py

    r781 r788  
    1010import subprocess
    1111import hashlib
     12import traceback
    1213
    1314if os.name=="nt":
     
    291292            sum.update(path)
    292293            toremoveDir = getToremoveDir(toremoveDir, directory)
    293             os.rename(path, os.path.join(toremoveDir, sum.hexdigest()))
     294            targetPath = os.path.join(toremoveDir, sum.hexdigest())
     295            try:
     296                os.remove(targetPath)
     297            except:
     298                pass
     299            os.rename(path, targetPath)
    294300        except Exception, e:
    295301            print "Cannot remove file " + path + ": " + utf2unicode(str(e))
     
    386392        listener.done()
    387393    except Exception, e:
     394        exc = traceback.format_exc()
     395        print >> sys.stderr, utf2unicode(exc)
     396       
    388397        error = utf2unicode(str(e))
    389398        print >> sys.stderr, "Error:", error
     399
    390400        listener.failed(error)
    391401
     
    535545def update(directory, updateURL, listener, fromGUI = False):
    536546    """Perform the update."""
    537     result = prepareUpdate(directory, updateURL, listener)
    538     if result is None:
    539         return
    540 
    541     (manifest, updateManifest, modifiedAndNew, removed) = result       
    542     localRemoved = getToremoveFiles(directory)
    543 
    544     if not modifiedAndNew and not removed and not localRemoved:
    545         listener.done()
    546         return
    547 
    548     if fromGUI and not isDirectoryWritable(directory):
    549         if listener.needSudo():
    550             sudoUpdate(directory, updateURL, listener, updateManifest)
    551     else:
    552         updateFiles(directory, updateURL, listener, updateManifest,
    553                     modifiedAndNew, removed, localRemoved)
     547    try:
     548        result = prepareUpdate(directory, updateURL, listener)
     549        if result is None:
     550            return
     551
     552        (manifest, updateManifest, modifiedAndNew, removed) = result       
     553        localRemoved = getToremoveFiles(directory)
     554
     555        if not modifiedAndNew and not removed and not localRemoved:
     556            listener.done()
     557            return
     558
     559        if fromGUI and not isDirectoryWritable(directory):
     560            if listener.needSudo():
     561                sudoUpdate(directory, updateURL, listener, updateManifest)
     562        else:
     563            updateFiles(directory, updateURL, listener, updateManifest,
     564                        modifiedAndNew, removed, localRemoved)
     565    except Exception, e:
     566        exc = traceback.format_exc()
     567        print >> sys.stderr, utf2unicode(exc)
     568       
     569        error = utf2unicode(str(e))
     570        print >> sys.stderr, "Update error:", error
     571       
     572        listener.failed(error)
    554573
    555574#------------------------------------------------------------------------------
     
    557576def updateProcess():
    558577    """This is called in the child process, when we need a child process."""
    559     clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
    560     clientSocket.connect(("127.0.0.1", int(sys.argv[1])))
    561 
    562     directory = os.path.dirname(sys.argv[0])
    563 
    564     manifest = readLocalManifest(directory)
    565    
    566     updateManifest = Manifest()
    567     with open(sys.argv[2], "rt") as f:
    568         updateManifest.readFrom(f)
    569 
    570     (modifiedAndNew, removed) = manifest.compare(updateManifest)
    571     localRemoved = getToremoveFiles(directory)
    572 
    573     updateFiles(directory, sys.argv[3],
    574                 ClientListener(clientSocket),
    575                 updateManifest, modifiedAndNew, removed, localRemoved)
     578    try:
     579        clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
     580        clientSocket.connect(("127.0.0.1", int(sys.argv[1])))
     581
     582        directory = os.path.dirname(sys.argv[0])
     583
     584        manifest = readLocalManifest(directory)
     585
     586        updateManifest = Manifest()
     587        with open(sys.argv[2], "rt") as f:
     588            updateManifest.readFrom(f)
     589
     590        (modifiedAndNew, removed) = manifest.compare(updateManifest)
     591        localRemoved = getToremoveFiles(directory)
     592
     593        updateFiles(directory, sys.argv[3],
     594                    ClientListener(clientSocket),
     595                    updateManifest, modifiedAndNew, removed, localRemoved)
     596    except:
     597        exc = traceback.format_exc()
     598        print >> sys.stderr, utf2unicode(exc)
    576599
    577600#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.