Go to Desktop instead of showing an error if a parent folder is deleted in the middle of files navigation

This commit is contained in:
David Capello 2022-05-24 09:06:32 -03:00
parent c457f1680a
commit 0e9001fbd3

View File

@ -961,7 +961,7 @@ static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_
return nullptr;
// new file-item
FileItem* fileitem = new FileItem(nullptr);
auto fileitem = std::make_unique<FileItem>(nullptr);
fileitem->m_fullpidl = clone_pidl(fullpidl);
{
@ -974,25 +974,25 @@ static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_
free_pidl(parent_fullpidl);
// The parent folder is sometimes deleted for some reasons. In
// that case, m_parent becomes nullptr, which can causes crash.
if (fileitem->m_parent == nullptr) {
throw std::runtime_error(
"Unexpected file system change. Please check the file.");
}
// that case, m_parent becomes nullptr, so we cannot use it
// anymore. Here we just return nullptr to indicate that the item
// doesn't exist anymore.
if (fileitem->m_parent == nullptr)
return nullptr;
// Get specific pidl attributes
if (fileitem->m_pidl &&
fileitem->m_parent) {
attrib = get_pidl_attrib(fileitem, attrib);
attrib = get_pidl_attrib(fileitem.get(), attrib);
}
}
update_by_pidl(fileitem, attrib);
put_fileitem(fileitem);
update_by_pidl(fileitem.get(), attrib);
put_fileitem(fileitem.get());
//LOG("FS: fileitem %p created %s with parent %p\n", fileitem, fileitem->keyname.c_str(), fileitem->parent);
return fileitem;
return fileitem.release();
}
// Inserts the fileitem in the hash map of items.