зеркало из https://github.com/mozilla/gecko-dev.git
Bug 311238 ns*SummarySpec.* are no longer required (Part 2 - provide some utility functions). r=bienvenu,sr=dmose
This commit is contained in:
Родитель
4aadba5105
Коммит
fd03f141d0
|
@ -1125,3 +1125,57 @@ void Seconds2PRTime(PRUint32 seconds, PRTime *prTime)
|
|||
LL_UI2L(intermediateResult, seconds);
|
||||
LL_MUL((*prTime), intermediateResult, microSecondsPerSecond);
|
||||
}
|
||||
|
||||
nsresult GetSummaryFileLocation(nsIFile* fileLocation, nsIFile** summaryLocation)
|
||||
{
|
||||
nsIFile* newSummaryLocation;
|
||||
|
||||
nsresult rv = fileLocation->Clone(&newSummaryLocation);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXPIDLCString fileName;
|
||||
|
||||
rv = newSummaryLocation->GetNativeLeafName(fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
fileName.Append(NS_LITERAL_CSTRING(SUMMARY_SUFFIX));
|
||||
|
||||
rv = newSummaryLocation->SetNativeLeafName(fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*summaryLocation = newSummaryLocation;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult GetSummaryFileLocation(nsIFileSpec* fileLocation, nsIFileSpec** summaryLocation)
|
||||
{
|
||||
nsIFileSpec* newSummaryLocation;
|
||||
nsresult rv = NS_NewFileSpec(&newSummaryLocation);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = newSummaryLocation->FromFileSpec(fileLocation);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXPIDLCString fileName;
|
||||
|
||||
rv = newSummaryLocation->GetLeafName(getter_Copies(fileName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
fileName.Append(NS_LITERAL_CSTRING(SUMMARY_SUFFIX));
|
||||
|
||||
rv = newSummaryLocation->SetLeafName(fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*summaryLocation = newSummaryLocation;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult GetSummaryFileLocation(nsIFileSpec* fileLocation, nsFileSpec* summaryLocation)
|
||||
{
|
||||
nsCOMPtr<nsIFileSpec> summaryIFile;
|
||||
nsresult rv = GetSummaryFileLocation(fileLocation, getter_AddRefs(summaryIFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return summaryIFile->GetFileSpec(summaryLocation);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "MailNewsTypes2.h"
|
||||
|
||||
class nsFileSpec;
|
||||
class nsIFileSpec;
|
||||
class nsILocalFile;
|
||||
class nsIPrefBranch;
|
||||
|
@ -138,5 +139,18 @@ NS_MSG_BASE void PRTime2Seconds(PRTime prTime, PRUint32 *seconds);
|
|||
NS_MSG_BASE void PRTime2Seconds(PRTime prTime, PRInt32 *seconds);
|
||||
NS_MSG_BASE void Seconds2PRTime(PRUint32 seconds, PRTime *prTime);
|
||||
|
||||
// Appends the correct summary file extension onto the supplied fileLocation
|
||||
// and returns it in summaryLocation.
|
||||
NS_MSG_BASE nsresult GetSummaryFileLocation(nsIFile* fileLocation,
|
||||
nsIFile** summaryLocation);
|
||||
// XXX This function is provided temporarily whilst we are still working
|
||||
// on bug 33451 to remove nsIFileSpec from mailnews.
|
||||
NS_MSG_BASE nsresult GetSummaryFileLocation(nsIFileSpec* fileLocation,
|
||||
nsIFileSpec** summaryLocation);
|
||||
// XXX This function is provided temporarily whilst we are still working
|
||||
// on bug 33451 to remove nsIFileSpec from mailnews.
|
||||
NS_MSG_BASE nsresult GetSummaryFileLocation(nsIFileSpec* fileLocation,
|
||||
nsFileSpec* summaryLocation);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@
|
|||
#include "prprf.h"
|
||||
#include "nsTime.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsLocalFolderSummarySpec.h"
|
||||
#include "nsMsgDBCID.h"
|
||||
#include "nsILocale.h"
|
||||
#include "nsLocaleCID.h"
|
||||
|
@ -75,6 +74,7 @@
|
|||
#include "nsIMsgFolderCache.h"
|
||||
#include "nsIMsgFolderCacheElement.h"
|
||||
#include "MailNewsTypes2.h"
|
||||
#include "nsMsgUtils.h"
|
||||
|
||||
static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
|
||||
|
||||
|
@ -176,19 +176,17 @@ NS_IMETHODIMP nsMsgDBService::OpenFolderDB(nsIMsgFolder *aFolder, PRBool aCreate
|
|||
|
||||
NS_IMETHODIMP nsMsgDBService::OpenMailDBFromFileSpec(nsIFileSpec *aFolderName, PRBool aCreate, PRBool aLeaveInvalidDB, nsIMsgDatabase** pMessageDB)
|
||||
{
|
||||
nsFileSpec folderName;
|
||||
|
||||
if (!aFolderName)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
aFolderName->GetFileSpec(&folderName);
|
||||
nsLocalFolderSummarySpec summarySpec(folderName);
|
||||
|
||||
nsFileSpec dbPath(summarySpec);
|
||||
nsFileSpec dbPath;
|
||||
nsresult rv = GetSummaryFileLocation(aFolderName, &dbPath);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*pMessageDB = (nsMsgDatabase *) nsMsgDatabase::FindInCache(dbPath);
|
||||
if (*pMessageDB)
|
||||
return NS_OK;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIMsgDatabase> msgDB = do_CreateInstance(NS_MAILBOXDB_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = msgDB->Open(aFolderName, aCreate, aLeaveInvalidDB);
|
||||
|
@ -819,15 +817,16 @@ nsMsgDatabase* nsMsgDatabase::FindInCache(nsFileSpec &dbName)
|
|||
//----------------------------------------------------------------------
|
||||
nsIMsgDatabase* nsMsgDatabase::FindInCache(nsIMsgFolder *folder)
|
||||
{
|
||||
nsCOMPtr <nsIFileSpec> folderPath;
|
||||
nsFileSpec folderName;
|
||||
nsCOMPtr<nsIFileSpec> folderPath;
|
||||
|
||||
nsresult rv = folder->GetPath(getter_AddRefs(folderPath));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
folderPath->GetFileSpec(&folderName);
|
||||
nsLocalFolderSummarySpec summarySpec(folderName);
|
||||
|
||||
nsFileSpec dbPath(summarySpec);
|
||||
return (nsIMsgDatabase *) FindInCache(dbPath);
|
||||
nsFileSpec summaryFile;
|
||||
rv = GetSummaryFileLocation(folderPath, &summaryFile);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return (nsIMsgDatabase *) FindInCache(summaryFile);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -1086,29 +1085,32 @@ NS_IMETHODIMP nsMsgDatabase::Open(nsIFileSpec *aFolderName, PRBool aCreate, PRBo
|
|||
if (!aFolderName)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsFileSpec folderName;
|
||||
aFolderName->GetFileSpec(&folderName);
|
||||
nsLocalFolderSummarySpec summarySpec(folderName);
|
||||
|
||||
nsCOMPtr<nsIFileSpec> folderName;
|
||||
nsresult err = GetSummaryFileLocation(aFolderName, getter_AddRefs(folderName));
|
||||
NS_ENSURE_SUCCESS(err, err);
|
||||
|
||||
nsFileSpec summaryFile;
|
||||
err = folderName->GetFileSpec(&summaryFile);
|
||||
NS_ENSURE_SUCCESS(err, err);
|
||||
|
||||
nsIDBFolderInfo *folderInfo = nsnull;
|
||||
|
||||
#if defined(DEBUG_bienvenu)
|
||||
|
||||
printf("really opening db in nsImapMailDatabase::Open(%s, %s, %p, %s) -> %s\n",
|
||||
(const char*)folderName, aCreate ? "TRUE":"FALSE",
|
||||
this, aLeaveInvalidDB ? "TRUE":"FALSE", (const char*)folderName);
|
||||
#endif
|
||||
// if the old summary doesn't exist, we're creating a new one.
|
||||
if ((!summarySpec.Exists() || !summarySpec.GetFileSize()) && aCreate)
|
||||
if ((!summaryFile.Exists() || !summaryFile.GetFileSize()) && aCreate)
|
||||
newFile = PR_TRUE;
|
||||
|
||||
// stat file before we open the db, because if we've latered
|
||||
// any messages, handling latered will change time stamp on
|
||||
// folder file.
|
||||
summaryFileExists = summarySpec.Exists() && summarySpec.GetFileSize() > 0;
|
||||
summaryFileExists = summaryFile.Exists() && summaryFile.GetFileSize() > 0;
|
||||
|
||||
nsresult err = NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE;
|
||||
|
||||
err = OpenMDB((const char *) summarySpec, aCreate);
|
||||
err = OpenMDB((const char *) summaryFile, aCreate);
|
||||
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
|
@ -1148,7 +1150,7 @@ NS_IMETHODIMP nsMsgDatabase::Open(nsIFileSpec *aFolderName, PRBool aCreate, PRBo
|
|||
NS_IF_RELEASE(m_dbFolderInfo);
|
||||
ForceClosed();
|
||||
if (err == NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE)
|
||||
summarySpec.Delete(PR_FALSE);
|
||||
summaryFile.Delete(PR_FALSE);
|
||||
}
|
||||
if (err != NS_OK || newFile)
|
||||
{
|
||||
|
@ -1161,7 +1163,7 @@ NS_IMETHODIMP nsMsgDatabase::Open(nsIFileSpec *aFolderName, PRBool aCreate, PRBo
|
|||
else if (err != NS_OK && err != NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE)
|
||||
{
|
||||
Close(PR_FALSE);
|
||||
summarySpec.Delete(PR_FALSE); // blow away the db if it's corrupt.
|
||||
summaryFile.Delete(PR_FALSE); // blow away the db if it's corrupt.
|
||||
}
|
||||
}
|
||||
if (err == NS_OK || err == NS_MSG_ERROR_FOLDER_SUMMARY_MISSING)
|
||||
|
@ -1298,17 +1300,15 @@ nsresult nsMsgDatabase::CloseMDB(PRBool commit)
|
|||
NS_IMETHODIMP nsMsgDatabase::ForceFolderDBClosed(nsIMsgFolder *aFolder)
|
||||
{
|
||||
NS_ENSURE_ARG(aFolder);
|
||||
nsCOMPtr <nsIFileSpec> folderPath;
|
||||
nsFileSpec folderName;
|
||||
|
||||
nsCOMPtr<nsIFileSpec> folderPath;
|
||||
nsresult rv = aFolder->GetPath(getter_AddRefs(folderPath));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
folderPath->GetFileSpec(&folderName);
|
||||
nsLocalFolderSummarySpec summarySpec(folderName);
|
||||
|
||||
|
||||
nsFileSpec dbPath(summarySpec);
|
||||
|
||||
|
||||
nsFileSpec dbPath;
|
||||
rv = GetSummaryFileLocation(folderPath, &dbPath);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsIMsgDatabase *mailDB = (nsMsgDatabase *) FindInCache(dbPath);
|
||||
if (mailDB)
|
||||
{
|
||||
|
|
|
@ -1495,17 +1495,22 @@ NS_IMETHODIMP nsImapMailFolder::Delete ()
|
|||
mDatabase = nsnull;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFileSpec> pathSpec;
|
||||
rv = GetPath(getter_AddRefs(pathSpec));
|
||||
nsCOMPtr<nsILocalFile> path;
|
||||
rv = GetFilePath(getter_AddRefs(path));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsFileSpec fileSpec;
|
||||
rv = pathSpec->GetFileSpec(&fileSpec);
|
||||
nsCOMPtr<nsIFile> summaryLocation;
|
||||
rv = GetSummaryFileLocation(path, getter_AddRefs(summaryLocation));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsLocalFolderSummarySpec summarySpec(fileSpec);
|
||||
if (summarySpec.Exists())
|
||||
summarySpec.Delete(PR_FALSE);
|
||||
PRBool exists = PR_FALSE;
|
||||
rv = summaryLocation->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && exists)
|
||||
{
|
||||
rv = summaryLocation->Remove(PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING("failed to remove imap summary file");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mPath)
|
||||
|
|
|
@ -597,30 +597,33 @@ NS_IMETHODIMP nsMsgNewsFolder::Delete()
|
|||
mDatabase = nsnull;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFileSpec> pathSpec;
|
||||
rv = GetPath(getter_AddRefs(pathSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsILocalFile> folderPath;
|
||||
rv = GetFilePath(getter_AddRefs(folderPath));
|
||||
|
||||
nsFileSpec path;
|
||||
rv = pathSpec->GetFileSpec(&path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIFile> summaryPath;
|
||||
rv = GetSummaryFileLocation(folderPath, getter_AddRefs(summaryPath));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool exists = PR_FALSE;
|
||||
rv = folderPath->Exists(&exists);
|
||||
|
||||
// delete local store, if it exists
|
||||
if (path.Exists())
|
||||
path.Delete(PR_FALSE);
|
||||
if (NS_SUCCEEDED(rv) && exists)
|
||||
rv = folderPath->Remove(PR_FALSE);
|
||||
|
||||
// Remove summary file.
|
||||
nsXPIDLCString summaryFile;
|
||||
rv = pathSpec->GetLeafName(getter_Copies(summaryFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING("Failed to remove News Folder");
|
||||
|
||||
summaryFile.Append(SUMMARY_SUFFIX);
|
||||
rv = summaryPath->Exists(&exists);
|
||||
|
||||
rv = pathSpec->SetLeafName(summaryFile.get());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_SUCCEEDED(rv) && exists)
|
||||
rv = summaryPath->Remove(PR_FALSE);
|
||||
|
||||
rv = pathSpec->Delete(PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING("Failed to remove News Folder Summary File");
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr <nsINntpIncomingServer> nntpServer;
|
||||
rv = GetNntpServer(getter_AddRefs(nntpServer));
|
||||
|
|
Загрузка…
Ссылка в новой задаче