feat: Update 3 files

This commit is contained in:
Your Name
2025-06-29 19:55:07 +12:00
parent 50fb5f9da6
commit 17b321fb46
6 changed files with 74 additions and 24 deletions

View File

@ -267,4 +267,51 @@ bool GetbinClient::listPackages(std::vector<std::string>& outPackages) {
std::cerr << "[GetbinClient::listPackages] Exception: " << e.what() << std::endl;
return false;
}
}
}
bool GetbinClient::listAllEntries(std::vector<std::pair<std::string, std::vector<std::string>>>& outEntries) {
try {
std::string url = "https://" + SERVER_HOST + "/dir";
auto response = cpr::Get(cpr::Url{url},
cpr::Header{{"User-Agent", getUserAgent()}},
cpr::Timeout{30000}, // 30 seconds
cpr::VerifySsl{true});
if (response.status_code == 200) {
try {
auto resp_json = json::parse(response.text);
if (resp_json.contains("entries") && resp_json["entries"].is_array()) {
outEntries.clear();
for (const auto& entry : resp_json["entries"]) {
if (entry.contains("hash") && entry.contains("labeltags") &&
entry["hash"].is_string() && entry["labeltags"].is_array()) {
std::string hash = entry["hash"].get<std::string>();
std::vector<std::string> labeltags;
for (const auto& tag : entry["labeltags"]) {
if (tag.is_string()) {
labeltags.push_back(tag.get<std::string>());
}
}
outEntries.push_back({hash, labeltags});
}
}
return true;
}
} catch (const json::exception& e) {
std::cerr << "[GetbinClient::listAllEntries] JSON parse error: " << e.what() << std::endl;
}
} else {
std::cerr << "[GetbinClient::listAllEntries] HTTP " << response.status_code << ": " << response.error.message << std::endl;
}
return false;
} catch (const std::exception& e) {
std::cerr << "[GetbinClient::listAllEntries] Exception: " << e.what() << std::endl;
return false;
}
}

View File

@ -17,8 +17,9 @@ public:
bool getHash(const std::string& toolName, const std::string& arch, std::string& outHash);
bool deleteObject(const std::string& hash, const std::string& token);
bool listPackages(std::vector<std::string>& outPackages);
bool listAllEntries(std::vector<std::pair<std::string, std::vector<std::string>>>& outEntries);
private:
static const std::string SERVER_HOST;
std::string getUserAgent() const;
};
};

View File

@ -701,35 +701,34 @@ int unpublish_tool(int argc, char* argv[]) {
return 1;
}
} else {
// No specific architecture - unpublish all architectures
std::vector<std::string> allArchitectures = {"x86_64", "aarch64", "universal"};
std::vector<std::pair<std::string, std::string>> foundPackages;
// No specific architecture - unpublish ALL entries with this tool name
std::vector<std::pair<std::string, std::vector<std::string>>> allEntries;
std::vector<std::pair<std::string, std::string>> foundPackages; // (tag, hash)
std::cout << "Searching for " << toolName << " across all architectures..." << std::endl;
std::cout << "Searching for all entries with label '" << toolName << "'..." << std::endl;
// Find all existing versions
for (const auto& arch : allArchitectures) {
std::string archHash;
if (getbin.getHash(toolName, arch, archHash) && !archHash.empty()) {
// Validate hash
bool validHash = true;
for (char c : archHash) {
if (!std::isdigit(c)) {
validHash = false;
break;
}
}
if (validHash) {
foundPackages.push_back({arch, archHash});
std::cout << " Found " << toolName << ":" << arch << " (hash: " << archHash << ")" << std::endl;
if (!getbin.listAllEntries(allEntries)) {
std::cerr << "Failed to get directory listing from server" << std::endl;
return 1;
}
// Find all entries with labeltags starting with toolName:
for (const auto& entry : allEntries) {
const std::string& hash = entry.first;
const std::vector<std::string>& labeltags = entry.second;
for (const std::string& tag : labeltags) {
if (tag.find(toolName + ":") == 0) {
// Found a matching labeltag
foundPackages.push_back({tag, hash});
std::cout << " Found " << tag << " (hash: " << hash << ")" << std::endl;
break; // Only count each hash once even if it has multiple matching tags
}
}
}
if (foundPackages.empty()) {
std::cerr << "No packages found for " << toolName << std::endl;
std::cerr << "Searched architectures: x86_64, aarch64, universal" << std::endl;
return 1;
}
@ -741,7 +740,7 @@ int unpublish_tool(int argc, char* argv[]) {
int failCount = 0;
for (const auto& [arch, archHash] : foundPackages) {
std::cout << " Unpublishing " << toolName << ":" << arch << "... ";
std::cout << " Unpublishing " << arch << "... ";
if (getbin.deleteObject(archHash, token)) {
std::cout << "OK" << std::endl;
successCount++;

View File

@ -0,0 +1 @@
#!/bin/bash\necho display test

1
getpkg/test_multi/test-multi Executable file
View File

@ -0,0 +1 @@
#!/bin/bash\necho multi arch

1
getpkg/test_robust/test-robust Executable file
View File

@ -0,0 +1 @@
#!/bin/bash\necho robust test