B2G/gecko/toolkit/mozapps/extensions/XPIProviderUtils.js
/**
   * Opens a new connection to the database file.
   *
   * @param  aRebuildOnError
   *         A boolean indicating whether add-on information should be loaded
   *         from the install locations if the database needs to be rebuilt.
   * @return the migration data from the database if it was an old schema or
   *         null otherwise.
   */
Opens a new connection to the database file.
@param  aRebuildOnError
A boolean indicating whether add-on information should be loaded
from the install locations if the database needs to be rebuilt.
@return the migration data from the database if it was an old schema or
null otherwise.
Opens a new connection to the database file . @param aRebuildOnError A boolean indicating whether add - on information should be loaded from the install locations if the database needs to be rebuilt . @return the migration data from the database if it was an old schema or null otherwise .
function XPIDB_openConnection(aRebuildOnError, aForceOpen) {
    delete this.connection;
    if (!aForceOpen && !this.dbfileExists) {
      this.connection = null;
      return {};
    }
    this.initialized = true;
    this.migrateData = null;
    this.connection = this.openDatabaseFile(this.dbfile);
    let schemaVersion = this.connection.schemaVersion;
    if (schemaVersion != DB_SCHEMA) {
      if (schemaVersion != 0) {
        LOG("Migrating data from schema " + schemaVersion);
        this.migrateData = this.getMigrateDataFromDatabase();
        this.connection.close();
        try {
          if (this.dbfileExists)
            this.dbfile.remove(true);
          this.connection = this.openDatabaseFile(this.dbfile);
        }
        catch (e) {
          ERROR("Failed to remove old database", e);
          this.connection = Services.storage.openSpecialDatabase("memory");
        }
      }
      else {
        let dbSchema = 0;
        try {
          dbSchema = Services.prefs.getIntPref(PREF_DB_SCHEMA);
        } catch (e) {}
        if (dbSchema == 0) {
          this.migrateData = this.getMigrateDataFromRDF();
        }
      }
      try {
        this.createSchema();
      }
      catch (e) {
        this.connection = Services.storage.openSpecialDatabase("memory");
      }
      if (!this.migrateData)
        this.activeBundles = this.getActiveBundles();
      if (aRebuildOnError) {
        WARN("Rebuilding add-ons database from installed extensions.");
        this.beginTransaction();
        try {
          let state = XPIProvider.getInstallLocationStates();
          XPIProvider.processFileChanges(state, {}, false);
          Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, true);
          this.commitTransaction();
        }
        catch (e) {
          ERROR("Error processing file changes", e);
          this.rollbackTransaction();
        }
      }
    }
    if (this.connection.databaseFile) {
      Services.prefs.setIntPref(PREF_DB_SCHEMA, DB_SCHEMA);
      Services.prefs.savePrefFile(null);
    }
    for (let i = 0; i < this.transactionCount; i++)
      this.connection.executeSimpleSQL("SAVEPOINT 'default'");
  }
function XPIDB_openConnection ( aRebuildOnError , aForceOpen ) { delete this . connection ; if ( ! aForceOpen && ! this . dbfileExists ) { this . connection = null ; return { } ; } this . initialized = true ; this . migrateData = null ; this . connection = this . openDatabaseFile ( this . dbfile ) ; let schemaVersion = this . connection . schemaVersion ; if ( schemaVersion != DB_SCHEMA ) { if ( schemaVersion != 0 ) { LOG ( "Migrating data from schema " + schemaVersion ) ; this . migrateData = this . getMigrateDataFromDatabase ( ) ; this . connection . close ( ) ; try { if ( this . dbfileExists ) this . dbfile . remove ( true ) ; this . connection = this . openDatabaseFile ( this . dbfile ) ; } catch ( e ) { ERROR ( "Failed to remove old database" , e ) ; this . connection = Services . storage . openSpecialDatabase ( "memory" ) ; } } else { let dbSchema = 0 ; try { dbSchema = Services . prefs . getIntPref ( PREF_DB_SCHEMA ) ; } catch ( e ) { } if ( dbSchema == 0 ) { this . migrateData = this . getMigrateDataFromRDF ( ) ; } } try { this . createSchema ( ) ; } catch ( e ) { this . connection = Services . storage . openSpecialDatabase ( "memory" ) ; } if ( ! this . migrateData ) this . activeBundles = this . getActiveBundles ( ) ; if ( aRebuildOnError ) { WARN ( "Rebuilding add-ons database from installed extensions." ) ; this . beginTransaction ( ) ; try { let state = XPIProvider . getInstallLocationStates ( ) ; XPIProvider . processFileChanges ( state , { } , false ) ; Services . prefs . setBoolPref ( PREF_PENDING_OPERATIONS , true ) ; this . commitTransaction ( ) ; } catch ( e ) { ERROR ( "Error processing file changes" , e ) ; this . rollbackTransaction ( ) ; } } } if ( this . connection . databaseFile ) { Services . prefs . setIntPref ( PREF_DB_SCHEMA , DB_SCHEMA ) ; Services . prefs . savePrefFile ( null ) ; } for ( let i = 0 ; i < this . transactionCount ; i ++ ) this . connection . executeSimpleSQL ( "SAVEPOINT 'default'" ) ; }
Opens a new connection to the database file.
Opens a new connection to the database file .
// If the database was corrupt or missing then the new blank database will // have a schema version of 0. // A non-zero schema version means that a schema has been successfully // created in the database in the past so we might be able to get useful // information from it // Delete the existing database // Reopen an empty database // If the file couldn't be deleted then fall back to an in-memory // database // Only migrate data from the RDF if we haven't done it before // At this point the database should be completely empty // If creating the schema fails, then the database is unusable, // fall back to an in-memory database. // If there is no migration data then load the list of add-on directories // that were active during the last run // Make sure to update the active add-ons and add-ons list on shutdown // If the database connection has a file open then it has the right schema // by now so make sure the preferences reflect that. // Begin any pending transactions