Changeset 785:7fa99e74e8ab


Ignore:
Timestamp:
06/16/16 17:43:30 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
version_0.37_maint
Phase:
public
Message:

Made the update procedure more resilient to errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/update.py

    r681 r785  
    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))
     
    372378        listener.done()
    373379    except Exception, e:
     380        exc = traceback.format_exc()
     381        print >> sys.stderr, utf2unicode(exc)
     382       
    374383        error = utf2unicode(str(e))
    375384        print >> sys.stderr, "Error:", error
     385
    376386        listener.failed(error)
    377387
     
    521531def update(directory, updateURL, listener, fromGUI = False):
    522532    """Perform the update."""
    523     result = prepareUpdate(directory, updateURL, listener)
    524     if result is None:
    525         return
    526 
    527     (manifest, updateManifest, modifiedAndNew, removed) = result       
    528     localRemoved = getToremoveFiles(directory)
    529 
    530     if not modifiedAndNew and not removed and not localRemoved:
    531         listener.done()
    532         return
    533 
    534     if fromGUI and not isDirectoryWritable(directory):
    535         if listener.needSudo():
    536             sudoUpdate(directory, updateURL, listener, updateManifest)
    537     else:
    538         updateFiles(directory, updateURL, listener, updateManifest,
    539                     modifiedAndNew, removed, localRemoved)
     533    try:
     534        result = prepareUpdate(directory, updateURL, listener)
     535        if result is None:
     536            return
     537
     538        (manifest, updateManifest, modifiedAndNew, removed) = result       
     539        localRemoved = getToremoveFiles(directory)
     540
     541        if not modifiedAndNew and not removed and not localRemoved:
     542            listener.done()
     543            return
     544
     545        if fromGUI and not isDirectoryWritable(directory):
     546            if listener.needSudo():
     547                sudoUpdate(directory, updateURL, listener, updateManifest)
     548        else:
     549            updateFiles(directory, updateURL, listener, updateManifest,
     550                        modifiedAndNew, removed, localRemoved)
     551    except Exception, e:
     552        exc = traceback.format_exc()
     553        print >> sys.stderr, utf2unicode(exc)
     554       
     555        error = utf2unicode(str(e))
     556        print >> sys.stderr, "Update error:", error
     557       
     558        listener.failed(error)
    540559
    541560#------------------------------------------------------------------------------
     
    543562def updateProcess():
    544563    """This is called in the child process, when we need a child process."""
    545     clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
    546     clientSocket.connect(("127.0.0.1", int(sys.argv[1])))
    547 
    548     directory = os.path.dirname(sys.argv[0])
    549 
    550     manifest = readLocalManifest(directory)
    551    
    552     updateManifest = Manifest()
    553     with open(sys.argv[2], "rt") as f:
    554         updateManifest.readFrom(f)
    555 
    556     (modifiedAndNew, removed) = manifest.compare(updateManifest)
    557     localRemoved = getToremoveFiles(directory)
    558 
    559     updateFiles(directory, sys.argv[3],
    560                 ClientListener(clientSocket),
    561                 updateManifest, modifiedAndNew, removed, localRemoved)
     564    try:
     565        clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
     566        clientSocket.connect(("127.0.0.1", int(sys.argv[1])))
     567
     568        directory = os.path.dirname(sys.argv[0])
     569
     570        manifest = readLocalManifest(directory)
     571
     572        updateManifest = Manifest()
     573        with open(sys.argv[2], "rt") as f:
     574            updateManifest.readFrom(f)
     575
     576        (modifiedAndNew, removed) = manifest.compare(updateManifest)
     577        localRemoved = getToremoveFiles(directory)
     578
     579        updateFiles(directory, sys.argv[3],
     580                    ClientListener(clientSocket),
     581                    updateManifest, modifiedAndNew, removed, localRemoved)
     582    except:
     583        exc = traceback.format_exc()
     584        print >> sys.stderr, utf2unicode(exc)
    562585
    563586#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.