mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +00:00
start implementing open routines
This commit is contained in:
parent
78a1dc1a1a
commit
1f4a25686d
@ -31,7 +31,7 @@ EXPORTS = \
|
||||
|
||||
CPPSRCS = \
|
||||
nsMsgDatabase.cpp\
|
||||
nsMailMsgDatabase.cpp\
|
||||
nsMailDatabase.cpp\
|
||||
$(NULL)
|
||||
|
||||
DIRS = public src tests
|
||||
|
@ -22,17 +22,17 @@ include <$(DEPTH)\config\config.mak>
|
||||
|
||||
LIBRARY_NAME=mailnews
|
||||
MODULE= mailnews
|
||||
REQUIRES=
|
||||
REQUIRES=rdf
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= nsMsgDatabase.cpp\
|
||||
nsMailMsgDatabase.cpp\
|
||||
nsMailDatabase.cpp\
|
||||
nsMsgHdr.cpp\
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= .\$(OBJDIR)\nsMsgDatabase.obj \
|
||||
.\$(OBJDIR)\nsMailMsgDatabase.obj\
|
||||
.\$(OBJDIR)\nsMailDatabase.obj\
|
||||
.\$(OBJDIR)\nsMsgHdr.obj\
|
||||
$(NULL)
|
||||
|
||||
@ -41,7 +41,7 @@ EXPORTS= \
|
||||
$(NULL)
|
||||
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\mailnews -I$(PUBLIC)\raptor
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\mailnews -I$(PUBLIC)\raptor -I$(PUBLIC)\rdf
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
|
@ -18,3 +18,185 @@
|
||||
|
||||
#include "nsMailDatabase.h"
|
||||
|
||||
nsMailDatabase::nsMailDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
nsMailDatabase::~nsMailDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static nsresult nsMailDatabase::Open(nsFilePath &dbName, PRBool create, nsMailDatabase** pMessageDB)
|
||||
{
|
||||
nsMailDatabase *mailDB;
|
||||
int statResult;
|
||||
XP_StatStruct st;
|
||||
XP_Bool newFile = FALSE;
|
||||
|
||||
// OK, dbName is probably folder name, since I can't figure out how nsFilePath interacts
|
||||
// with xpFileTypes and its related routines.
|
||||
const char *folderName = dbName;
|
||||
|
||||
*pMessageDB = NULL;
|
||||
|
||||
mailDB = (nsMailDatabase *) FindInCache(dbName);
|
||||
if (mailDB)
|
||||
{
|
||||
*pMessageDB = mailDB;
|
||||
mailDB->AddRef();
|
||||
return(NS_OK);
|
||||
}
|
||||
// if the old summary doesn't exist, we're creating a new one.
|
||||
if (XP_Stat (folderName, &st, xpMailFolderSummary) && create)
|
||||
newFile = TRUE;
|
||||
|
||||
|
||||
mailDB = new nsMailDatabase;
|
||||
|
||||
if (!mailDB)
|
||||
return(eOUT_OF_MEMORY);
|
||||
|
||||
mailDB->m_folderName = XP_STRDUP(folderName);
|
||||
|
||||
dbName = WH_FileName(folderName, xpMailFolderSummary);
|
||||
if (!dbName) return eOUT_OF_MEMORY;
|
||||
// stat file before we open the db, because if we've latered
|
||||
// any messages, handling latered will change time stamp on
|
||||
// folder file.
|
||||
result = XP_Stat( newName, info );
|
||||
statResult = XP_Stat (folderName, &st, xpMailFolder);
|
||||
|
||||
MsgERR err = mailDB->OpenMDB(dbName, create);
|
||||
XP_FREE(dbName);
|
||||
|
||||
if (err == eSUCCESS)
|
||||
{
|
||||
folderInfo = mailDB->GetDBFolderInfo();
|
||||
if (folderInfo == NULL)
|
||||
{
|
||||
err = eOldSummaryFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if opening existing file, make sure summary file is up to date.
|
||||
// if caller is upgrading, don't return eOldSummaryFile so the caller
|
||||
// can pull out the transfer info for the new db.
|
||||
if (!newFile && !statResult && !upgrading)
|
||||
{
|
||||
if (folderInfo->m_folderSize != st.st_size ||
|
||||
folderInfo->m_folderDate != st.st_mtime || folderInfo->GetNumNewMessages() < 0)
|
||||
err = eOldSummaryFile;
|
||||
}
|
||||
// compare current version of db versus filed out version info.
|
||||
if (mailDB->GetCurVersion() != folderInfo->GetDiskVersion())
|
||||
err = eOldSummaryFile;
|
||||
}
|
||||
if (err != eSUCCESS)
|
||||
{
|
||||
mailDB->Close();
|
||||
mailDB = NULL;
|
||||
}
|
||||
}
|
||||
if (err != eSUCCESS || newFile)
|
||||
{
|
||||
// if we couldn't open file, or we have a blank one, and we're supposed
|
||||
// to upgrade, updgrade it.
|
||||
if (newFile && !upgrading) // caller is upgrading, and we have empty summary file,
|
||||
{ // leave db around and open so caller can upgrade it.
|
||||
err = eNoSummaryFile;
|
||||
}
|
||||
else if (err != eSUCCESS)
|
||||
{
|
||||
*pMessageDB = NULL;
|
||||
delete mailDB;
|
||||
}
|
||||
}
|
||||
if (err == eSUCCESS || err == eNoSummaryFile)
|
||||
{
|
||||
*pMessageDB = mailDB;
|
||||
if (m_cacheEnabled)
|
||||
GetDBCache()->Add(mailDB);
|
||||
if (err == eSUCCESS)
|
||||
mailDB->HandleLatered();
|
||||
|
||||
}
|
||||
return(err);
|
||||
nsresult ret = OpenMDB(dbName, create);
|
||||
if (NS_MSG_SUCCEEDED(ret)
|
||||
{
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static nsresult nsMailDatabase::CloneInvalidDBInfoIntoNewDB(nsFilePath &pathName, nsMailDatabase** pMailDB)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsMailDatabase::OnNewPath (nsFilePath &newPath)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsMailDatabase::DeleteMessages(IDArray &messageKeys, ChangeListener *instigator)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int nsMailDatabase::GetCurVersion() {return kMailDBVersion;}
|
||||
|
||||
static nsresult nsMailDatabase::SetFolderInfoValid(nsFilePath &pathname, int num, int numunread)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsMailDatabase::GetFolderName(nsString &folderName)
|
||||
{
|
||||
folderName = m_folderName;
|
||||
}
|
||||
|
||||
nsMailDatabase *nsMailDatabase::GetMailDB() {return this;}
|
||||
|
||||
// The master is needed to find the folder info corresponding to the db.
|
||||
// Perhaps if we passed in the folder info when we opened the db,
|
||||
// we wouldn't need the master. I don't remember why we sometimes need to
|
||||
// get from the db to the folder info, but it's probably something like
|
||||
// some poor soul who has a db pointer but no folderInfo.
|
||||
|
||||
MSG_Master *nsMailDatabase::GetMaster() {return m_master;}
|
||||
void nsMailDatabase::SetMaster(MSG_Master *master) {m_master = master;}
|
||||
|
||||
MSG_FolderInfo *nsMailDatabase::GetFolderInfo()
|
||||
{
|
||||
}
|
||||
|
||||
// for offline imap queued operations
|
||||
// these are in the base mail class (presumably) because offline moves between online and offline
|
||||
// folders can cause these operations to be stored in local mail folders.
|
||||
nsresult nsMailDatabase::ListAllOfflineOpIds(IDArray &outputIds)
|
||||
{
|
||||
}
|
||||
int nsMailDatabase::ListAllOfflineDeletes(IDArray &outputIds)
|
||||
{
|
||||
}
|
||||
nsresult nsMailDatabase::GetOfflineOpForKey(MessageKey opKey, PRBool create, nsOfflineImapOperation **)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsMailDatabase::AddOfflineOp(nsOfflineImapOperation *op)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult DeleteOfflineOp(MessageKey opKey)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult SetSourceMailbox(nsOfflineImapOperation *op, const char *mailbox, MessageKey key)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsMailDatabase::SetSummaryValid(PRBool valid = TRUE)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsMailDatabase::GetIdsWithNoBodies (IDArray &bodylessIds)
|
||||
{
|
||||
}
|
||||
|
@ -84,12 +84,12 @@ nsMsgDatabase::CleanupCache()
|
||||
//----------------------------------------------------------------------
|
||||
// FindInCache
|
||||
//----------------------------------------------------------------------
|
||||
nsMsgDatabase* nsMsgDatabase::FindInCache(const char * pDbName)
|
||||
nsMsgDatabase* nsMsgDatabase::FindInCache(nsFilePath &dbName)
|
||||
{
|
||||
for (int i = 0; i < GetDBCache()->GetSize(); i++)
|
||||
{
|
||||
nsMsgDatabase* pMessageDB = GetDBCache()->GetAt(i);
|
||||
if (pMessageDB->MatchDbName(pDbName))
|
||||
if (pMessageDB->MatchDbName(dbName))
|
||||
{
|
||||
return(pMessageDB);
|
||||
}
|
||||
@ -112,6 +112,12 @@ int nsMsgDatabase::FindInCache(nsMsgDatabase* pMessageDB)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
PRBool nsMsgDatabase::MatchDbName(nsFilePath &dbName) // returns TRUE if they match
|
||||
{
|
||||
// ### we need equality operators for nsFileSpec...
|
||||
return strcmp(dbName, m_dbName);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// RemoveFromCache
|
||||
//----------------------------------------------------------------------
|
||||
@ -135,7 +141,91 @@ void nsMsgDatabase::DumpCache()
|
||||
#endif
|
||||
GetDBCache()->GetAt(i);
|
||||
#ifdef DEBUG_bienvenu
|
||||
XP_Trace("db %s in cache use count = %d\n", pMessageDB->m_dbName, pMessageDB->m_useCount);
|
||||
XP_Trace("db %s in cache use count = %d\n", pMessageDB->m_dbName, pMessageDB->mRefCnt);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
// ref counting methods - if we inherit from nsISupports, we won't need these,
|
||||
// and we can take advantage of the nsISupports ref-counting tracing methods
|
||||
nsrefcnt nsMsgDatabase::AddRef(void)
|
||||
{
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt nsMsgDatabase::Release(void)
|
||||
{
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
if (--mRefCnt == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
/* static */ mdbFactory *nsMsgDatabase::GetMDBFactory()
|
||||
{
|
||||
static mdbFactory *gMDBFactory = NULL;
|
||||
if (!gMDBFactory)
|
||||
{
|
||||
// ### hook up class factory code when it's working
|
||||
// gMDBFactory = new mdbFactory;
|
||||
}
|
||||
return gMDBFactory;
|
||||
}
|
||||
|
||||
nsresult nsMsgDatabase::OpenMDB(const char *dbName, PRBool create)
|
||||
{
|
||||
nsresult ret = NS_OK;
|
||||
mdbFactory *myMDBFactory = GetMDBFactory();
|
||||
if (myMDBFactory)
|
||||
{
|
||||
ret = myMDBFactory->MakeEnv(&m_mdbEnv);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
nsresult nsMsgDatabase::CloseMDB(PRBool commit /* = TRUE */)
|
||||
{
|
||||
--mRefCnt;
|
||||
PR_ASSERT(mRefCnt >= 0);
|
||||
if (mRefCnt == 0)
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
#ifdef DEBUG_bienvenu1
|
||||
if (GetNumInCache() != 0)
|
||||
{
|
||||
XP_Trace("closing %s\n", m_dbName);
|
||||
DumpCache();
|
||||
}
|
||||
XP_Trace("On close - cache used = %lx", CNeoPersist::FCacheUsed);
|
||||
#endif
|
||||
// if this terrifies you, we can make it a static method
|
||||
delete this;
|
||||
return(NS_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(NS_OK);
|
||||
}
|
||||
}
|
||||
|
||||
// force the database to close - this'll flush out anybody holding onto
|
||||
// a database without having a listener!
|
||||
// This is evil in the com world, but there are times we need to delete the file.
|
||||
nsresult nsMsgDatabase::ForceClosed()
|
||||
{
|
||||
nsresult err = NS_OK;
|
||||
|
||||
while (mRefCnt > 0 && NS_SUCCEEDED(err))
|
||||
{
|
||||
int32 saveUseCount = mRefCnt;
|
||||
err = CloseMDB();
|
||||
if (saveUseCount == 1)
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user