| 473 | } |
| 474 | |
| 475 | void 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 | |
| 525 | static bool RequeueFromWorker(WorkItem item) { |
| 526 | std::lock_guard<std::mutex> lock(g_queueMutex); |
no test coverage detected