From 8eec786badeb4fbba243868c49f7db5188e38e78 Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Wed, 2 Oct 2024 13:12:57 +0300 Subject: [PATCH] Bug 1921899 - Move nsMsgDBFolder::CreateFileForDB() into nsImapMailFolder. r=mkmelin nsImapMailFolder is the sole caller of CreateFileForDB(). Differential Revision: https://phabricator.services.mozilla.com/D224176 --HG-- extra : rebase_source : c0ef4d8feda4da9124469ea5907457ccaa9c4cc2 --- mailnews/base/src/nsMsgDBFolder.cpp | 40 -------------------------- mailnews/base/src/nsMsgDBFolder.h | 2 -- mailnews/imap/src/nsImapMailFolder.cpp | 40 ++++++++++++++++++++++++++ mailnews/imap/src/nsImapMailFolder.h | 3 +- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/mailnews/base/src/nsMsgDBFolder.cpp b/mailnews/base/src/nsMsgDBFolder.cpp index 44cdb1c0e1..392a5e2856 100644 --- a/mailnews/base/src/nsMsgDBFolder.cpp +++ b/mailnews/base/src/nsMsgDBFolder.cpp @@ -782,46 +782,6 @@ nsMsgDBFolder::GetMsgInputStream(nsIMsgDBHdr* aMsgHdr, return NS_OK; } -// path coming in is the root path without the leaf name, -// on the way out, it's the whole path. -nsresult nsMsgDBFolder::CreateFileForDB(const nsAString& userLeafName, - nsIFile* path, nsIFile** dbFile) { - NS_ENSURE_ARG_POINTER(dbFile); - - nsAutoString proposedDBName(userLeafName); - NS_MsgHashIfNecessary(proposedDBName); - - // (note, the caller of this will be using the dbFile to call db->Open() - // will turn the path into summary file path, and append the ".msf" extension) - // - // we want db->Open() to create a new summary file - // so we have to jump through some hoops to make sure the .msf it will - // create is unique. now that we've got the "safe" proposedDBName, - // we append ".msf" to see if the file exists. if so, we make the name - // unique and then string off the ".msf" so that we pass the right thing - // into Open(). this isn't ideal, since this is not atomic - // but it will make do. - nsresult rv; - nsCOMPtr dbPath = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - dbPath->InitWithFile(path); - proposedDBName.AppendLiteral(SUMMARY_SUFFIX); - dbPath->Append(proposedDBName); - bool exists; - dbPath->Exists(&exists); - if (exists) { - rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); - NS_ENSURE_SUCCESS(rv, rv); - dbPath->GetLeafName(proposedDBName); - } - // now, take the ".msf" off - proposedDBName.SetLength(proposedDBName.Length() - SUMMARY_SUFFIX_LENGTH); - dbPath->SetLeafName(proposedDBName); - - dbPath.forget(dbFile); - return NS_OK; -} - NS_IMETHODIMP nsMsgDBFolder::GetMsgDatabase(nsIMsgDatabase** aMsgDatabase) { NS_ENSURE_ARG_POINTER(aMsgDatabase); diff --git a/mailnews/base/src/nsMsgDBFolder.h b/mailnews/base/src/nsMsgDBFolder.h index 9b9ce9c7e9..f7e38271a1 100644 --- a/mailnews/base/src/nsMsgDBFolder.h +++ b/mailnews/base/src/nsMsgDBFolder.h @@ -148,8 +148,6 @@ class nsMsgDBFolder : public nsSupportsWeakReference, nsresult CheckWithNewMessagesStatus(bool messageAdded); void UpdateNewMessages(); nsresult OnHdrAddedOrDeleted(nsIMsgDBHdr* hdrChanged, bool added); - nsresult CreateFileForDB(const nsAString& userLeafName, nsIFile* baseDir, - nsIFile** dbFile); nsresult GetFolderCacheKey(nsIFile** aFile); nsresult GetFolderCacheElemFromFile(nsIFile* file, diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 309118800e..cc4aec5aa2 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -865,6 +865,46 @@ NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const nsAString& folderName, return imapService->CreateFolder(this, folderName, this, getter_AddRefs(url)); } +// Path coming in is the root path without the leaf name, +// on the way out, it's the whole path. +nsresult nsImapMailFolder::CreateFileForDB(const nsAString& userLeafName, + nsIFile* path, nsIFile** dbFile) { + NS_ENSURE_ARG_POINTER(dbFile); + + nsAutoString proposedDBName(userLeafName); + NS_MsgHashIfNecessary(proposedDBName); + + // (note, the caller of this will be using the dbFile to call db->Open() + // will turn the path into summary file path, and append the ".msf" extension) + // + // we want db->Open() to create a new summary file + // so we have to jump through some hoops to make sure the .msf it will + // create is unique. now that we've got the "safe" proposedDBName, + // we append ".msf" to see if the file exists. if so, we make the name + // unique and then string off the ".msf" so that we pass the right thing + // into Open(). this isn't ideal, since this is not atomic + // but it will make do. + nsresult rv; + nsCOMPtr dbPath = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + dbPath->InitWithFile(path); + proposedDBName.AppendLiteral(SUMMARY_SUFFIX); + dbPath->Append(proposedDBName); + bool exists; + dbPath->Exists(&exists); + if (exists) { + rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); + NS_ENSURE_SUCCESS(rv, rv); + dbPath->GetLeafName(proposedDBName); + } + // now, take the ".msf" off + proposedDBName.SetLength(proposedDBName.Length() - SUMMARY_SUFFIX_LENGTH); + dbPath->SetLeafName(proposedDBName); + + dbPath.forget(dbFile); + return NS_OK; +} + NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo( const nsACString& folderName, char hierarchyDelimiter, int32_t flags, bool suppressNotification) { diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index 6fb327238a..cafe12595c 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -371,7 +371,8 @@ class nsImapMailFolder : public nsMsgDBFolder, protected: virtual ~nsImapMailFolder(); // Helper methods - + nsresult CreateFileForDB(const nsAString& userLeafName, nsIFile* baseDir, + nsIFile** dbFile); nsresult ExpungeAndCompact(nsIUrlListener* aListener, nsIMsgWindow* aMsgWindow); void FindKeysToAdd(const nsTArray& existingKeys,