| 230 | } |
| 231 | |
| 232 | void HttpMetaCache::SaveNow() |
| 233 | { |
| 234 | if(m_index_file.isNull()) |
| 235 | return; |
| 236 | QJsonObject toplevel; |
| 237 | toplevel.insert("version", QJsonValue(QString("1"))); |
| 238 | QJsonArray entriesArr; |
| 239 | for (auto group : m_entries) |
| 240 | { |
| 241 | for (auto entry : group.entry_list) |
| 242 | { |
| 243 | // do not save stale entries. they are dead. |
| 244 | if(entry->stale) |
| 245 | { |
| 246 | continue; |
| 247 | } |
| 248 | QJsonObject entryObj; |
| 249 | entryObj.insert("base", QJsonValue(entry->baseId)); |
| 250 | entryObj.insert("path", QJsonValue(entry->relativePath)); |
| 251 | entryObj.insert("md5sum", QJsonValue(entry->md5sum)); |
| 252 | entryObj.insert("etag", QJsonValue(entry->etag)); |
| 253 | entryObj.insert("last_changed_timestamp", |
| 254 | QJsonValue(double(entry->local_changed_timestamp))); |
| 255 | if (!entry->remote_changed_timestamp.isEmpty()) |
| 256 | entryObj.insert("remote_changed_timestamp", |
| 257 | QJsonValue(entry->remote_changed_timestamp)); |
| 258 | entriesArr.append(entryObj); |
| 259 | } |
| 260 | } |
| 261 | toplevel.insert("entries", entriesArr); |
| 262 | |
| 263 | QJsonDocument doc(toplevel); |
| 264 | try |
| 265 | { |
| 266 | FS::write(m_index_file, doc.toJson()); |
| 267 | } |
| 268 | catch (const Exception &e) |
| 269 | { |
| 270 | qWarning() << e.what(); |
| 271 | } |
| 272 | } |