зеркало из https://github.com/mozilla/pjs.git
Converting the file location of the component registry and the xpti manifest file to use the directory service. r=darin, b=191055
This commit is contained in:
Родитель
5afc67f9b3
Коммит
da37fd9b09
|
@ -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<nsIFile> 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<nsILocalFile> localFile = do_QueryInterface(componentReg, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIFile> file;
|
||||
mRegistryFile->Clone(getter_AddRefs(file));
|
||||
if (!file)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsILocalFile> 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<nsIFile> file;
|
||||
mRegistryFile->Clone(getter_AddRefs(file));
|
||||
if (!file)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsILocalFile> 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<nsIFile> 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<nsILocalFile> 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<nsIFile> 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<nsIFile> 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<nsIInterfaceInfoManager> iim =
|
||||
|
@ -3140,9 +3136,9 @@ nsComponentManagerImpl::AutoRegisterNonNativeComponents(nsIFile* spec)
|
|||
nsCOMPtr<nsIFile> 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++) {
|
||||
|
|
|
@ -214,6 +214,8 @@ protected:
|
|||
nsCOMPtr<nsIFile> mGREComponentsDir;
|
||||
PRInt32 mGREComponentsOffset;
|
||||
|
||||
nsCOMPtr<nsIFile> mRegistryFile;
|
||||
|
||||
// Shutdown
|
||||
#define NS_SHUTDOWN_NEVERHAPPENED 0
|
||||
#define NS_SHUTDOWN_INPROGRESS 1
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<nsILocalFile> 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
|
||||
|
|
|
@ -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<nsILocalFile> 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<nsILocalFile> 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<nsIFile> 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<nsILocalFile> 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<nsILocalFile> 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;
|
||||
|
|
|
@ -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<nsILocalFile> mManifestDir;
|
||||
nsCOMPtr<nsISupportsArray> mSearchPath;
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче