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

Method resolveEntry

launcher/net/HttpMetaCache.cpp:85–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 15

downloadFromUrlMethod · 0.80
installConfigsMethod · 0.80
downloadModsMethod · 0.80
downloadPackMethod · 0.80
executeTaskMethod · 0.80
downloadIndexMethod · 0.80
downloadTranslationMethod · 0.80
executeTaskMethod · 0.80
processURLsMethod · 0.80
getIconMethod · 0.80
getLogoMethod · 0.80
requestLogoMethod · 0.80

Calls 10

RemoveInvalidPathCharsFunction · 0.85
PathCombineFunction · 0.85
isFileMethod · 0.80
errorStringMethod · 0.80
readAllMethod · 0.80
isExpiredMethod · 0.80
hashFunction · 0.50
removeMethod · 0.45
isEmptyMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected