Bug 1317117 - call msgStore folder deletion during imap/news empty trash. r=jorgk

Also factors out some common code into nsMSgDBFolder::Delete(), and
makes a couple of incidental changes to try and clarify the
responsibilies of nsIMsgPluggableStore::DeleteFolder().
This commit is contained in:
Ben Campbell 2018-09-14 12:03:52 +12:00
Родитель 33ecc60c8e
Коммит ace6a24948
8 изменённых файлов: 79 добавлений и 141 удалений

Просмотреть файл

@ -51,8 +51,8 @@ interface nsIMsgPluggableStore : nsISupports {
nsIMsgFolder createFolder(in nsIMsgFolder aParent, in AString aFolderName);
/**
* Delete the passed in folder. This is a real delete, not a move
* to the trash folder.
* Delete storage for a folder and its subfolders, if any.
* This is a real delete, not a move to the trash folder.
*
* @param aFolder folder to delete
*/

Просмотреть файл

@ -3614,7 +3614,31 @@ NS_IMETHODIMP nsMsgDBFolder::GetShowDeletedMessages(bool *showDeletedMessages)
NS_IMETHODIMP nsMsgDBFolder::Delete()
{
return NS_OK;
ForceDBClosed();
// Delete the .msf file.
// NOTE: this doesn't remove .msf files in subfolders, but
// both nsMsgBrkMBoxStore::DeleteFolder() and
// nsMsgMaildirStore::DeleteFolder() will remove those .msf files
// as a side-effect of deleting the .sbd directory.
nsCOMPtr<nsIFile> summaryFile;
nsresult rv = GetSummaryFile(getter_AddRefs(summaryFile));
NS_ENSURE_SUCCESS(rv, rv);
bool exists = false;
summaryFile->Exists(&exists);
if (exists) {
rv = summaryFile->Remove(false);
NS_ENSURE_SUCCESS(rv, rv);
}
// Ask the msgStore to delete the actual storage (mbox, maildir or whatever
// else may be supported in future).
nsCOMPtr<nsIMsgPluggableStore> msgStore;
rv = GetMsgStore(getter_AddRefs(msgStore));
NS_ENSURE_SUCCESS(rv, rv);
rv = msgStore->DeleteFolder(this);
return rv;
}
NS_IMETHODIMP nsMsgDBFolder::DeleteSubFolders(nsIArray *folders,

Просмотреть файл

@ -1443,7 +1443,6 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
} // if we fetched an imap server
} // if emptying trash on exit which is done through the account manager.
nsCOMPtr<nsIMsgDatabase> trashDB;
if (WeAreOffline())
{
nsCOMPtr <nsIMsgDatabase> trashDB;
@ -1460,12 +1459,7 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
}
return rv;
}
nsCOMPtr <nsIDBFolderInfo> transferInfo;
rv = trashFolder->GetDBTransferInfo(getter_AddRefs(transferInfo));
rv = trashFolder->Delete(); // delete summary spec
trashFolder->SetDBTransferInfo(transferInfo);
trashFolder->SetSizeOnDisk(0);
nsCOMPtr<nsIImapService> imapService = do_GetService(NS_IMAPSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -1511,7 +1505,17 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
}
}
// The trash folder has effectively been deleted
nsCOMPtr <nsIDBFolderInfo> transferInfo;
rv = trashFolder->GetDBTransferInfo(getter_AddRefs(transferInfo));
NS_ENSURE_SUCCESS(rv, rv);
// Bulk-delete all the messages by deleting the msf file and storage.
// This is a little kludgy.
rv = trashFolder->Delete();
NS_ENSURE_SUCCESS(rv, rv);
trashFolder->SetDBTransferInfo(transferInfo);
trashFolder->SetSizeOnDisk(0);
// The trash folder has effectively been deleted.
nsCOMPtr<nsIMsgFolderNotificationService> notifier(do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
if (notifier)
notifier->NotifyFolderDeleted(trashFolder);
@ -1523,41 +1527,9 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
NS_IMETHODIMP nsImapMailFolder::Delete()
{
nsresult rv;
if (!mDatabase)
{
// Check if anyone has this db open. If so, do a force closed.
nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
msgDBService->CachedDBForFolder(this, getter_AddRefs(mDatabase));
}
if (mDatabase)
{
mDatabase->ForceClosed();
mDatabase = nullptr;
}
nsresult rv = nsMsgDBFolder::Delete();
nsCOMPtr<nsIFile> path;
rv = GetFilePath(getter_AddRefs(path));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIFile> summaryLocation;
rv = GetSummaryFileLocation(path, getter_AddRefs(summaryLocation));
if (NS_SUCCEEDED(rv))
{
bool exists = false;
rv = summaryLocation->Exists(&exists);
if (NS_SUCCEEDED(rv) && exists)
{
rv = summaryLocation->Remove(false);
if (NS_FAILED(rv))
NS_WARNING("failed to remove imap summary file");
}
}
}
if (mPath)
mPath->Remove(false);
// should notify nsIMsgFolderListeners about the folder getting deleted...
// Should notify nsIMsgFolderListeners about the folder getting deleted?
return rv;
}

Просмотреть файл

