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

Function End

engine/dlib/src/dlib/http_cache.cpp:561–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

559 }
560
561 Result End(HCache cache, HCacheCreator cache_creator)
562 {
563 dmMutex::ScopedLock lock(cache->m_Mutex);
564
565 assert(cache_creator->m_File && cache_creator->m_Filename);
566 uint64_t identifier_hash = cache_creator->m_IdentifierHash;
567
568 fclose(cache_creator->m_File);
569 cache_creator->m_File = 0;
570
571 uint64_t uri_hash = cache_creator->m_UriHash;
572 Entry* entry = cache->m_CacheTable.Get(uri_hash);
573 assert(entry);
574
575 if (cache_creator->m_Error)
576 {
577 dmSys::Unlink(cache_creator->m_Filename);
578 FreeCacheCreator(cache, cache_creator);
579 cache->m_CacheTable.Erase(uri_hash);
580 return RESULT_IO_ERROR;
581 }
582
583 char path[DMPATH_MAX_PATH];
584 ContentFilePath(cache, identifier_hash, path, sizeof(path));
585 if (dmSys::Exists(path))
586 {
587 dmSys::Result r = dmSys::Unlink(path);
588 if (r != dmSys::RESULT_OK)
589 {
590 dmLogError("Unable to remove cache file: %s", path);
591 FreeCacheCreator(cache, cache_creator);
592 cache->m_CacheTable.Erase(uri_hash);
593 return RESULT_IO_ERROR;
594 }
595 }
596 else
597 {
598 // Modify path and remove last part of hash temporarily
599 // ie, .../5d/a7b8fa56d18877 to .../5d
600 char* last_slash = strrchr(path, '/');
601 char save = *last_slash;
602 *last_slash = '\0';
603 if (!dmSys::Exists(path))
604 {
605 dmSys::Result r = dmSys::Mkdir(path, 0755);
606 if (r != dmSys::RESULT_OK)
607 {
608 dmLogError("Unable to create directory '%s'", path);
609 FreeCacheCreator(cache, cache_creator);
610 cache->m_CacheTable.Erase(uri_hash);
611 return RESULT_IO_ERROR;
612 }
613 }
614 *last_slash = save;
615 }
616
617 assert(entry->m_WriteLock);
618 assert(entry->m_Info.m_IdentifierHash == identifier_hash);

Callers 3

DoDoRequestFunction · 0.70
PutMethod · 0.50
TEST_FFunction · 0.50

Calls 11

FreeCacheCreatorFunction · 0.85
ContentFilePathFunction · 0.85
dmHashFinal64Function · 0.85
dmStrErrorFunction · 0.85
UnlinkFunction · 0.70
ExistsFunction · 0.70
MkdirFunction · 0.70
RenameFunction · 0.70
assertFunction · 0.50
GetMethod · 0.45
EraseMethod · 0.45

Tested by 2

PutMethod · 0.40
TEST_FFunction · 0.40