MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / store_if_not_there

Method store_if_not_there

libcppcryptfs/filename/longfilenamecache.cpp:177–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175
176
177bool LongFilenameCache::store_if_not_there(LPCWSTR base64_hash, LPCWSTR path, const char *actual_encrypted)
178{
179
180 bool rval = true;
181
182 const WCHAR *key = base64_hash;
183
184 lock();
185
186 try {
187
188 // see if it's already there. If it isn't, inser it.
189
190 // If it is already there THEN DO NOTHING
191
192 auto mp = m_map.emplace(key, (LongFilenameCacheNode*)NULL);
193
194 if (mp.second) {
195
196 LongFilenameCacheNode *node = NULL;
197
198 // if it isn't, then see if the cache is full
199
200 // if so, remove oldest entry (from tail of linked list)
201
202 if (m_map.size() >= LFN_CACHE_ENTRIES) {
203 node = m_lru_list.back();
204 m_lru_list.pop_back();
205 m_map.erase(node->m_key);
206 }
207
208 // re-use node if we removed one, otherwise get one from spare list, otherwise make a new one
209
210 if (!node) {
211 if (!m_spare_node_list.empty()) {
212 node = m_spare_node_list.front();
213 m_spare_node_list.pop_front();
214 } else {
215 node = new LongFilenameCacheNode;
216 }
217 }
218
219 mp.first->second = node;
220
221 node->m_key = mp.first->first;
222 node->m_path = path;
223 node->m_actual_encrypted = actual_encrypted;
224#ifndef LFN_CACHE_NOTTL
225 node->m_timestap = GetTickCount64();
226#endif
227 node->m_list_it = m_lru_list.insert(m_lru_list.begin(), node);
228
229 }
230
231 } catch (...) {
232 rval = false;
233 }
234

Callers 1

decrypt_reverse_longnameFunction · 0.80

Calls 4

sizeMethod · 0.80
eraseMethod · 0.80
emptyMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected