When removing folders, make sure to remove all of the items in the folder, and recursively remove any subfolders. Bug 318176, r=brettw.

git-svn-id: svn://10.0.0.236/trunk@185453 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bryner%brianryner.com
2005-11-30 18:42:29 +00:00
parent dfd79f9b29
commit b18e6bf6f7
2 changed files with 34 additions and 3 deletions

View File

@@ -217,6 +217,11 @@ nsNavBookmarks::Init()
NS_NAMED_LITERAL_CSTRING(orderByPosition, " ORDER BY a.position");
// Select only folder children of a given folder (unsorted)
rv = dbConn->CreateStatement(selectFolderChildren,
getter_AddRefs(mDBGetFolderChildren));
NS_ENSURE_SUCCESS(rv, rv);
// Select all children of a given folder, sorted by position
rv = dbConn->CreateStatement(selectItemChildren +
NS_LITERAL_CSTRING(" UNION ALL ") +
@@ -583,24 +588,49 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFolder)
index = statement->AsInt32(1);
}
buffer.AssignLiteral("DELETE FROM moz_bookmarks_containers WHERE id = ");
// Now locate all of the folder children, so we can recursively remove them.
nsTArray<PRInt64> folderChildren;
{
mozStorageStatementScoper scope(mDBGetFolderChildren);
rv = mDBGetChildren->BindInt64Parameter(0, aFolder);
NS_ENSURE_SUCCESS(rv, rv);
PRBool more;
while (NS_SUCCEEDED(rv = mDBGetChildren->ExecuteStep(&more)) && more) {
folderChildren.AppendElement(mDBGetChildren->AsInt64(kGetChildrenIndex_FolderChild));
}
}
for (PRUint32 i = 0; i < folderChildren.Length(); ++i) {
RemoveFolder(folderChildren[i]);
}
// Now remove the remaining items
buffer.AssignLiteral("DELETE FROM moz_bookmarks_assoc WHERE parent = ");
buffer.AppendInt(aFolder);
rv = dbConn->ExecuteSimpleSQL(buffer);
NS_ENSURE_SUCCESS(rv, rv);
// Remove the folder from its parent
buffer.AssignLiteral("DELETE FROM moz_bookmarks_assoc WHERE folder_child = ");
buffer.AppendInt(aFolder);
rv = dbConn->ExecuteSimpleSQL(buffer);
NS_ENSURE_SUCCESS(rv, rv);
// And remove the folder from the folder table
buffer.AssignLiteral("DELETE FROM moz_bookmarks_containers WHERE id = ");
buffer.AppendInt(aFolder);
rv = dbConn->ExecuteSimpleSQL(buffer);
NS_ENSURE_SUCCESS(rv, rv);
rv = AdjustIndices(parent, index + 1, PR_INT32_MAX, -1);
NS_ENSURE_SUCCESS(rv, rv);
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
for (PRInt32 i = 0; i < mObservers.Count(); ++i) {
mObservers[i]->OnFolderRemoved(aFolder, parent, index);
for (PRInt32 j = 0; j < mObservers.Count(); ++j) {
mObservers[j]->OnFolderRemoved(aFolder, parent, index);
}
return NS_OK;

View File

@@ -98,6 +98,7 @@ private:
static const PRInt32 kGetFolderInfoIndex_Title;
nsCOMPtr<mozIStorageStatement> mDBGetChildren; // kGetInfoIndex_* results + kGetChildrenIndex_* results
nsCOMPtr<mozIStorageStatement> mDBGetFolderChildren;
static const PRInt32 kGetChildrenIndex_Position;
static const PRInt32 kGetChildrenIndex_ItemChild;
static const PRInt32 kGetChildrenIndex_FolderChild;