Prefix member variables in HttpMetaCache
MSVC warns about shadowing variables Signed-off-by: TheLastRar <TheLastRar@users.noreply.github.com>
This commit is contained in:
parent
64576f4c4c
commit
472d931b4b
@ -47,7 +47,7 @@
|
|||||||
auto MetaEntry::getFullPath() -> QString
|
auto MetaEntry::getFullPath() -> QString
|
||||||
{
|
{
|
||||||
// FIXME: make local?
|
// FIXME: make local?
|
||||||
return FS::PathCombine(basePath, relativePath);
|
return FS::PathCombine(m_basePath, m_relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpMetaCache::HttpMetaCache(QString path) : QObject(), m_index_file(path)
|
HttpMetaCache::HttpMetaCache(QString path) : QObject(), m_index_file(path)
|
||||||
@ -99,7 +99,7 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex
|
|||||||
return staleEntry(base, resource_path);
|
return staleEntry(base, resource_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expected_etag.isEmpty() && expected_etag != entry->etag) {
|
if (!expected_etag.isEmpty() && expected_etag != entry->m_etag) {
|
||||||
// if the etag doesn't match expected, we disown the entry
|
// if the etag doesn't match expected, we disown the entry
|
||||||
selected_base.entry_list.remove(resource_path);
|
selected_base.entry_list.remove(resource_path);
|
||||||
return staleEntry(base, resource_path);
|
return staleEntry(base, resource_path);
|
||||||
@ -107,17 +107,17 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex
|
|||||||
|
|
||||||
// if the file changed, check md5sum
|
// if the file changed, check md5sum
|
||||||
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
|
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
|
||||||
if (file_last_changed != entry->local_changed_timestamp) {
|
if (file_last_changed != entry->m_local_changed_timestamp) {
|
||||||
QFile input(real_path);
|
QFile input(real_path);
|
||||||
input.open(QIODevice::ReadOnly);
|
input.open(QIODevice::ReadOnly);
|
||||||
QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5).toHex().constData();
|
QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5).toHex().constData();
|
||||||
if (entry->md5sum != md5sum) {
|
if (entry->m_md5sum != md5sum) {
|
||||||
selected_base.entry_list.remove(resource_path);
|
selected_base.entry_list.remove(resource_path);
|
||||||
return staleEntry(base, resource_path);
|
return staleEntry(base, resource_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// md5sums matched... keep entry and save the new state to file
|
// md5sums matched... keep entry and save the new state to file
|
||||||
entry->local_changed_timestamp = file_last_changed;
|
entry->m_local_changed_timestamp = file_last_changed;
|
||||||
SaveEventually();
|
SaveEventually();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,23 +130,23 @@ auto HttpMetaCache::resolveEntry(QString base, QString resource_path, QString ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// entry passed all the checks we cared about.
|
// entry passed all the checks we cared about.
|
||||||
entry->basePath = getBasePath(base);
|
entry->m_basePath = getBasePath(base);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto HttpMetaCache::updateEntry(MetaEntryPtr stale_entry) -> bool
|
auto HttpMetaCache::updateEntry(MetaEntryPtr stale_entry) -> bool
|
||||||
{
|
{
|
||||||
if (!m_entries.contains(stale_entry->baseId)) {
|
if (!m_entries.contains(stale_entry->m_baseId)) {
|
||||||
qCritical() << "Cannot add entry with unknown base: " << stale_entry->baseId.toLocal8Bit();
|
qCritical() << "Cannot add entry with unknown base: " << stale_entry->m_baseId.toLocal8Bit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stale_entry->stale) {
|
if (stale_entry->m_stale) {
|
||||||
qCritical() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit();
|
qCritical() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_entries[stale_entry->baseId].entry_list[stale_entry->relativePath] = stale_entry;
|
m_entries[stale_entry->m_baseId].entry_list[stale_entry->m_relativePath] = stale_entry;
|
||||||
SaveEventually();
|
SaveEventually();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -157,7 +157,7 @@ auto HttpMetaCache::evictEntry(MetaEntryPtr entry) -> bool
|
|||||||
if (!entry)
|
if (!entry)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
entry->stale = true;
|
entry->m_stale = true;
|
||||||
SaveEventually();
|
SaveEventually();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ void HttpMetaCache::evictAll()
|
|||||||
qDebug() << "Evicting base" << base;
|
qDebug() << "Evicting base" << base;
|
||||||
for (MetaEntryPtr entry : map.entry_list) {
|
for (MetaEntryPtr entry : map.entry_list) {
|
||||||
if (!evictEntry(entry))
|
if (!evictEntry(entry))
|
||||||
qWarning() << "Unexpected missing cache entry" << entry->basePath;
|
qWarning() << "Unexpected missing cache entry" << entry->m_basePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,10 +177,10 @@ void HttpMetaCache::evictAll()
|
|||||||
auto HttpMetaCache::staleEntry(QString base, QString resource_path) -> MetaEntryPtr
|
auto HttpMetaCache::staleEntry(QString base, QString resource_path) -> MetaEntryPtr
|
||||||
{
|
{
|
||||||
auto foo = new MetaEntry();
|
auto foo = new MetaEntry();
|
||||||
foo->baseId = base;
|
foo->m_baseId = base;
|
||||||
foo->basePath = getBasePath(base);
|
foo->m_basePath = getBasePath(base);
|
||||||
foo->relativePath = resource_path;
|
foo->m_relativePath = resource_path;
|
||||||
foo->stale = true;
|
foo->m_stale = true;
|
||||||
|
|
||||||
return MetaEntryPtr(foo);
|
return MetaEntryPtr(foo);
|
||||||
}
|
}
|
||||||
@ -235,23 +235,23 @@ void HttpMetaCache::Load()
|
|||||||
auto& entrymap = m_entries[base];
|
auto& entrymap = m_entries[base];
|
||||||
|
|
||||||
auto foo = new MetaEntry();
|
auto foo = new MetaEntry();
|
||||||
foo->baseId = base;
|
foo->m_baseId = base;
|
||||||
foo->relativePath = Json::ensureString(element_obj, "path");
|
foo->m_relativePath = Json::ensureString(element_obj, "path");
|
||||||
foo->md5sum = Json::ensureString(element_obj, "md5sum");
|
foo->m_md5sum = Json::ensureString(element_obj, "md5sum");
|
||||||
foo->etag = Json::ensureString(element_obj, "etag");
|
foo->m_etag = Json::ensureString(element_obj, "etag");
|
||||||
foo->local_changed_timestamp = Json::ensureDouble(element_obj, "last_changed_timestamp");
|
foo->m_local_changed_timestamp = Json::ensureDouble(element_obj, "last_changed_timestamp");
|
||||||
foo->remote_changed_timestamp = Json::ensureString(element_obj, "remote_changed_timestamp");
|
foo->m_remote_changed_timestamp = Json::ensureString(element_obj, "remote_changed_timestamp");
|
||||||
|
|
||||||
foo->makeEternal(Json::ensureBoolean(element_obj, (const QString)QStringLiteral("eternal"), false));
|
foo->makeEternal(Json::ensureBoolean(element_obj, (const QString)QStringLiteral("eternal"), false));
|
||||||
if (!foo->isEternal()) {
|
if (!foo->isEternal()) {
|
||||||
foo->current_age = Json::ensureDouble(element_obj, "current_age");
|
foo->m_current_age = Json::ensureDouble(element_obj, "current_age");
|
||||||
foo->max_age = Json::ensureDouble(element_obj, "max_age");
|
foo->m_max_age = Json::ensureDouble(element_obj, "max_age");
|
||||||
}
|
}
|
||||||
|
|
||||||
// presumed innocent until closer examination
|
// presumed innocent until closer examination
|
||||||
foo->stale = false;
|
foo->m_stale = false;
|
||||||
|
|
||||||
entrymap.entry_list[foo->relativePath] = MetaEntryPtr(foo);
|
entrymap.entry_list[foo->m_relativePath] = MetaEntryPtr(foo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,23 +276,23 @@ void HttpMetaCache::SaveNow()
|
|||||||
for (auto group : m_entries) {
|
for (auto group : m_entries) {
|
||||||
for (auto entry : group.entry_list) {
|
for (auto entry : group.entry_list) {
|
||||||
// do not save stale entries. they are dead.
|
// do not save stale entries. they are dead.
|
||||||
if (entry->stale) {
|
if (entry->m_stale) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject entryObj;
|
QJsonObject entryObj;
|
||||||
Json::writeString(entryObj, "base", entry->baseId);
|
Json::writeString(entryObj, "base", entry->m_baseId);
|
||||||
Json::writeString(entryObj, "path", entry->relativePath);
|
Json::writeString(entryObj, "path", entry->m_relativePath);
|
||||||
Json::writeString(entryObj, "md5sum", entry->md5sum);
|
Json::writeString(entryObj, "md5sum", entry->m_md5sum);
|
||||||
Json::writeString(entryObj, "etag", entry->etag);
|
Json::writeString(entryObj, "etag", entry->m_etag);
|
||||||
entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->local_changed_timestamp)));
|
entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->m_local_changed_timestamp)));
|
||||||
if (!entry->remote_changed_timestamp.isEmpty())
|
if (!entry->m_remote_changed_timestamp.isEmpty())
|
||||||
entryObj.insert("remote_changed_timestamp", QJsonValue(entry->remote_changed_timestamp));
|
entryObj.insert("remote_changed_timestamp", QJsonValue(entry->m_remote_changed_timestamp));
|
||||||
if (entry->isEternal()) {
|
if (entry->isEternal()) {
|
||||||
entryObj.insert("eternal", true);
|
entryObj.insert("eternal", true);
|
||||||
} else {
|
} else {
|
||||||
entryObj.insert("current_age", QJsonValue(double(entry->current_age)));
|
entryObj.insert("current_age", QJsonValue(double(entry->m_current_age)));
|
||||||
entryObj.insert("max_age", QJsonValue(double(entry->max_age)));
|
entryObj.insert("max_age", QJsonValue(double(entry->m_max_age)));
|
||||||
}
|
}
|
||||||
entriesArr.append(entryObj);
|
entriesArr.append(entryObj);
|
||||||
}
|
}
|
||||||
|
@ -49,47 +49,47 @@ class MetaEntry {
|
|||||||
MetaEntry() = default;
|
MetaEntry() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
auto isStale() -> bool { return stale; }
|
auto isStale() -> bool { return m_stale; }
|
||||||
void setStale(bool stale) { this->stale = stale; }
|
void setStale(bool stale) { m_stale = stale; }
|
||||||
|
|
||||||
auto getFullPath() -> QString;
|
auto getFullPath() -> QString;
|
||||||
|
|
||||||
auto getRemoteChangedTimestamp() -> QString { return remote_changed_timestamp; }
|
auto getRemoteChangedTimestamp() -> QString { return m_remote_changed_timestamp; }
|
||||||
void setRemoteChangedTimestamp(QString remote_changed_timestamp) { this->remote_changed_timestamp = remote_changed_timestamp; }
|
void setRemoteChangedTimestamp(QString remote_changed_timestamp) { m_remote_changed_timestamp = remote_changed_timestamp; }
|
||||||
void setLocalChangedTimestamp(qint64 timestamp) { local_changed_timestamp = timestamp; }
|
void setLocalChangedTimestamp(qint64 timestamp) { m_local_changed_timestamp = timestamp; }
|
||||||
|
|
||||||
auto getETag() -> QString { return etag; }
|
auto getETag() -> QString { return m_etag; }
|
||||||
void setETag(QString etag) { this->etag = etag; }
|
void setETag(QString etag) { m_etag = etag; }
|
||||||
|
|
||||||
auto getMD5Sum() -> QString { return md5sum; }
|
auto getMD5Sum() -> QString { return m_md5sum; }
|
||||||
void setMD5Sum(QString md5sum) { this->md5sum = md5sum; }
|
void setMD5Sum(QString md5sum) { m_md5sum = md5sum; }
|
||||||
|
|
||||||
/* Whether the entry expires after some time (false) or not (true). */
|
/* Whether the entry expires after some time (false) or not (true). */
|
||||||
void makeEternal(bool eternal) { is_eternal = eternal; }
|
void makeEternal(bool eternal) { m_is_eternal = eternal; }
|
||||||
[[nodiscard]] bool isEternal() const { return is_eternal; }
|
[[nodiscard]] bool isEternal() const { return m_is_eternal; }
|
||||||
|
|
||||||
auto getCurrentAge() -> qint64 { return current_age; }
|
auto getCurrentAge() -> qint64 { return m_current_age; }
|
||||||
void setCurrentAge(qint64 age) { current_age = age; }
|
void setCurrentAge(qint64 age) { m_current_age = age; }
|
||||||
|
|
||||||
auto getMaximumAge() -> qint64 { return max_age; }
|
auto getMaximumAge() -> qint64 { return m_max_age; }
|
||||||
void setMaximumAge(qint64 age) { max_age = age; }
|
void setMaximumAge(qint64 age) { m_max_age = age; }
|
||||||
|
|
||||||
bool isExpired(qint64 offset) { return !is_eternal && (current_age >= max_age - offset); };
|
bool isExpired(qint64 offset) { return !m_is_eternal && (m_current_age >= m_max_age - offset); };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString baseId;
|
QString m_baseId;
|
||||||
QString basePath;
|
QString m_basePath;
|
||||||
QString relativePath;
|
QString m_relativePath;
|
||||||
QString md5sum;
|
QString m_md5sum;
|
||||||
QString etag;
|
QString m_etag;
|
||||||
|
|
||||||
qint64 local_changed_timestamp = 0;
|
qint64 m_local_changed_timestamp = 0;
|
||||||
QString remote_changed_timestamp; // QString for now, RFC 2822 encoded time
|
QString m_remote_changed_timestamp; // QString for now, RFC 2822 encoded time
|
||||||
qint64 current_age = 0;
|
qint64 m_current_age = 0;
|
||||||
qint64 max_age = 0;
|
qint64 m_max_age = 0;
|
||||||
bool is_eternal = false;
|
bool m_is_eternal = false;
|
||||||
|
|
||||||
bool stale = true;
|
bool m_stale = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MetaEntryPtr = std::shared_ptr<MetaEntry>;
|
using MetaEntryPtr = std::shared_ptr<MetaEntry>;
|
||||||
|
Loading…
Reference in New Issue
Block a user