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

Function CmdSyncAllRemoteApps

src/common/cli.cpp:688–748  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

686}
687
688std::string CmdSyncAllRemoteApps(const std::string& provider, const std::string& accountId,
689 const std::string& cloudRootArg) {
690 std::string tokenPath = GetTokenPath(provider);
691 if (tokenPath.empty()) {
692 return JsonError("Cannot determine config directory");
693 }
694
695 uint32_t parsedAccountId = static_cast<uint32_t>(std::strtoul(accountId.c_str(), nullptr, 10));
696 if (parsedAccountId == 0) {
697 return JsonError("Invalid account_id");
698 }
699
700 auto prov = CreateCloudProvider(provider);
701 if (!prov) {
702 return JsonError("Unknown provider: " + provider);
703 }
704
705 if (!prov->Init(tokenPath)) {
706 return JsonError("Failed to initialize provider");
707 }
708
709 if (!prov->IsAuthenticated()) {
710 prov->Shutdown();
711 return JsonError("Not authenticated");
712 }
713
714 std::string cloudRoot = NormalizeCloudRoot(cloudRootArg);
715 if (cloudRoot.empty()) {
716 prov->Shutdown();
717 return JsonError("cloud_root is required");
718 }
719 std::string storageRoot = cloudRoot + "storage/";
720#ifdef _WIN32
721 for (auto& c : storageRoot) { if (c == '/') c = '\\'; }
722#endif
723
724 LocalStorage::Init(storageRoot);
725 LocalMetadataStore::Init(storageRoot);
726 PendingOpsJournal::Init(storageRoot);
727 CloudStorage::Init(cloudRoot, std::move(prov));
728
729 auto syncedApps = CloudStorage::SyncAllFromCloud(parsedAccountId);
730 CloudWorkQueue::DrainQueue();
731 CloudStorage::Shutdown();
732
733 std::ostringstream apps;
734 apps << "[";
735 bool first = true;
736 for (uint32_t id : syncedApps) {
737 if (!first) apps << ",";
738 apps << JsonInt(id);
739 first = false;
740 }
741 apps << "]";
742
743 return JsonObject({
744 {"success", JsonBool(true)},
745 {"synced_apps", apps.str()},

Callers 1

RunCliFunction · 0.85

Calls 15

GetTokenPathFunction · 0.85
JsonErrorFunction · 0.85
CreateCloudProviderFunction · 0.85
NormalizeCloudRootFunction · 0.85
SyncAllFromCloudFunction · 0.85
DrainQueueFunction · 0.85
JsonIntFunction · 0.85
JsonObjectFunction · 0.85
JsonBoolFunction · 0.85
sizeMethod · 0.80
InitFunction · 0.70
ShutdownFunction · 0.70

Tested by

no test coverage detected