MCPcopy Create free account
hub / github.com/defold/defold / WriteIndex

Function WriteIndex

engine/dlib/src/dlib/http_cache.cpp:328–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326 }
327
328 static Result WriteIndex(HCache cache, FILE* f)
329 {
330 IndexHeader header;
331
332 header.m_Magic = MAGIC;
333 header.m_Version = VERSION;
334 header.m_Checksum = 0;
335 header.m_SizeOfEntry = (uint32_t)sizeof(Entry);
336 header.m_SizeOfFileEntry = (uint32_t)sizeof(FileEntry);
337 size_t n_written = fwrite(&header, 1, sizeof(header), f);
338 if (n_written != sizeof(header))
339 {
340 return RESULT_IO_ERROR;
341 }
342 else
343 {
344 WriteEntryContext context(f);
345 cache->m_CacheTable.Iterate(&WriteEntry, &context);
346 if (context.m_Error)
347 {
348 return RESULT_IO_ERROR;
349 }
350 else
351 {
352 // Rewrite header with checksum
353 fseek(f, 0, SEEK_SET);
354 header.m_Checksum = dmHashFinal64(&context.m_HashState);
355 size_t n_written = fwrite(&header, 1, sizeof(header), f);
356 if (n_written != sizeof(header))
357 {
358 return RESULT_IO_ERROR;
359 }
360 }
361 }
362 return RESULT_OK;
363 }
364
365 Result Flush(HCache cache)
366 {

Callers 1

FlushFunction · 0.85

Calls 2

dmHashFinal64Function · 0.85
IterateMethod · 0.80

Tested by

no test coverage detected