B2G/gecko/toolkit/mozapps/extensions/XPIProvider.jsm
/**
   * Installs an add-on into the install location.
   *
   * @param  aId
   *         The ID of the add-on to install
   * @param  aSource
   *         The source nsIFile to install from
   * @param  aExistingAddonID
   *         The ID of an existing add-on to uninstall at the same time
   * @param  aCopy
   *         If false the source files will be moved to the new location,
   *         otherwise they will only be copied
   * @return an nsIFile indicating where the add-on was installed to
   */
Installs an add-on into the install location.
Installs an add - on into the install location .
function DirInstallLocation_installAddon(aId, aSource,
                                                         aExistingAddonID,
                                                         aCopy) {
    let trashDir = this.getTrashDir();
    let transaction = new SafeInstallOperation();
    let self = this;
    function moveOldAddon(aId) {
      let file = self._directory.clone();
      file.append(aId);
      if (file.exists())
        transaction.move(file, trashDir);
      file = self._directory.clone();
      file.append(aId + ".xpi");
      if (file.exists()) {
        flushJarCache(file);
        transaction.move(file, trashDir);
      }
    }
    try {
      moveOldAddon(aId);
      if (aExistingAddonID && aExistingAddonID != aId)
        moveOldAddon(aExistingAddonID);
      if (aCopy) {
        transaction.copy(aSource, this._directory);
      }
      else {
        if (aSource.isFile())
          flushJarCache(aSource);
        transaction.move(aSource, this._directory);
      }
    }
    finally {
      try {
        recursiveRemove(trashDir);
      }
      catch (e) {
        WARN("Failed to remove trash directory when installing " + aId, e);
      }
    }
    let newFile = this._directory.clone();
    newFile.append(aSource.leafName);
    try {
      newFile.lastModifiedTime = Date.now();
    } catch (e)  {
      WARN("failed to set lastModifiedTime on " + newFile.path, e);
    }
    this._FileToIDMap[newFile.path] = aId;
    this._IDToFileMap[aId] = newFile;
    if (aExistingAddonID && aExistingAddonID != aId &&
        aExistingAddonID in this._IDToFileMap) {
      delete this._FileToIDMap[this._IDToFileMap[aExistingAddonID]];
      delete this._IDToFileMap[aExistingAddonID];
    }
    return newFile;
  }
function DirInstallLocation_installAddon ( aId , aSource , aExistingAddonID , aCopy ) { let trashDir = this . getTrashDir ( ) ; let transaction = new SafeInstallOperation ( ) ; let self = this ; function moveOldAddon ( aId ) { let file = self . _directory . clone ( ) ; file . append ( aId ) ; if ( file . exists ( ) ) transaction . move ( file , trashDir ) ; file = self . _directory . clone ( ) ; file . append ( aId + ".xpi" ) ; if ( file . exists ( ) ) { flushJarCache ( file ) ; transaction . move ( file , trashDir ) ; } } try { moveOldAddon ( aId ) ; if ( aExistingAddonID && aExistingAddonID != aId ) moveOldAddon ( aExistingAddonID ) ; if ( aCopy ) { transaction . copy ( aSource , this . _directory ) ; } else { if ( aSource . isFile ( ) ) flushJarCache ( aSource ) ; transaction . move ( aSource , this . _directory ) ; } } finally { try { recursiveRemove ( trashDir ) ; } catch ( e ) { WARN ( "Failed to remove trash directory when installing " + aId , e ) ; } } let newFile = this . _directory . clone ( ) ; newFile . append ( aSource . leafName ) ; try { newFile . lastModifiedTime = Date . now ( ) ; } catch ( e ) { WARN ( "failed to set lastModifiedTime on " + newFile . path , e ) ; } this . _FileToIDMap [ newFile . path ] = aId ; this . _IDToFileMap [ aId ] = newFile ; if ( aExistingAddonID && aExistingAddonID != aId && aExistingAddonID in this . _IDToFileMap ) { delete this . _FileToIDMap [ this . _IDToFileMap [ aExistingAddonID ] ] ; delete this . _IDToFileMap [ aExistingAddonID ] ; } return newFile ; }
Installs an add-on into the install location.
Installs an add - on into the install location .
// If any of these operations fails the finally block will clean up the // temporary directory // It isn't ideal if this cleanup fails but it isn't worth rolling back // the install because of it.