mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 22:05:44 +00:00
Bug 1084180 - Refine RemoveEntry - Don't remove only the entry but also its children if they exist. r=dhylands
This commit is contained in:
parent
cbd95cfe18
commit
434dd2043d
@ -171,9 +171,29 @@ void
|
|||||||
MozMtpDatabase::RemoveEntry(MtpObjectHandle aHandle)
|
MozMtpDatabase::RemoveEntry(MtpObjectHandle aHandle)
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mMutex);
|
MutexAutoLock lock(mMutex);
|
||||||
|
if (!IsValidHandle(aHandle)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (aHandle > 0 && aHandle < mDb.Length()) {
|
RefPtr<DbEntry> removedEntry = mDb[aHandle];
|
||||||
mDb[aHandle] = nullptr;
|
mDb[aHandle] = nullptr;
|
||||||
|
MTP_DBG("0x%08x removed", aHandle);
|
||||||
|
// if the entry is not a folder, just return.
|
||||||
|
if (removedEntry->mObjectFormat != MTP_FORMAT_ASSOCIATION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find out and remove the children of aHandle.
|
||||||
|
// Since the index for a directory will always be less than the index of any of its children,
|
||||||
|
// we can remove the entire subtree in one pass.
|
||||||
|
ProtectedDbArray::size_type numEntries = mDb.Length();
|
||||||
|
ProtectedDbArray::index_type entryIndex;
|
||||||
|
for (entryIndex = aHandle+1; entryIndex < numEntries; entryIndex++) {
|
||||||
|
RefPtr<DbEntry> entry = mDb[entryIndex];
|
||||||
|
if (entry && IsValidHandle(entry->mParent) && !mDb[entry->mParent]) {
|
||||||
|
mDb[entryIndex] = nullptr;
|
||||||
|
MTP_DBG("0x%08x removed", aHandle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +226,11 @@ private:
|
|||||||
MatchParentFormat,
|
MatchParentFormat,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool IsValidHandle(MtpObjectHandle aHandle)
|
||||||
|
{
|
||||||
|
return aHandle > 0 && aHandle < mDb.Length();
|
||||||
|
}
|
||||||
|
|
||||||
void AddEntry(DbEntry* aEntry);
|
void AddEntry(DbEntry* aEntry);
|
||||||
void AddEntryAndNotify(DbEntry* aEntr, RefCountedMtpServer* aMtpServer);
|
void AddEntryAndNotify(DbEntry* aEntr, RefCountedMtpServer* aMtpServer);
|
||||||
void DumpEntries(const char* aLabel);
|
void DumpEntries(const char* aLabel);
|
||||||
|
Loading…
Reference in New Issue
Block a user