Changeset 735

Show
Ignore:
Timestamp:
04/17/08 16:14:49 (8 months ago)
Author:
aranti..@gmail.com
Message:

Fixes #37 Fixes #89

  • When creating temporary files, always use nsILocalFile.createUnique()
  • Track temporary files created during script install
  • Clean up all temporary files when script install completes or is canceled
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/chrome/chromeFiles/content/install.js

    r694 r735  
    107107 
    108108  onCancel: function(){ 
     109    this.scriptDownloader_.cleanupTempFiles(); 
    109110    window.close(); 
    110111  }, 
  • trunk/src/chrome/chromeFiles/content/scriptdownloader.js

    r694 r735  
    88  this.dependenciesLoaded_ = false; 
    99  this.installOnCompletion_ = false; 
     10  this.tempFiles_ = []; 
    1011} 
    1112 
     
    6162    var base = this.script.name.replace(/[^A-Z0-9_]/gi, "").toLowerCase(); 
    6263    file.append(base + ".user.js"); 
     64    file.createUnique( 
     65      Components.interfaces.nsILocalFile.NORMAL_FILE_TYPE, 
     66      0640 
     67    ); 
     68    this.tempFiles_.push(file); 
    6369 
    6470    var converter = 
     
    122128 
    123129      var file = getTempFile(); 
     130      this.tempFiles_.push(file); 
    124131 
    125132      var progressListener = new PersistProgressListener(persist); 
     
    207214}; 
    208215 
     216ScriptDownloader.prototype.cleanupTempFiles = function() { 
     217  for (var i = 0, file = null; file = this.tempFiles_[i]; i++) { 
     218    file.remove(false); 
     219  } 
     220}; 
     221 
    209222ScriptDownloader.prototype.showInstallDialog = function(timer) { 
    210223  if (!timer) { 
  • trunk/src/chrome/chromeFiles/content/utils.js

    r715 r735  
    201201        .get("TmpD", Components.interfaces.nsILocalFile); 
    202202 
    203   file.append("gm_" + new Date().getTime() + Math.floor(Math.random()*65536)); 
    204   if(file.exists()){ 
    205     return getTempFile(); 
    206   } 
     203  file.append("gm-temp"); 
     204  file.createUnique( 
     205    Components.interfaces.nsILocalFile.NORMAL_FILE_TYPE, 
     206    0640 
     207  ); 
    207208 
    208209  return file;