From a4c7c7573f6bb1237b75c284bc510d65af31f46e Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Tue, 11 Mar 2003 21:36:59 +0000 Subject: [PATCH] Converting the file location of the component registry and the xpti manifest file to use the directory service. r=darin, b=191055 --- xpcom/components/nsComponentManager.cpp | 106 +++++++++--------- xpcom/components/nsComponentManager.h | 2 + xpcom/glue/standalone/nsDebugGlue.cpp | 87 -------------- xpcom/io/nsDirectoryService.cpp | 29 +++-- xpcom/io/nsDirectoryService.h | 1 + xpcom/io/nsDirectoryServiceDefs.h | 2 + .../xptinfo/src/xptiInterfaceInfoManager.cpp | 29 ++--- xpcom/reflect/xptinfo/src/xptiManifest.cpp | 39 +++---- xpcom/reflect/xptinfo/src/xptiprivate.h | 3 +- 9 files changed, 102 insertions(+), 196 deletions(-) delete mode 100644 xpcom/glue/standalone/nsDebugGlue.cpp diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index a70ba304e14e..cde81f596fc8 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -123,9 +123,6 @@ const static char XPCOM_ABSCOMPONENT_PREFIX[] = "abs:"; const static char XPCOM_RELCOMPONENT_PREFIX[] = "rel:"; const static char XPCOM_GRECOMPONENT_PREFIX[] = "gre:"; -const static char persistentRegistryFilename[] = "compreg.dat"; -const static char persistentRegistryTempFilename[] = "compreg.tmp"; - // Nonexistent factory entry // This is used to mark non-existent contractid mappings static nsFactoryEntry * kNonExistentContractID = (nsFactoryEntry*) 1; @@ -825,6 +822,14 @@ nsresult nsComponentManagerImpl::Init(void) mGREComponentsOffset = componentDescriptor.Length(); } + GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_REGISTRY_FILE, + getter_AddRefs(mRegistryFile)); + + if(!mRegistryFile) { + NS_WARNING("No Component Registry file was found in the directory service"); + return NS_ERROR_FAILURE; + } + PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Initialized.")); @@ -1034,24 +1039,22 @@ nsComponentManagerImpl::ReadPersistentRegistry() nsManifestLineReader reader; if (!mComponentsDir) - return NS_ERROR_FAILURE; // this should have been set by Init(). + return NS_ERROR_NOT_INITIALIZED; // this should have been set by Init(). PRFileDesc* fd = nsnull; - nsCOMPtr componentReg; + // Set From Init + if (!mRegistryFile) { + return NS_ERROR_FILE_NOT_FOUND; + } - rv = mComponentsDir->Clone(getter_AddRefs(componentReg)); - if (NS_FAILED(rv)) - return rv; - - rv = componentReg->AppendNative(nsDependentCString(persistentRegistryFilename)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr localFile = do_QueryInterface(componentReg, &rv); - if (NS_FAILED(rv)) - return rv; + nsCOMPtr file; + mRegistryFile->Clone(getter_AddRefs(file)); + if (!file) + return NS_ERROR_OUT_OF_MEMORY; + nsCOMPtr localFile(do_QueryInterface(file)); + rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd); if (NS_FAILED(rv)) return rv; @@ -1407,26 +1410,26 @@ nsComponentManagerImpl::WriteCategoryManagerToRegistry(PRFileDesc* fd) nsresult nsComponentManagerImpl::WritePersistentRegistry() { - if (!mComponentsDir) + if (!mRegistryFile) return NS_ERROR_FAILURE; // this should have been set by Init(). + nsCOMPtr file; + mRegistryFile->Clone(getter_AddRefs(file)); + if (!file) + return NS_ERROR_OUT_OF_MEMORY; + + nsCOMPtr localFile(do_QueryInterface(file)); + + nsCAutoString originalLeafName; + localFile->GetNativeLeafName(originalLeafName); + + nsCAutoString leafName; + leafName.Assign(originalLeafName + NS_LITERAL_CSTRING(".tmp")); + + localFile->SetNativeLeafName(leafName); + PRFileDesc* fd = nsnull; - - nsCOMPtr componentReg; - - nsresult rv = mComponentsDir->Clone(getter_AddRefs(componentReg)); - if (NS_FAILED(rv)) - return rv; - - rv = componentReg->AppendNative(nsDependentCString(persistentRegistryTempFilename)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr localFile = do_QueryInterface(componentReg, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666, &fd); + nsresult rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666, &fd); if (NS_FAILED(rv)) return rv; @@ -1472,27 +1475,20 @@ out: if (NS_FAILED(rv)) return rv; - nsCOMPtr mainFile; - rv = mComponentsDir->Clone(getter_AddRefs(mainFile)); - if (NS_FAILED(rv)) - return rv; - - rv = mainFile->AppendNative(nsDependentCString(persistentRegistryFilename)); - if (NS_FAILED(rv)) - return rv; + if (!mRegistryFile) + return NS_ERROR_NOT_INITIALIZED; PRBool exists; - rv = mainFile->Exists(&exists); - if (NS_FAILED(rv)) - return rv; + if(NS_FAILED(mRegistryFile->Exists(&exists))) + return PR_FALSE; + + if(exists && NS_FAILED(mRegistryFile->Remove(PR_FALSE))) + return PR_FALSE; + + nsCOMPtr parent; + mRegistryFile->GetParent(getter_AddRefs(parent)); - if (exists) - { - rv = mainFile->Remove(PR_FALSE); - if (NS_FAILED(rv)) - return rv; - } - rv = componentReg->MoveToNative(nsnull, nsDependentCString(persistentRegistryFilename)); + rv = localFile->MoveToNative(parent, originalLeafName); mRegistryDirty = PR_FALSE; return rv; @@ -3062,9 +3058,9 @@ nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when, } else { - GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_DIR, getter_AddRefs(dir)); + mComponentsDir->Clone(getter_AddRefs(dir)); if (!dir) - return NS_ERROR_UNEXPECTED; + return NS_ERROR_NOT_INITIALIZED; } nsCOMPtr iim = @@ -3140,9 +3136,9 @@ nsComponentManagerImpl::AutoRegisterNonNativeComponents(nsIFile* spec) nsCOMPtr directory = spec; if (!directory) { - GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_DIR, getter_AddRefs(directory)); + mComponentsDir->Clone(getter_AddRefs(directory)); if (!directory) - return NS_ERROR_UNEXPECTED; + return NS_ERROR_NOT_INITIALIZED; } for (int i = 1; i < mNLoaderData; i++) { diff --git a/xpcom/components/nsComponentManager.h b/xpcom/components/nsComponentManager.h index 3c4be29da8e0..f58df906e2fc 100644 --- a/xpcom/components/nsComponentManager.h +++ b/xpcom/components/nsComponentManager.h @@ -214,6 +214,8 @@ protected: nsCOMPtr mGREComponentsDir; PRInt32 mGREComponentsOffset; + nsCOMPtr mRegistryFile; + // Shutdown #define NS_SHUTDOWN_NEVERHAPPENED 0 #define NS_SHUTDOWN_INPROGRESS 1 diff --git a/xpcom/glue/standalone/nsDebugGlue.cpp b/xpcom/glue/standalone/nsDebugGlue.cpp deleted file mode 100644 index 367b5c575df4..000000000000 --- a/xpcom/glue/standalone/nsDebugGlue.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* ***** 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 Mozilla. - * - * The Initial Developer of the Original Code is Austin Powers. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * 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 deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * 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 ***** */ - -#include "nsDebug.h" - -// Empty implementation of nsDebug for XPCOM Glue - -void -nsDebug::AbortIfFalse(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) {} -void -nsDebug::WarnIfFalse(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) {} - -void -nsDebug::SetWarningMessageBoxEnable(PRBool aOnOff) {} - -PRBool -nsDebug::GetWarningMessageBoxEnable(void) { return PR_FALSE; } - - -void -nsDebug::Abort(const char* aFile, PRIntn aLine) {} - -void -nsDebug::Break(const char* aFile, PRIntn aLine) {} - -void -nsDebug::PreCondition(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) {} - -void -nsDebug::PostCondition(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) {} - -void -nsDebug::Assertion(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) { -} - -void -nsDebug::NotYetImplemented(const char* aMessage, - const char* aFile, PRIntn aLine) {} - -void -nsDebug::NotReached(const char* aMessage, - const char* aFile, PRIntn aLine) {} - -void -nsDebug::Error(const char* aMessage, - const char* aFile, PRIntn aLine) {} - -void -nsDebug::Warning(const char* aMessage, - const char* aFile, PRIntn aLine) {} diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index 4dc7bbb13d4b..fb166ff336e4 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -88,17 +88,11 @@ #define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("Component Registry") #define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("Components") #else -#define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("component.reg") +#define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("compreg.dat") #define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("components") #endif -#if defined(XP_MAC) -#define APP_REGISTRY_NAME "Application Registry" -#elif defined(XP_WIN) || defined(XP_OS2) -#define APP_REGISTRY_NAME "registry.dat" -#else -#define APP_REGISTRY_NAME "appreg" -#endif +#define XPTI_REGISTRY_NAME NS_LITERAL_CSTRING("xpti.dat") // define home directory // For Windows platform, We are choosing Appdata folder as HOME @@ -345,6 +339,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) nsIAtom* nsDirectoryService::sCurrentProcess = nsnull; nsIAtom* nsDirectoryService::sComponentRegistry = nsnull; +nsIAtom* nsDirectoryService::sXPTIRegistry = nsnull; nsIAtom* nsDirectoryService::sComponentDirectory = nsnull; nsIAtom* nsDirectoryService::sGRE_Directory = nsnull; nsIAtom* nsDirectoryService::sGRE_ComponentDirectory = nsnull; @@ -450,6 +445,7 @@ nsDirectoryService::Init() nsDirectoryService::sCurrentProcess = NS_NewAtom(NS_XPCOM_CURRENT_PROCESS_DIR); nsDirectoryService::sComponentRegistry = NS_NewAtom(NS_XPCOM_COMPONENT_REGISTRY_FILE); nsDirectoryService::sComponentDirectory = NS_NewAtom(NS_XPCOM_COMPONENT_DIR); + nsDirectoryService::sXPTIRegistry = NS_NewAtom(NS_XPCOM_XPTI_REGISTRY_FILE); nsDirectoryService::sGRE_Directory = NS_NewAtom(NS_GRE_DIR); nsDirectoryService::sGRE_ComponentDirectory = NS_NewAtom(NS_GRE_COMPONENT_DIR); @@ -546,6 +542,7 @@ nsDirectoryService::~nsDirectoryService() NS_IF_RELEASE(nsDirectoryService::sCurrentProcess); NS_IF_RELEASE(nsDirectoryService::sComponentRegistry); NS_IF_RELEASE(nsDirectoryService::sComponentDirectory); + NS_IF_RELEASE(nsDirectoryService::sXPTIRegistry); NS_IF_RELEASE(nsDirectoryService::sGRE_Directory); NS_IF_RELEASE(nsDirectoryService::sGRE_ComponentDirectory); NS_IF_RELEASE(nsDirectoryService::sOS_DriveDirectory); @@ -830,8 +827,20 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret else if (inAtom == nsDirectoryService::sComponentRegistry) { rv = GetCurrentProcessDirectory(getter_AddRefs(localFile)); - if (localFile) - localFile->AppendNative(COMPONENT_REGISTRY_NAME); + if (!localFile) + return NS_ERROR_FAILURE; + + localFile->AppendNative(COMPONENT_DIRECTORY); + localFile->AppendNative(COMPONENT_REGISTRY_NAME); + } + else if (inAtom == nsDirectoryService::sXPTIRegistry) + { + rv = GetCurrentProcessDirectory(getter_AddRefs(localFile)); + if (!localFile) + return NS_ERROR_FAILURE; + + localFile->AppendNative(COMPONENT_DIRECTORY); + localFile->AppendNative(XPTI_REGISTRY_NAME); } else if (inAtom == nsDirectoryService::sGRE_Directory) { diff --git a/xpcom/io/nsDirectoryService.h b/xpcom/io/nsDirectoryService.h index ef21f721965d..d5c6044ae656 100644 --- a/xpcom/io/nsDirectoryService.h +++ b/xpcom/io/nsDirectoryService.h @@ -84,6 +84,7 @@ private: static nsIAtom *sCurrentProcess; static nsIAtom *sComponentRegistry; static nsIAtom *sComponentDirectory; + static nsIAtom *sXPTIRegistry; static nsIAtom *sGRE_Directory; static nsIAtom *sGRE_ComponentDirectory; static nsIAtom *sOS_DriveDirectory; diff --git a/xpcom/io/nsDirectoryServiceDefs.h b/xpcom/io/nsDirectoryServiceDefs.h index 178be807aa85..3c75d4decea7 100755 --- a/xpcom/io/nsDirectoryServiceDefs.h +++ b/xpcom/io/nsDirectoryServiceDefs.h @@ -60,6 +60,8 @@ #define NS_GRE_DIR "GreD" #define NS_GRE_COMPONENT_DIR "GreComsD" +#define NS_XPCOM_XPTI_REGISTRY_FILE "XptiRegF" + #define NS_OS_HOME_DIR "Home" #define NS_OS_DRIVE_DIR "DrvD" #define NS_OS_TEMP_DIR "TmpD" diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index 640bce0bc2f6..b5ecd9814e3e 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -277,29 +277,18 @@ PRBool xptiInterfaceInfoManager::BuildFileSearchPath(nsISupportsArray** aPath) } PRBool -xptiInterfaceInfoManager::GetCloneOfManifestDir(nsILocalFile** aDir) +xptiInterfaceInfoManager::GetCloneOfManifestLocation(nsILocalFile** aFile) { - // We cache the manifest directory to ensure that this call always returns - // the same directory. Not doing so could be a problem if we try something - // fancier in the future and that algorithm has different results when - // run at startup than when run later. + // We *trust* that this will not change! + nsCOMPtr lf; + nsresult rv = GetDirectoryFromDirService(NS_XPCOM_XPTI_REGISTRY_FILE, + getter_AddRefs(lf)); - if(!mManifestDir) - { - // If we are going to do something fancy to get some other dir, then - // do it here... + if (NS_FAILED(rv)) return PR_FALSE; - if(!GetDirectoryFromDirService(NS_XPCOM_COMPONENT_DIR, - getter_AddRefs(mManifestDir))) - return PR_FALSE; - - // To be sure after the stuff above. - if(!mManifestDir) - return PR_FALSE; - - mManifestDir->Create(nsIFile::DIRECTORY_TYPE, 0666); - } - return NS_SUCCEEDED(xptiCloneLocalFile(mManifestDir, aDir)); + rv = xptiCloneLocalFile(lf, aFile); + if (NS_FAILED(rv)) return PR_FALSE; + return PR_TRUE; } PRBool diff --git a/xpcom/reflect/xptinfo/src/xptiManifest.cpp b/xpcom/reflect/xptinfo/src/xptiManifest.cpp index f2a9e80e3f22..b426e6f866e3 100644 --- a/xpcom/reflect/xptinfo/src/xptiManifest.cpp +++ b/xpcom/reflect/xptinfo/src/xptiManifest.cpp @@ -43,9 +43,6 @@ #include "nsManifestLineReader.h" #include "nsString.h" -#define g_MainManifestFilename NS_LITERAL_CSTRING("xpti.dat") -#define g_TempManifestFilename NS_LITERAL_CSTRING("xptitemp.dat") - static const char g_Disclaimer[] = "# Generated file. ** DO NOT EDIT! **"; static const char g_TOKEN_Files[] = "Files"; @@ -133,17 +130,21 @@ PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr, nsCAutoString appDirString; nsCOMPtr tempFile; - if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(tempFile)) || !tempFile) + if(!aMgr->GetCloneOfManifestLocation(getter_AddRefs(tempFile)) || !tempFile) return PR_FALSE; - if(NS_FAILED(tempFile->AppendNative(g_TempManifestFilename))) - return PR_FALSE; + nsCAutoString originalLeafName; + tempFile->GetNativeLeafName(originalLeafName); + + nsCAutoString leafName; + leafName.Assign(originalLeafName + NS_LITERAL_CSTRING(".tmp")); + + tempFile->SetNativeLeafName(leafName); // All exits via "goto out;" from here on... - if(NS_FAILED(tempFile-> - OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, - 0666, &fd)) || !fd) + OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, + 0666, &fd)) || !fd) { goto out; } @@ -259,10 +260,7 @@ out: { // delete the old file and rename this nsCOMPtr mainFile; - if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(mainFile)) || !mainFile) - return PR_FALSE; - - if(NS_FAILED(mainFile->AppendNative(g_MainManifestFilename))) + if(!aMgr->GetCloneOfManifestLocation(getter_AddRefs(mainFile)) || !mainFile) return PR_FALSE; PRBool exists; @@ -272,8 +270,11 @@ out: if(exists && NS_FAILED(mainFile->Remove(PR_FALSE))) return PR_FALSE; + nsCOMPtr parent; + mainFile->GetParent(getter_AddRefs(parent)); + // MoveTo means rename. - if(NS_FAILED(tempFile->MoveToNative(nsnull, g_MainManifestFilename))) + if(NS_FAILED(tempFile->MoveToNative(parent, originalLeafName))) return PR_FALSE; } @@ -294,10 +295,7 @@ ReadManifestIntoMemory(xptiInterfaceInfoManager* aMgr, PRBool success = PR_FALSE; nsCOMPtr aFile; - if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(aFile)) || !aFile) - return nsnull; - - if(NS_FAILED(aFile->AppendNative(g_MainManifestFilename))) + if(!aMgr->GetCloneOfManifestLocation(getter_AddRefs(aFile)) || !aFile) return nsnull; #ifdef DEBUG @@ -697,10 +695,7 @@ PRBool xptiManifest::Read(xptiInterfaceInfoManager* aMgr, PRBool xptiManifest::Delete(xptiInterfaceInfoManager* aMgr) { nsCOMPtr aFile; - if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(aFile)) || !aFile) - return PR_FALSE; - - if(NS_FAILED(aFile->AppendNative(g_MainManifestFilename))) + if(!aMgr->GetCloneOfManifestLocation(getter_AddRefs(aFile)) || !aFile) return PR_FALSE; PRBool exists; diff --git a/xpcom/reflect/xptinfo/src/xptiprivate.h b/xpcom/reflect/xptinfo/src/xptiprivate.h index 2deb05cb8c9a..fccf6e61e659 100644 --- a/xpcom/reflect/xptinfo/src/xptiprivate.h +++ b/xpcom/reflect/xptinfo/src/xptiprivate.h @@ -884,7 +884,7 @@ public: xptiWorkingSet* aWorkingSet = nsnull); PRBool GetApplicationDir(nsILocalFile** aDir); - PRBool GetCloneOfManifestDir(nsILocalFile** aDir); + PRBool GetCloneOfManifestLocation(nsILocalFile** aDir); void GetSearchPath(nsISupportsArray** aSearchPath) {NS_ADDREF(*aSearchPath = mSearchPath);} @@ -965,7 +965,6 @@ private: PRMonitor* mInfoMonitor; PRLock* mAdditionalManagersLock; nsSupportsArray mAdditionalManagers; - nsCOMPtr mManifestDir; nsCOMPtr mSearchPath; };