MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / resolveEntry

Method resolveEntry

launcher/net/HttpMetaCache.cpp:83–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString expected_etag) -> MetaEntryPtr
84{
85 auto entry = getEntry(base, resource_path);
86 // it's not present? generate a default stale entry
87 if (!entry) {
88 return staleEntry(base, resource_path);
89 }
90
91 auto& selected_base = m_entries[base];
92 QString real_path = FS::PathCombine(selected_base.base_path, resource_path);
93 QFileInfo finfo(real_path);
94
95 // is the file really there? if not -> stale
96 if (!finfo.isFile() || !finfo.isReadable()) {
97 // if the file doesn't exist, we disown the entry
98 selected_base.entry_list.remove(resource_path);
99 return staleEntry(base, resource_path);
100 }
101
102 if (!expected_etag.isEmpty() && expected_etag != entry->etag) {
103 // if the etag doesn't match expected, we disown the entry
104 selected_base.entry_list.remove(resource_path);
105 return staleEntry(base, resource_path);
106 }
107
108 // if the file changed, check md5sum
109 qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
110 if (file_last_changed != entry->local_changed_timestamp) {
111 QFile input(real_path);
112 input.open(QIODevice::ReadOnly);
113 QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5).toHex().constData();
114 if (entry->md5sum != md5sum) {
115 selected_base.entry_list.remove(resource_path);
116 return staleEntry(base, resource_path);
117 }
118
119 // md5sums matched... keep entry and save the new state to file
120 entry->local_changed_timestamp = file_last_changed;
121 SaveEventually();
122 }
123
124 // Get rid of old entries, to prevent cache problems
125 auto current_time = QDateTime::currentSecsSinceEpoch();
126 if (entry->isExpired(current_time - ( file_last_changed / 1000 ))) {
127 qWarning() << "Removing cache entry because of old age!";
128 selected_base.entry_list.remove(resource_path);
129 return staleEntry(base, resource_path);
130 }
131
132 // entry passed all the checks we cared about.
133 entry->basePath = getBasePath(base);
134 return entry;
135}
136
137auto HttpMetaCache::updateEntry(MetaEntryPtr stale_entry) -> bool
138{

Callers 15

executeTaskMethod · 0.80
getFaceFromCacheFunction · 0.80
installConfigsMethod · 0.80
downloadModsMethod · 0.80
downloadPackMethod · 0.80
executeTaskMethod · 0.80
downloadPackMethod · 0.80
downloadIndexMethod · 0.80
downloadTranslationMethod · 0.80
getLogoMethod · 0.80
requestLogoMethod · 0.80
getLogoMethod · 0.80

Calls 6

PathCombineFunction · 0.85
hashFunction · 0.85
isEmptyMethod · 0.80
openMethod · 0.80
isExpiredMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected