MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / EnqueueWork

Function EnqueueWork

src/common/cloud_work_queue.cpp:475–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473}
474
475void EnqueueWork(WorkItem item) {
476 {
477 std::lock_guard<std::mutex> lock(g_queueMutex);
478 g_failedPaths.erase(item.cloudPath);
479 g_failedWorkItems.erase(item.cloudPath);
480
481 if (item.type == WorkItem::Delete) {
482 ClearRecentUploadForDeleteLocked(item.cloudPath);
483 } else if (item.type == WorkItem::Upload) {
484 uint64_t fingerprint = FingerprintUpload(item.data);
485 auto now = std::chrono::steady_clock::now();
486 PruneRecentUploadFingerprintsLocked(now);
487
488 auto recentIt = g_recentUploadFingerprints.find(item.cloudPath);
489 if (!HasDeleteBarrierForPathLocked(item.cloudPath) &&
490 recentIt != g_recentUploadFingerprints.end() &&
491 recentIt->second.first == fingerprint) {
492 LOG("[CloudStorage] Dedup: dropping recent identical upload for %s",
493 item.cloudPath.c_str());
494 return;
495 }
496
497 auto indexIt = g_uploadIndex.find(item.cloudPath);
498 if (indexIt != g_uploadIndex.end()) {
499 WorkItem existingCopy = *indexIt->second;
500 g_workQueue.erase(indexIt->second);
501 g_uploadIndex.erase(indexIt);
502
503 if (item.skipIfExists && !existingCopy.skipIfExists) {
504 LOG("[CloudStorage] Dedup: keeping queued authoritative upload for %s",
505 item.cloudPath.c_str());
506 g_workQueue.push_back(std::move(existingCopy));
507 g_uploadIndex[g_workQueue.back().cloudPath] = std::prev(g_workQueue.end());
508 return;
509 }
510 LOG("[CloudStorage] Dedup: replacing queued upload for %s (%zu -> %zu bytes)",
511 item.cloudPath.c_str(), existingCopy.data.size(), item.data.size());
512 // Fall through to push new item
513 }
514 }
515
516 g_workQueue.push_back(std::move(item));
517 auto it = std::prev(g_workQueue.end());
518 if (it->type == WorkItem::Upload) {
519 g_uploadIndex[it->cloudPath] = it;
520 }
521 }
522 g_queueCV.notify_one();
523}
524
525static bool RequeueFromWorker(WorkItem item) {
526 std::lock_guard<std::mutex> lock(g_queueMutex);

Callers 9

SaveRootTokensFunction · 0.85
SaveFileTokensFunction · 0.85
SaveManifestImplFunction · 0.85
EnqueueCloudDeleteFunction · 0.85
StoreBlobStagedFunction · 0.85
RetrieveBlobFunction · 0.85
DeleteBlobFunction · 0.85
SyncFromCloudInnerFunction · 0.85

Calls 6

FingerprintUploadFunction · 0.85
findMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected