From 6da2e0183c21ab975f7039d151010aa9fa4f9814 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 24 Aug 2024 01:15:32 -0700 Subject: [PATCH 1/7] Add devdeviceid telemetry --- include/vcpkg/base/parse.h | 2 + include/vcpkg/base/system.deviceid.h | 17 ++++ include/vcpkg/base/system.h | 2 + include/vcpkg/metrics.h | 1 + src/vcpkg-test/metrics.cpp | 16 ++++ src/vcpkg/base/system.cpp | 13 +++ src/vcpkg/base/system.deviceid.cpp | 118 +++++++++++++++++++++++++++ src/vcpkg/metrics.cpp | 12 +++ 8 files changed, 181 insertions(+) create mode 100644 include/vcpkg/base/system.deviceid.h create mode 100644 src/vcpkg/base/system.deviceid.cpp diff --git a/include/vcpkg/base/parse.h b/include/vcpkg/base/parse.h index c4995786a3..55815750df 100644 --- a/include/vcpkg/base/parse.h +++ b/include/vcpkg/base/parse.h @@ -57,6 +57,8 @@ namespace vcpkg return is_lower_alpha(ch) || is_ascii_digit(ch) || ch == '-'; } + static constexpr bool is_hex_digit_lower(char32_t ch) { return is_ascii_digit(ch) || (ch >= 'a' && ch <= 'f'); } + static constexpr bool is_hex_digit(char32_t ch) { return is_ascii_digit(ch) || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'); diff --git a/include/vcpkg/base/system.deviceid.h b/include/vcpkg/base/system.deviceid.h new file mode 100644 index 0000000000..336df71016 --- /dev/null +++ b/include/vcpkg/base/system.deviceid.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#include + +namespace vcpkg +{ + bool validate_device_id(StringView uuid); + +#if defined(_WIN32) + std::string get_device_id(); +#else + std::string get_device_id(const vcpkg::Filesystem& fs); +#endif +} \ No newline at end of file diff --git a/include/vcpkg/base/system.h b/include/vcpkg/base/system.h index 6531546af1..7456664728 100644 --- a/include/vcpkg/base/system.h +++ b/include/vcpkg/base/system.h @@ -18,6 +18,8 @@ namespace vcpkg const ExpectedL& get_home_dir() noexcept; + const ExpectedL& get_platform_cache_root() noexcept; + const ExpectedL& get_platform_cache_vcpkg() noexcept; const ExpectedL& get_user_configuration_home() noexcept; diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index c128099f20..b18ccf5c6e 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -60,6 +60,7 @@ namespace vcpkg CommandName, DeploymentKind, DetectedCiEnvironment, + DevDeviceId, CiProjectId, CiOwnerId, InstallPlan_1, diff --git a/src/vcpkg-test/metrics.cpp b/src/vcpkg-test/metrics.cpp index 309abee672..7abc79373e 100644 --- a/src/vcpkg-test/metrics.cpp +++ b/src/vcpkg-test/metrics.cpp @@ -1,6 +1,7 @@ #include #include +#include #include @@ -88,6 +89,21 @@ TEST_CASE ("user config parses multiple paragraphs ", "[metrics]") CHECK(result.last_completed_survey == "survey"); } +TEST_CASE("device id", "[metrics]") +{ + CHECK(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff40a")); + + CHECK_FALSE(validate_device_id("")); + CHECK_FALSE(validate_device_id("nope")); + CHECK_FALSE(validate_device_id("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")); + CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a ")); + CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a\r\n")); + CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a")); + CHECK_FALSE(validate_device_id("C5337D65-1E69-46E1-AF76-BFFC7b9ff40A")); + CHECK_FALSE(validate_device_id("z5337x65:1y69:46z1:xx76:mlno7p9qr40s")); + CHECK_FALSE(validate_device_id("{c5337d65-1e69-46e1-af76-bffc7b9ff40a}")); +} + TEST_CASE ("user config to string", "[metrics]") { MetricsUserConfig uut; diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index ac4d4b8d83..5547233bfd 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -1,10 +1,12 @@ #include #include #include +#include #include #include #include #include +#include #if defined(__APPLE__) #include @@ -504,6 +506,17 @@ namespace vcpkg } #endif + const ExpectedL& get_platform_cache_root() noexcept + { + return +#if defined(_WIN32) + get_appdata_local() +#else + get_xdg_cache_home() +#endif + ; + } + const ExpectedL& get_platform_cache_vcpkg() noexcept { static ExpectedL s_vcpkg = diff --git a/src/vcpkg/base/system.deviceid.cpp b/src/vcpkg/base/system.deviceid.cpp new file mode 100644 index 0000000000..d4fc29eecf --- /dev/null +++ b/src/vcpkg/base/system.deviceid.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +namespace vcpkg +{ + // To ensure consistency, the uuid must follow the format specified below. + // - The value follows the 8-4-4-4-12 format(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) + // - The value shall be all lowercase and only contain hyphens. No braces or brackets. + bool validate_device_id(StringView uuid) + { + static constexpr size_t UUID_LENGTH = 36; + static constexpr char format[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; + if (uuid.size() != UUID_LENGTH) return false; + for (size_t i = 0; i < UUID_LENGTH; ++i) + { + if (format[i] == '-' && uuid[i] != '-') return false; + if (format[i] == 'x' && !ParserBase::is_hex_digit_lower(uuid[i])) return false; + } + return true; + } + +#if defined(_WIN32) + // Returns a shared DevDeviceID for telemetry. + std::string get_device_id() + { + // The value is cached in the 64-bit Windows Registry under HKeyCurrentUser\SOFTWARE\Microsoft\DeveloperTools. + // The key should be named 'deviceid' and should be of type REG_SZ(String value). + // The value should be stored in plain text. + auto maybe_registry_value = + get_registry_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\DeveloperTools", "deviceid"); + if (auto registry_value = maybe_registry_value.get()) + { + auto device_id = *registry_value; + return validate_device_id(deviceid) ? device_id : std::string{}; + } + + // vcpkg::generate_random_UUID() generates a compliant UUID + auto new_device_id = Strings::ascii_to_lowercase(vcpkg::generate_random_UUID()); + const auto as_utf16 = Strings::to_utf16(new_device_id); + const auto status = RegSetKeyValueW(HKEY_CURRENT_USER, + L"SOFTWARE\\Microsoft\\DeveloperTools", + L"deviceid", + REG_SZ, + as_utf16.c_str(), + static_cast(as_utf16.size() * sizeof(wchar_t))); + return (status != ERROR_SUCCESS) ? std::string{} : new_device_id; + } +#else + std::string get_device_id(const vcpkg::Filesystem& fs) + { + /* On Linux: + * - The folder subpath will be /Microsoft/DeveloperTools + * - Use $XDG_CACHE_HOME if it is set and not empty, else use $HOME/.cache. + * - The file will be called 'deviceid'. The value should be stored in plain text, UTF-8. + * + * On MacOS: + * - The folder path will be $HOME\Library\Application Support\Microsoft\DeveloperTools where $HOME is the + * user's home directory. + * - The file will be called 'deviceid'. + * - The value should be stored in plain text, UTF-8. + */ + const auto maybe_home_path = vcpkg::get_platform_cache_root(); + if (!maybe_home_path) + { + return {}; + } + + auto home_path = maybe_home_path.get(); + const auto container_path = +#if defined(__APPLE__) + *home_path / "Library/Application Support/Microsoft/DeveloperTools" +#else + *home_path / "Microsoft/DeveloperTools" +#endif + ; + const auto id_file_path = container_path / "deviceid"; + + std::error_code ec; + auto maybe_file = fs.exists(id_file_path, ec); + if (ec) + { + return {}; + } + + if (maybe_file) + { + auto contents = fs.read_contents(id_file_path, ec); + if (ec && !validate_device_id(contents)) + { + return {}; + } + return contents; + } + + // vcpkg::generate_random_UUID() generates a compliant UUID + auto new_device_id = Strings::ascii_to_lowercase(vcpkg::generate_random_UUID()); + fs.create_directories(container_path, ec); + if (ec) + { + return {}; + } + + fs.write_contents(id_file_path, new_device_id, ec); + if (ec) + { + return {}; + } + + return new_device_id; + } +#endif +} \ No newline at end of file diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 8f2b4453e9..275971ab7b 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ namespace vcpkg {StringMetric::CommandName, "command_name", "z-preregister-telemetry"}, {StringMetric::DeploymentKind, "deployment_kind", "Git"}, {StringMetric::DetectedCiEnvironment, "detected_ci_environment", "Generic"}, + {StringMetric::DevDeviceId, "devdeviceid", "00000000-0000-0000-0000-000000000000"}, {StringMetric::CiProjectId, "ci_project_id", "0"}, {StringMetric::CiOwnerId, "ci_owner_id", "0"}, // spec:triplet:version,... @@ -578,6 +580,16 @@ namespace vcpkg auto session = MetricsSessionData::from_system(); auto submission = get_global_metrics_collector().get_submission(); + + auto deviceid = +#if defined(_WIN32) + get_device_id() +#else + get_device_id(fs) +#endif + ; + submission.track_string(StringMetric::DevDeviceId, deviceid); + const std::string payload = format_metrics_payload(user, session, submission); if (g_should_print_metrics.load()) { From 08f003eacff9cb79441a3c8b0c43c995c938b4d1 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 24 Aug 2024 04:23:30 -0700 Subject: [PATCH 2/7] Fix null-terminated check on registry values --- src/vcpkg/base/system.cpp | 9 ++++++++- src/vcpkg/base/system.deviceid.cpp | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index 5547233bfd..bdeae3ec81 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -569,8 +569,15 @@ namespace vcpkg case REG_SZ: case REG_EXPAND_SZ: // remove trailing nulls - while (!value->data.empty() && !value->data.back()) + while (!value->data.empty()) { + auto data_len = value->data.size(); + if (data_len < 2 || value->data[data_len - 1] != '\0' || value->data[data_len - 2] != '\0') + { + break; + } + + value->data.pop_back(); value->data.pop_back(); } diff --git a/src/vcpkg/base/system.deviceid.cpp b/src/vcpkg/base/system.deviceid.cpp index d4fc29eecf..d4b20d9e82 100644 --- a/src/vcpkg/base/system.deviceid.cpp +++ b/src/vcpkg/base/system.deviceid.cpp @@ -37,18 +37,19 @@ namespace vcpkg if (auto registry_value = maybe_registry_value.get()) { auto device_id = *registry_value; - return validate_device_id(deviceid) ? device_id : std::string{}; + return validate_device_id(device_id) ? device_id : std::string{}; } // vcpkg::generate_random_UUID() generates a compliant UUID auto new_device_id = Strings::ascii_to_lowercase(vcpkg::generate_random_UUID()); const auto as_utf16 = Strings::to_utf16(new_device_id); + const auto status = RegSetKeyValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\DeveloperTools", L"deviceid", REG_SZ, as_utf16.c_str(), - static_cast(as_utf16.size() * sizeof(wchar_t))); + static_cast((1 + as_utf16.size()) * sizeof(wchar_t))); return (status != ERROR_SUCCESS) ? std::string{} : new_device_id; } #else From ba093333c9b45e1e56dcc14f3c4dfdea82bc3d0f Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 24 Aug 2024 13:15:24 -0700 Subject: [PATCH 3/7] Fixes --- src/vcpkg/base/system.cpp | 9 ++------- src/vcpkg/base/system.deviceid.cpp | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index bdeae3ec81..fcddf465cf 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -569,14 +569,9 @@ namespace vcpkg case REG_SZ: case REG_EXPAND_SZ: // remove trailing nulls - while (!value->data.empty()) + while (!value->data.empty() && !(L'\0' != *reinterpret_cast( + value->data.data() + value->data.size() - 2))) { - auto data_len = value->data.size(); - if (data_len < 2 || value->data[data_len - 1] != '\0' || value->data[data_len - 2] != '\0') - { - break; - } - value->data.pop_back(); value->data.pop_back(); } diff --git a/src/vcpkg/base/system.deviceid.cpp b/src/vcpkg/base/system.deviceid.cpp index d4b20d9e82..21b50d6546 100644 --- a/src/vcpkg/base/system.deviceid.cpp +++ b/src/vcpkg/base/system.deviceid.cpp @@ -92,7 +92,7 @@ namespace vcpkg if (maybe_file) { auto contents = fs.read_contents(id_file_path, ec); - if (ec && !validate_device_id(contents)) + if (ec || !validate_device_id(contents)) { return {}; } From 75992bfa77cbef2b83edb458685c47c8ac714079 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 24 Aug 2024 13:34:36 -0700 Subject: [PATCH 4/7] Format --- src/vcpkg-test/metrics.cpp | 14 ++++++++------ src/vcpkg/base/system.cpp | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/vcpkg-test/metrics.cpp b/src/vcpkg-test/metrics.cpp index 7abc79373e..728b33f4b7 100644 --- a/src/vcpkg-test/metrics.cpp +++ b/src/vcpkg-test/metrics.cpp @@ -1,8 +1,9 @@ #include -#include #include +#include + #include using namespace vcpkg; @@ -89,19 +90,20 @@ TEST_CASE ("user config parses multiple paragraphs ", "[metrics]") CHECK(result.last_completed_survey == "survey"); } -TEST_CASE("device id", "[metrics]") +TEST_CASE ("device id", "[metrics]") { CHECK(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff40a")); CHECK_FALSE(validate_device_id("")); CHECK_FALSE(validate_device_id("nope")); CHECK_FALSE(validate_device_id("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")); - CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a ")); - CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a\r\n")); - CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a")); + CHECK_FALSE(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff40a ")); + CHECK_FALSE(validate_device_id("c5337d6--1e6--46e--af76--ffc7b9ff40a")); + CHECK_FALSE(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff4\r\n")); + CHECK_FALSE(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff4\0")); CHECK_FALSE(validate_device_id("C5337D65-1E69-46E1-AF76-BFFC7b9ff40A")); - CHECK_FALSE(validate_device_id("z5337x65:1y69:46z1:xx76:mlno7p9qr40s")); CHECK_FALSE(validate_device_id("{c5337d65-1e69-46e1-af76-bffc7b9ff40a}")); + CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a")); } TEST_CASE ("user config to string", "[metrics]") diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index fcddf465cf..d943a8c3c2 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -569,8 +569,9 @@ namespace vcpkg case REG_SZ: case REG_EXPAND_SZ: // remove trailing nulls - while (!value->data.empty() && !(L'\0' != *reinterpret_cast( - value->data.data() + value->data.size() - 2))) + while ( + !value->data.empty() && value->data.size() >= 2 && + !(L'\0' != *reinterpret_cast(value->data.data() + value->data.size() - 2))) { value->data.pop_back(); value->data.pop_back(); From 1ea309aabbac27838cec83cfa92e7f10f9c3c71e Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 28 Aug 2024 13:03:09 -0700 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Billy O'Neal --- include/vcpkg/base/parse.h | 2 +- src/vcpkg/base/system.deviceid.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/vcpkg/base/parse.h b/include/vcpkg/base/parse.h index 55815750df..54e3ef78df 100644 --- a/include/vcpkg/base/parse.h +++ b/include/vcpkg/base/parse.h @@ -61,7 +61,7 @@ namespace vcpkg static constexpr bool is_hex_digit(char32_t ch) { - return is_ascii_digit(ch) || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'); + return is_hex_digit_lower(ch) || (ch >= 'A' && ch <= 'F'); } static constexpr bool is_word_char(char32_t ch) { return is_alphanum(ch) || ch == '_'; } diff --git a/src/vcpkg/base/system.deviceid.cpp b/src/vcpkg/base/system.deviceid.cpp index 21b50d6546..c42758385e 100644 --- a/src/vcpkg/base/system.deviceid.cpp +++ b/src/vcpkg/base/system.deviceid.cpp @@ -36,11 +36,10 @@ namespace vcpkg get_registry_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\DeveloperTools", "deviceid"); if (auto registry_value = maybe_registry_value.get()) { - auto device_id = *registry_value; + auto& device_id = *registry_value; return validate_device_id(device_id) ? device_id : std::string{}; } - // vcpkg::generate_random_UUID() generates a compliant UUID auto new_device_id = Strings::ascii_to_lowercase(vcpkg::generate_random_UUID()); const auto as_utf16 = Strings::to_utf16(new_device_id); From 189fc92fd4fd2b34f69c88c22a6be4b406b18a0e Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 28 Aug 2024 13:33:11 -0700 Subject: [PATCH 6/7] Apply suggestions from CR --- include/vcpkg/base/system.deviceid.h | 4 ---- src/vcpkg/base/system.cpp | 33 ++++++++++------------------ src/vcpkg/base/system.deviceid.cpp | 27 +++++++++++------------ src/vcpkg/metrics.cpp | 8 +------ 4 files changed, 26 insertions(+), 46 deletions(-) diff --git a/include/vcpkg/base/system.deviceid.h b/include/vcpkg/base/system.deviceid.h index 336df71016..4cc937d042 100644 --- a/include/vcpkg/base/system.deviceid.h +++ b/include/vcpkg/base/system.deviceid.h @@ -9,9 +9,5 @@ namespace vcpkg { bool validate_device_id(StringView uuid); -#if defined(_WIN32) - std::string get_device_id(); -#else std::string get_device_id(const vcpkg::Filesystem& fs); -#endif } \ No newline at end of file diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index d943a8c3c2..21943e6c1c 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -508,24 +508,19 @@ namespace vcpkg const ExpectedL& get_platform_cache_root() noexcept { - return + static ExpectedL s_home = #if defined(_WIN32) get_appdata_local() #else get_xdg_cache_home() #endif - ; + ; + return s_home; } const ExpectedL& get_platform_cache_vcpkg() noexcept { - static ExpectedL s_vcpkg = -#ifdef _WIN32 - get_appdata_local() -#else - get_xdg_cache_home() -#endif - .map([](const Path& p) { return p / "vcpkg"; }); + static ExpectedL s_vcpkg = get_platform_cache_root().map([](const Path& p) { return p / "vcpkg"; }); return s_vcpkg; } @@ -568,20 +563,16 @@ namespace vcpkg { case REG_SZ: case REG_EXPAND_SZ: - // remove trailing nulls - while ( - !value->data.empty() && value->data.size() >= 2 && - !(L'\0' != *reinterpret_cast(value->data.data() + value->data.size() - 2))) - { - value->data.pop_back(); - value->data.pop_back(); - } - + { + auto length_in_wchar_ts = value->data.size() >> 1; + auto as_utf8 = + Strings::to_utf8(reinterpret_cast(value->data.data()), length_in_wchar_ts); + while (!as_utf8.empty() && as_utf8.back() == 0) { - auto length_in_wchar_ts = value->data.size() >> 1; - return Strings::to_utf8(reinterpret_cast(value->data.data()), - length_in_wchar_ts); + as_utf8.pop_back(); } + return as_utf8; + } default: return msg::format_error(msgRegistryValueWrongType, msg::path = format_registry_value_name(base_hkey, sub_key, valuename)); diff --git a/src/vcpkg/base/system.deviceid.cpp b/src/vcpkg/base/system.deviceid.cpp index c42758385e..89f233139d 100644 --- a/src/vcpkg/base/system.deviceid.cpp +++ b/src/vcpkg/base/system.deviceid.cpp @@ -9,9 +9,9 @@ namespace vcpkg { - // To ensure consistency, the uuid must follow the format specified below. + // To ensure consistency, the device ID must follow the format specified below. // - The value follows the 8-4-4-4-12 format(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) - // - The value shall be all lowercase and only contain hyphens. No braces or brackets. + // - The value is all lowercase and only contain hyphens. No braces or brackets. bool validate_device_id(StringView uuid) { static constexpr size_t UUID_LENGTH = 36; @@ -26,12 +26,11 @@ namespace vcpkg } #if defined(_WIN32) - // Returns a shared DevDeviceID for telemetry. - std::string get_device_id() + std::string get_device_id(const vcpkg::Filesystem&) { // The value is cached in the 64-bit Windows Registry under HKeyCurrentUser\SOFTWARE\Microsoft\DeveloperTools. - // The key should be named 'deviceid' and should be of type REG_SZ(String value). - // The value should be stored in plain text. + // The key is named 'deviceid' and its type REG_SZ(String value). + // The value is stored in plain text. auto maybe_registry_value = get_registry_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\DeveloperTools", "deviceid"); if (auto registry_value = maybe_registry_value.get()) @@ -55,15 +54,16 @@ namespace vcpkg std::string get_device_id(const vcpkg::Filesystem& fs) { /* On Linux: - * - The folder subpath will be /Microsoft/DeveloperTools - * - Use $XDG_CACHE_HOME if it is set and not empty, else use $HOME/.cache. - * - The file will be called 'deviceid'. The value should be stored in plain text, UTF-8. + * - Use $XDG_CACHE_HOME if it is set and not empty, else use $HOME/.cache + * - The folder subpath is "/Microsoft/DeveloperTools" + * - The file is named 'deviceid' + * - The value is stored in UTF-8 plain text * * On MacOS: - * - The folder path will be $HOME\Library\Application Support\Microsoft\DeveloperTools where $HOME is the - * user's home directory. - * - The file will be called 'deviceid'. - * - The value should be stored in plain text, UTF-8. + * - Store the device id in the user's home directory ($HOME). + * - The folder subpath is "$HOME\Library\Application Support\Microsoft\DeveloperTools" + * - The file is named 'deviceid' + * - The value is stored in UTF-8 plain text */ const auto maybe_home_path = vcpkg::get_platform_cache_root(); if (!maybe_home_path) @@ -98,7 +98,6 @@ namespace vcpkg return contents; } - // vcpkg::generate_random_UUID() generates a compliant UUID auto new_device_id = Strings::ascii_to_lowercase(vcpkg::generate_random_UUID()); fs.create_directories(container_path, ec); if (ec) diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 275971ab7b..db13a59da5 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -581,13 +581,7 @@ namespace vcpkg auto submission = get_global_metrics_collector().get_submission(); - auto deviceid = -#if defined(_WIN32) - get_device_id() -#else - get_device_id(fs) -#endif - ; + auto deviceid = get_device_id(fs); submission.track_string(StringMetric::DevDeviceId, deviceid); const std::string payload = format_metrics_payload(user, session, submission); From 79cc507d56027f2bf93b2d8cd3ad1974b33cc5b9 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 28 Aug 2024 13:46:05 -0700 Subject: [PATCH 7/7] Fix format --- include/vcpkg/base/parse.h | 7 +------ include/vcpkg/base/system.deviceid.h | 2 +- src/vcpkg/base/system.deviceid.cpp | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/include/vcpkg/base/parse.h b/include/vcpkg/base/parse.h index 54e3ef78df..37263813c4 100644 --- a/include/vcpkg/base/parse.h +++ b/include/vcpkg/base/parse.h @@ -56,13 +56,8 @@ namespace vcpkg { return is_lower_alpha(ch) || is_ascii_digit(ch) || ch == '-'; } - static constexpr bool is_hex_digit_lower(char32_t ch) { return is_ascii_digit(ch) || (ch >= 'a' && ch <= 'f'); } - - static constexpr bool is_hex_digit(char32_t ch) - { - return is_hex_digit_lower(ch) || (ch >= 'A' && ch <= 'F'); - } + static constexpr bool is_hex_digit(char32_t ch) { return is_hex_digit_lower(ch) || (ch >= 'A' && ch <= 'F'); } static constexpr bool is_word_char(char32_t ch) { return is_alphanum(ch) || ch == '_'; } StringView skip_whitespace(); diff --git a/include/vcpkg/base/system.deviceid.h b/include/vcpkg/base/system.deviceid.h index 4cc937d042..945eb73afe 100644 --- a/include/vcpkg/base/system.deviceid.h +++ b/include/vcpkg/base/system.deviceid.h @@ -10,4 +10,4 @@ namespace vcpkg bool validate_device_id(StringView uuid); std::string get_device_id(const vcpkg::Filesystem& fs); -} \ No newline at end of file +} diff --git a/src/vcpkg/base/system.deviceid.cpp b/src/vcpkg/base/system.deviceid.cpp index 89f233139d..0188dd3770 100644 --- a/src/vcpkg/base/system.deviceid.cpp +++ b/src/vcpkg/base/system.deviceid.cpp @@ -114,4 +114,4 @@ namespace vcpkg return new_device_id; } #endif -} \ No newline at end of file +}