MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / addFile

Method addFile

src/common/CacheManager.cpp:124–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122
123
124bool CacheManager::addFile(CacheRecord& record, const void* data) {
125 if (((data == NULL) && (record.size != 0)) || (record.url.size() <= 0)) {
126 return false;
127 }
128
129 record.name = getLocalName(record.url);
130 std::ostream* out = FILEMGR.createDataOutStream(record.name, true /* binary*/);
131 if (out == NULL) {
132 return false;
133 }
134
135 bool replacement = false;
136 CacheRecord* rec = &record;
137
138 int pos = findRecord(record.url);
139 if (pos >= 0) {
140 records[pos] = record;
141 rec = &records[pos];
142 replacement = true;
143 }
144
145 out->write((char*)data, rec->size);
146
147 rec->usedDate = time(NULL); // update the timestamp
148
149 MD5 md5;
150 md5.update((unsigned char*)data, rec->size);
151 md5.finalize();
152 rec->key = md5.hexdigest();
153
154 if (!replacement) {
155 records.push_back(*rec);
156 }
157
158 delete out;
159 return true;
160}
161
162
163int CacheManager::findRecord(const std::string& url) {

Callers

nothing calls this directly

Calls 7

createDataOutStreamMethod · 0.80
hexdigestMethod · 0.80
sizeMethod · 0.45
writeMethod · 0.45
updateMethod · 0.45
finalizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected