зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1084180 - Refine RemoveEntry - Don't remove only the entry but also its children if they exist. r=dhylands
This commit is contained in:
Родитель
cbd95cfe18
Коммит
434dd2043d
|
@ -171,9 +171,29 @@ void
|
|||
MozMtpDatabase::RemoveEntry(MtpObjectHandle aHandle)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
if (!IsValidHandle(aHandle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aHandle > 0 && aHandle < mDb.Length()) {
|
||||
mDb[aHandle] = nullptr;
|
||||
RefPtr<DbEntry> removedEntry = mDb[aHandle];
|
||||
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,
|
||||
};
|
||||
|
||||
bool IsValidHandle(MtpObjectHandle aHandle)
|
||||
{
|
||||
return aHandle > 0 && aHandle < mDb.Length();
|
||||
}
|
||||
|
||||
void AddEntry(DbEntry* aEntry);
|
||||
void AddEntryAndNotify(DbEntry* aEntr, RefCountedMtpServer* aMtpServer);
|
||||
void DumpEntries(const char* aLabel);
|
||||
|
|
Загрузка…
Ссылка в новой задаче