diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp index 7f3584434a16..3c12874cf8a5 100644 --- a/toolkit/mozapps/update/updater/updater.cpp +++ b/toolkit/mozapps/update/updater/updater.cpp @@ -2085,6 +2085,50 @@ ReadMARChannelIDs(const NS_tchar *path, MARChannelStringTable *results) } #endif +static int +GetUpdateFileName(NS_tchar *fileName, int maxChars) +{ +#if defined(MOZ_WIDGET_GONK) + // If an update.link file exists, then it will contain the name + // of the update file (terminated by a newline). + + NS_tchar linkFileName[MAXPATHLEN]; + NS_tsnprintf(linkFileName, sizeof(linkFileName)/sizeof(linkFileName[0]), + NS_T("%s/update.link"), gSourcePath); + AutoFile linkFile = NS_tfopen(linkFileName, NS_T("rb")); + if (linkFile == NULL) { + NS_tsnprintf(fileName, maxChars, + NS_T("%s/update.mar"), gSourcePath); + return OK; + } + + char dataFileName[MAXPATHLEN]; + size_t bytesRead; + + if ((bytesRead = fread(dataFileName, 1, sizeof(dataFileName)-1, linkFile)) <= 0) { + *fileName = NS_T('\0'); + return READ_ERROR; + } + if (dataFileName[bytesRead-1] == '\n') { + // Strip trailing newline (for \n and \r\n) + bytesRead--; + } + if (dataFileName[bytesRead-1] == '\r') { + // Strip trailing CR (for \r, \r\n) + bytesRead--; + } + dataFileName[bytesRead] = '\0'; + + strncpy(fileName, dataFileName, maxChars-1); + fileName[maxChars-1] = '\0'; +#else + // We currently only support update.link files under GONK + NS_tsnprintf(fileName, maxChars, + NS_T("%s/update.mar"), gSourcePath); +#endif + return OK; +} + static void UpdateThreadFunc(void *param) { @@ -2094,10 +2138,10 @@ UpdateThreadFunc(void *param) rv = ProcessReplaceRequest(); } else { NS_tchar dataFile[MAXPATHLEN]; - NS_tsnprintf(dataFile, sizeof(dataFile)/sizeof(dataFile[0]), - NS_T("%s/update.mar"), gSourcePath); - - rv = gArchiveReader.Open(dataFile); + rv = GetUpdateFileName(dataFile, sizeof(dataFile)/sizeof(dataFile[0])); + if (rv == OK) { + rv = gArchiveReader.Open(dataFile); + } #ifdef MOZ_VERIFY_MAR_SIGNATURE if (rv == OK) { diff --git a/toolkit/xre/nsUpdateDriver.cpp b/toolkit/xre/nsUpdateDriver.cpp index 5b84ee3275af..580d82f186c9 100644 --- a/toolkit/xre/nsUpdateDriver.cpp +++ b/toolkit/xre/nsUpdateDriver.cpp @@ -987,8 +987,17 @@ nsUpdateProcessor::ProcessUpdate(nsIUpdate* aUpdate) if (dirProvider) { // Normal code path // Check for and process any available updates bool persistent; - nsresult rv = dirProvider->GetFile(XRE_UPDATE_ROOT_DIR, &persistent, - getter_AddRefs(updRoot)); + nsresult rv = NS_ERROR_FAILURE; // Take the NS_FAILED path when non-GONK +#ifdef MOZ_WIDGET_GONK + // Check in the sdcard for updates first, since that's our preferred + // download location. + rv = dirProvider->GetFile(XRE_UPDATE_ARCHIVE_DIR, &persistent, + getter_AddRefs(updRoot)); +#endif + if (NS_FAILED(rv)) { + rv = dirProvider->GetFile(XRE_UPDATE_ROOT_DIR, &persistent, + getter_AddRefs(updRoot)); + } // XRE_UPDATE_ROOT_DIR may fail. Fallback to appDir if failed if (NS_FAILED(rv)) updRoot = dirProvider->GetAppDir(); diff --git a/xpcom/build/nsXULAppAPI.h b/xpcom/build/nsXULAppAPI.h index c8d338ba7dce..311ac9f65dda 100644 --- a/xpcom/build/nsXULAppAPI.h +++ b/xpcom/build/nsXULAppAPI.h @@ -123,6 +123,14 @@ */ #define XRE_UPDATE_ROOT_DIR "UpdRootD" +/** + * A directory service key which provides an alternate location + * to UpdRootD to to store large files. This key is currently + * only implemented in the Gonk directory service provider. + */ + +#define XRE_UPDATE_ARCHIVE_DIR "UpdArchD" + /** * A directory service key which provides the directory where an OS update is * applied.