@ -643,8 +643,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EmptyTrash(nsIMsgWindow *msgWindow,
if (NS_SUCCEEDED(rv))
{
uint32_t flags;
nsCString trashUri;
trashFolder->GetURI(trashUri);
trashFolder->GetFlags(&flags);
int32_t totalMessages = 0;
rv = trashFolder->GetTotalMessages(true, &totalMessages);
@ -740,43 +738,6 @@ nsresult nsMsgLocalMailFolder::IsChildOfTrash(bool *result)
return rv;
}
NS_IMETHODIMP nsMsgLocalMailFolder::Delete()
{
nsresult rv;
nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
msgDBService->CachedDBForFolder(this, getter_AddRefs(mDatabase));
if (mDatabase)
{
mDatabase->ForceClosed();
mDatabase = nullptr;
}
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMsgPluggableStore> msgStore;
rv = server->GetMsgStore(getter_AddRefs(msgStore));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsIFile> summaryFile;
rv = GetSummaryFile(getter_AddRefs(summaryFile));
NS_ENSURE_SUCCESS(rv, rv);
//Clean up .sbd folder if it exists.
// Remove summary file.
rv = summaryFile->Remove(false);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Could not delete msg summary file");
rv = msgStore->DeleteFolder(this);
if (rv == NS_ERROR_FILE_NOT_FOUND ||
rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
rv = NS_OK; // virtual folders do not have a msgStore file
return rv;
}
NS_IMETHODIMP nsMsgLocalMailFolder::DeleteSubFolders(nsIArray *folders, nsIMsgWindow *msgWindow)
{
nsresult rv;

Просмотреть файл

@ -125,7 +125,6 @@ public:
NS_IMETHOD Compact(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow) override;
NS_IMETHOD CompactAll(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow, bool aCompactOfflineAlso) override;
NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener) override;
NS_IMETHOD Delete () override;
NS_IMETHOD DeleteSubFolders(nsIArray *folders, nsIMsgWindow *msgWindow) override;
NS_IMETHOD CreateStorageIfMissing(nsIUrlListener* urlListener) override;
NS_IMETHOD Rename (const nsAString& aNewName, nsIMsgWindow *msgWindow) override;

Просмотреть файл

@ -300,26 +300,30 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::SetSummaryFileValid(nsIMsgFolder *aFolder,
NS_IMETHODIMP nsMsgBrkMBoxStore::DeleteFolder(nsIMsgFolder *aFolder)
{
NS_ENSURE_ARG_POINTER(aFolder);
//Delete mailbox
bool exists;
// Delete mbox file.
nsCOMPtr<nsIFile> pathFile;
nsresult rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
NS_ENSURE_SUCCESS(rv, rv);
pathFile->Remove(false);
bool isDirectory = false;
pathFile->IsDirectory(&isDirectory);
if (!isDirectory)
{
nsAutoString leafName;
pathFile->GetLeafName(leafName);
leafName.AppendLiteral(FOLDER_SUFFIX);
pathFile->SetLeafName(leafName);
exists = false;
pathFile->Exists(&exists);
if (exists) {
rv = pathFile->Remove(false);
NS_ENSURE_SUCCESS(rv, rv);
}
isDirectory = false;
pathFile->IsDirectory(&isDirectory);
//If this is a directory, then remove it.
return isDirectory ? pathFile->Remove(true) : NS_OK;
// Delete any subfolders (.sbd-suffixed directories).
AddDirectorySeparator(pathFile);
exists = false;
pathFile->Exists(&exists);
if (exists) {
rv = pathFile->Remove(true);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
NS_IMETHODIMP nsMsgBrkMBoxStore::RenameFolder(nsIMsgFolder *aFolder,

Просмотреть файл

@ -321,19 +321,30 @@ NS_IMETHODIMP nsMsgMaildirStore::SetSummaryFileValid(nsIMsgFolder *aFolder,
NS_IMETHODIMP nsMsgMaildirStore::DeleteFolder(nsIMsgFolder *aFolder)
{
NS_ENSURE_ARG_POINTER(aFolder);
bool exists;
// Delete Maildir structure
// Delete the Maildir itself.
nsCOMPtr<nsIFile> pathFile;
nsresult rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = pathFile->Remove(true); // recursive
AddDirectorySeparator(pathFile);
bool exists;
exists = false;
pathFile->Exists(&exists);
if (exists)
pathFile->Remove(true);
return rv;
if (exists) {
rv = pathFile->Remove(true);
NS_ENSURE_SUCCESS(rv, rv);
}
// Delete any subfolders (.sbd-suffixed directories).
AddDirectorySeparator(pathFile);
exists = false;
pathFile->Exists(&exists);
if (exists) {
rv = pathFile->Remove(true);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
NS_IMETHODIMP nsMsgMaildirStore::RenameFolder(nsIMsgFolder *aFolder,

Просмотреть файл

@ -486,41 +486,8 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateSubfolder(const nsAString& newsgroupName,
NS_IMETHODIMP nsMsgNewsFolder::Delete()
{
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
{
mDatabase->ForceClosed();
mDatabase = nullptr;
}
nsCOMPtr<nsIFile> folderPath;
rv = GetFilePath(getter_AddRefs(folderPath));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIFile> summaryPath;
rv = GetSummaryFileLocation(folderPath, getter_AddRefs(summaryPath));
if (NS_SUCCEEDED(rv))
{
bool exists = false;
rv = folderPath->Exists(&exists);
if (NS_SUCCEEDED(rv) && exists)
rv = folderPath->Remove(false);
if (NS_FAILED(rv))
NS_WARNING("Failed to remove News Folder");
rv = summaryPath->Exists(&exists);
if (NS_SUCCEEDED(rv) && exists)
rv = summaryPath->Remove(false);
if (NS_FAILED(rv))
NS_WARNING("Failed to remove News Folder Summary File");
}
}
nsresult rv = nsMsgDBFolder::Delete();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsINntpIncomingServer> nntpServer;
rv = GetNntpServer(getter_AddRefs(nntpServer));