зеркало из https://github.com/mozilla/pjs.git
Bug 396457 - Store mTempFile as tempPath in moz_downloads table. r=sdwilsh, a=mconnor
This commit is contained in:
Родитель
267ac9fdfa
Коммит
058eacad84
|
@ -91,7 +91,7 @@ static PRBool gStoppingDownloads = PR_FALSE;
|
|||
|
||||
static const PRInt64 gUpdateInterval = 400 * PR_USEC_PER_MSEC;
|
||||
|
||||
#define DM_SCHEMA_VERSION 4
|
||||
#define DM_SCHEMA_VERSION 5
|
||||
#define DM_DB_NAME NS_LITERAL_STRING("downloads.sqlite")
|
||||
#define DM_DB_CORRUPT_FILENAME NS_LITERAL_STRING("downloads.sqlite.corrupt")
|
||||
|
||||
|
@ -356,6 +356,20 @@ nsDownloadManager::InitDB(PRBool *aDoImport)
|
|||
}
|
||||
// Fallthrough to the next upgrade
|
||||
|
||||
case 4: // This version adds a column to the database (tempPath)
|
||||
{
|
||||
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
||||
"ALTER TABLE moz_downloads "
|
||||
"ADD COLUMN tempPath TEXT"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Finally, update the schemaVersion variable and the database schema
|
||||
schemaVersion = 5;
|
||||
rv = mDBConn->SetSchemaVersion(schemaVersion);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// Fallthrough to the next upgrade
|
||||
|
||||
// Extra sanity checking for developers
|
||||
#ifndef DEBUG
|
||||
case DM_SCHEMA_VERSION:
|
||||
|
@ -385,8 +399,8 @@ nsDownloadManager::InitDB(PRBool *aDoImport)
|
|||
{
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT id, name, source, target, startTime, endTime, state, referrer, "
|
||||
"entityID "
|
||||
"SELECT id, name, source, target, tempPath, startTime, endTime, state, "
|
||||
"referrer, entityID "
|
||||
"FROM moz_downloads"), getter_AddRefs(stmt));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
break;
|
||||
|
@ -424,6 +438,7 @@ nsDownloadManager::CreateTable()
|
|||
"name TEXT, "
|
||||
"source TEXT, "
|
||||
"target TEXT, "
|
||||
"tempPath TEXT, "
|
||||
"startTime INTEGER, "
|
||||
"endTime INTEGER, "
|
||||
"state INTEGER, "
|
||||
|
@ -564,7 +579,8 @@ nsDownloadManager::ImportDownloadHistory()
|
|||
rv = rdfInt->GetValue(&state);
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
(void)AddDownloadToDB(name, source, target, startTime, endTime, state);
|
||||
(void)AddDownloadToDB(name, source, target, EmptyString(), startTime,
|
||||
endTime, state);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -632,6 +648,7 @@ PRInt64
|
|||
nsDownloadManager::AddDownloadToDB(const nsAString &aName,
|
||||
const nsACString &aSource,
|
||||
const nsACString &aTarget,
|
||||
const nsAString &aTempPath,
|
||||
PRInt64 aStartTime,
|
||||
PRInt64 aEndTime,
|
||||
PRInt32 aState)
|
||||
|
@ -639,8 +656,8 @@ nsDownloadManager::AddDownloadToDB(const nsAString &aName,
|
|||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"INSERT INTO moz_downloads "
|
||||
"(name, source, target, startTime, endTime, state) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6)"), getter_AddRefs(stmt));
|
||||
"(name, source, target, tempPath, startTime, endTime, state) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)"), getter_AddRefs(stmt));
|
||||
NS_ENSURE_SUCCESS(rv, 0);
|
||||
|
||||
PRInt32 i = 0;
|
||||
|
@ -656,6 +673,10 @@ nsDownloadManager::AddDownloadToDB(const nsAString &aName,
|
|||
rv = stmt->BindUTF8StringParameter(i++, aTarget);
|
||||
NS_ENSURE_SUCCESS(rv, 0);
|
||||
|
||||
// tempPath
|
||||
rv = stmt->BindStringParameter(i++, aTempPath);
|
||||
NS_ENSURE_SUCCESS(rv, 0);
|
||||
|
||||
// startTime
|
||||
rv = stmt->BindInt64Parameter(i++, aStartTime);
|
||||
NS_ENSURE_SUCCESS(rv, 0);
|
||||
|
@ -763,7 +784,8 @@ nsDownloadManager::GetDownloadFromDB(PRUint32 aID, nsDownload **retVal)
|
|||
// First, let's query the database and see if it even exists
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"SELECT id, state, startTime, source, target, name, referrer, entityID "
|
||||
"SELECT id, state, startTime, source, target, tempPath, name, referrer, "
|
||||
"entityID "
|
||||
"FROM moz_downloads "
|
||||
"WHERE id = ?1"), getter_AddRefs(stmt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -798,6 +820,13 @@ nsDownloadManager::GetDownloadFromDB(PRUint32 aID, nsDownload **retVal)
|
|||
rv = NS_NewURI(getter_AddRefs(dl->mTarget), target);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsString tempPath;
|
||||
stmt->GetString(i++, tempPath);
|
||||
if (!tempPath.IsEmpty()) {
|
||||
rv = NS_NewLocalFile(tempPath, PR_TRUE, getter_AddRefs(dl->mTempFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
stmt->GetString(i++, dl->mDisplayName);
|
||||
|
||||
nsCString referrer;
|
||||
|
@ -1085,7 +1114,13 @@ nsDownloadManager::AddDownload(DownloadType aDownloadType,
|
|||
aSource->GetSpec(source);
|
||||
aTarget->GetSpec(target);
|
||||
|
||||
PRInt64 id = AddDownloadToDB(dl->mDisplayName, source, target, aStartTime, 0,
|
||||
// Track the temp file for exthandler downloads
|
||||
nsAutoString tempPath;
|
||||
if (aTempFile)
|
||||
aTempFile->GetPath(tempPath);
|
||||
|
||||
PRInt64 id = AddDownloadToDB(dl->mDisplayName, source, target, tempPath,
|
||||
aStartTime, 0,
|
||||
nsIDownloadManager::DOWNLOAD_NOTSTARTED);
|
||||
NS_ENSURE_TRUE(id, NS_ERROR_FAILURE);
|
||||
dl->mID = id;
|
||||
|
|
|
@ -117,6 +117,7 @@ protected:
|
|||
PRInt64 AddDownloadToDB(const nsAString &aName,
|
||||
const nsACString &aSource,
|
||||
const nsACString &aTarget,
|
||||
const nsAString &aTempPath,
|
||||
PRInt64 aStartTime,
|
||||
PRInt64 aEndTime,
|
||||
PRInt32 aState);
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Download Manager Test Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
* Srirang G Doddihal <brahmana@doddihal.com>
|
||||
* Edward Lee <edward.lee@engineering.uiuc.edu>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by declaring the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not declare
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// This file tests migration from v4 to v5
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// First import the downloads.sqlite file
|
||||
importDatabaseFile("v4.sqlite");
|
||||
|
||||
// ok, now it is OK to init the download manager - this will perform the
|
||||
// migration!
|
||||
var dm = Cc["@mozilla.org/download-manager;1"].
|
||||
getService(Ci.nsIDownloadManager);
|
||||
var dbConn = dm.DBConnection;
|
||||
|
||||
// check schema version
|
||||
do_check_true(dbConn.schemaVersion >= 5);
|
||||
|
||||
// Check that the columns exist (no throw) and entries are correct
|
||||
var stmt = dbConn.createStatement(
|
||||
"SELECT name, source, target, startTime, endTime, state, referrer, " +
|
||||
"entityID, tempPath " +
|
||||
"FROM moz_downloads " +
|
||||
"WHERE id = 27");
|
||||
stmt.executeStep();
|
||||
do_check_eq("Firefox 2.0.0.6.dmg", stmt.getString(0));
|
||||
do_check_eq("http://ftp-mozilla.netscape.com/pub/mozilla.org/firefox/releases/2.0.0.6/mac/en-US/Firefox%202.0.0.6.dmg",
|
||||
stmt.getUTF8String(1));
|
||||
do_check_eq("file:///Users/sdwilsh/Desktop/Firefox%202.0.0.6.dmg",
|
||||
stmt.getUTF8String(2));
|
||||
do_check_eq(1187390974170783, stmt.getInt64(3));
|
||||
do_check_eq(1187391001257446, stmt.getInt64(4));
|
||||
do_check_eq(1, stmt.getInt32(5));
|
||||
do_check_eq("http://www.mozilla.com/en-US/products/download.html?product=firefox-2.0.0.6&os=osx&lang=en-US",stmt.getUTF8String(6));
|
||||
do_check_true(stmt.getIsNull(7));
|
||||
do_check_true(stmt.getIsNull(8));
|
||||
stmt.reset();
|
||||
|
||||
cleanup();
|
||||
}
|
Двоичный файл не отображается.
Загрузка…
Ссылка в новой задаче