diskmanager: ensure file is deleted and ignore accesses from non-existent hashes

This commit is contained in:
itsmattkc
2021-03-08 15:37:29 +11:00
parent 97dd84c68b
commit 3ac1503a32
+7 -1
View File
@@ -224,6 +224,10 @@ bool DiskCacheFolder::ClearCache()
void DiskCacheFolder::Accessed(const QByteArray &hash)
{
if (!disk_data_.contains(hash)) {
return;
}
disk_data_[hash].access_time = QDateTime::currentMSecsSinceEpoch();
}
@@ -306,7 +310,7 @@ QByteArray DiskCacheFolder::DeleteLeastRecent()
auto hash_to_delete = disk_data_.begin();
for (auto it=disk_data_.begin()+1; it!=disk_data_.end(); it++) {
if (hash_to_delete.value().access_time > it.value().access_time) {
if (it->access_time < hash_to_delete->access_time) {
hash_to_delete = it;
}
}
@@ -315,6 +319,8 @@ QByteArray DiskCacheFolder::DeleteLeastRecent()
HashTime ht = hash_to_delete.value();
disk_data_.erase(hash_to_delete);
QFile::remove(ht.file_name);
consumption_ -= ht.file_size;
return hash;