Skip to content

Commit 20befb1

Browse files
committed
#5655 Fix freeze on purging cef cache
1 parent 9cdd52d commit 20befb1

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

indra/newview/llappviewer.cpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,13 +4564,45 @@ void LLAppViewer::purgeCefStaleCaches()
45644564
LL_PROFILE_ZONE_SCOPED;
45654565
// TODO: we really shouldn't use a hard coded name for the cache folder here...
45664566
const std::string browser_parent_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
4567-
if (LLFile::isdir(browser_parent_cache))
4567+
if (!LLFile::isdir(browser_parent_cache))
45684568
{
4569-
// This is a sledgehammer approach - nukes the cef_cache dir entirely
4570-
// which is then recreated the first time a CEF instance creates an
4571-
// individual cache folder. If we ever decide to retain some folders
4572-
// e.g. Search UI cache - then we will need a more granular approach.
4573-
gDirUtilp->deleteDirAndContents(browser_parent_cache);
4569+
return;
4570+
}
4571+
// We are using a fixed name to not leave stale fodlers
4572+
// around in case something goes wrong on startup.
4573+
const std::string holder_cache_name = browser_parent_cache + "_rename";
4574+
4575+
// Rename the directory first to be able to clean it at our leasure.
4576+
if (LLFile::rename(browser_parent_cache, holder_cache_name) != 0)
4577+
{
4578+
LL_WARNS() << "Failed to rename CEF cache folder from " << browser_parent_cache
4579+
<< " to " << holder_cache_name << LL_ENDL;
4580+
// Shouldn't happen, perhaps viewer crashed on startup?
4581+
// Clean holder cache and retry.
4582+
gDirUtilp->deleteDirAndContents(holder_cache_name);
4583+
4584+
if (LLFile::rename(browser_parent_cache, holder_cache_name) != 0)
4585+
{
4586+
LL_WARNS() << "Failed to rename CEF cache folder from " << browser_parent_cache
4587+
<< " to " << holder_cache_name << " on retry" << LL_ENDL;
4588+
// Shouldn't happen, but if it does, just delete the cache and move on.
4589+
gDirUtilp->deleteDirAndContents(browser_parent_cache);
4590+
return;
4591+
}
4592+
} // renamed
4593+
4594+
if (auto queue = LL::WorkQueue::getInstance("General"))
4595+
{
4596+
queue->post([holder_cache_name]()
4597+
{
4598+
LL_PROFILE_ZONE_NAMED("cef_cache_cleanup");
4599+
gDirUtilp->deleteDirAndContents(holder_cache_name);
4600+
});
4601+
}
4602+
else
4603+
{
4604+
LL_WARNS() << "Failed to get General work queue, deleting CEF cache synchronously" << LL_ENDL;
4605+
gDirUtilp->deleteDirAndContents(holder_cache_name);
45744606
}
45754607
}
45764608

0 commit comments

Comments
 (0)