@samitouri / QOSAMI-WSL / commits / 25d3add3

Fix unity build ODR collisions on duplicate file-local constants (#41446)

beena352 committed Aug 26, 2026 at 14:56 UTC 25d3add326358c52d05ca348a3754242ab082ea4
5 files changed +16 -17
src/windows/common/string.hpp
+4
@@ -36,6 +36,10 @@ std::optional<uint64_t> ParseStorageSize(std::wstring_view String, StorageSizeUn
36 // 119856765 -> "120MB" at precision 3, "119.9MB" at precision 4.
37 std::wstring FormatHumanReadableSize(uint64_t Bytes, uint32_t Precision = 3, StorageSizeUnit Unit = StorageSizeUnit::Decimal);
38
39 +// Precision used when reporting the space reclaimed by prune, so that container, image and volume
40 +// prune agree on a single decimal place.
41 +inline constexpr uint32_t c_reclaimedSpacePrecision = 4;
42 +
43 std::vector<std::string> InitializeStringSet(_In_count_(BufferSize) LPCSTR Buffer, _In_ SIZE_T BufferSize);
44
45 bool IsPathComponentEqual(const std::wstring_view String1, const std::wstring_view String2);
src/windows/wslc/tasks/ContainerTasks.cpp
-2
@@ -129,8 +129,6 @@ nlohmann::json ComputeContainerStatsJson(const wsl::windows::common::docker_sche
129
130 namespace wsl::windows::wslc::task {
131
132 -constexpr uint32_t c_reclaimedSpacePrecision = 4;
133 -
132 static bool TryInspectContainer(Terminal& terminal, Session& session, const std::string& containerId, std::optional<wslc_schema::InspectContainer>& inspectData)
133 {
134 try
src/windows/wslc/tasks/ImageTasks.cpp
+4 -6
@@ -37,8 +37,6 @@ using namespace wsl::windows::wslc::services;
37
38 namespace wsl::windows::wslc::task {
39
40 -constexpr uint32_t c_reclaimedSpacePrecision = 4;
41 -
40 namespace {
41
42 class DECLSPEC_UUID("91EF98A7-99A8-41C2-893C-43CDFB7DB69F") WSLCImageLoadCallback
@@ -74,7 +72,7 @@ namespace {
72 };
73
74 // Placeholder for values that are unavailable. wslc does not track image digests or layer sharing.
77 - constexpr std::string_view c_notAvailable = "N/A";
75 + constexpr std::string_view c_imageNotAvailable = "N/A";
76
77 // Builds the representation of an image, shared by the table and json output so the two cannot
78 // drift. Every value is emitted as a string, "<none>" is used for missing repository/tag data,
@@ -82,17 +80,17 @@ namespace {
80 ImageOutputInformation ToImageOutput(const ImageInformation& image, bool truncate)
81 {
82 ImageOutputInformation entry;
85 - entry.Containers = image.Containers < 0 ? std::string{c_notAvailable} : std::to_string(image.Containers);
83 + entry.Containers = image.Containers < 0 ? std::string{c_imageNotAvailable} : std::to_string(image.Containers);
84
85 entry.CreatedAt = EpochToLocalDisplayTime(image.Created);
86 entry.CreatedSince = WideToMultiByte(FormatRelativeTime(image.Created));
87 entry.Digest = c_none;
88 entry.ID = truncate ? TruncateId(image.Id, true) : image.Id;
89 entry.Repository = image.Repository.value_or(std::string{c_none});
92 - entry.SharedSize = c_notAvailable;
90 + entry.SharedSize = c_imageNotAvailable;
91 entry.Size = WideToMultiByte(FormatHumanReadableSize(static_cast<uint64_t>(std::max<int64_t>(image.Size, 0))));
92 entry.Tag = image.Tag.value_or(std::string{c_none});
95 - entry.UniqueSize = c_notAvailable;
93 + entry.UniqueSize = c_imageNotAvailable;
94
95 return entry;
96 }
src/windows/wslc/tasks/VolumeTasks.cpp
+6 -8
@@ -31,27 +31,25 @@ using wsl::windows::common::string::FormatHumanReadableSize;
31
32 namespace wsl::windows::wslc::task {
33
34 -constexpr uint32_t c_reclaimedSpacePrecision = 4;
35 -
34 namespace {
35
36 // Reported for the fields that only carry a value when volume usage data or swarm cluster
37 // information is available, neither of which applies here.
40 - constexpr std::string_view c_notAvailable = "N/A";
38 + constexpr std::string_view c_volumeNotAvailable = "N/A";
39
40 // Converts session volume entries into the all-string shape used for "volume list --format json".
41 VolumeOutputInformation ToVolumeOutput(const wslc_schema::VolumeListEntry& volume)
42 {
43 VolumeOutputInformation entry;
46 - entry.Availability = c_notAvailable;
44 + entry.Availability = c_volumeNotAvailable;
45 entry.Driver = volume.Driver;
48 - entry.Group = c_notAvailable;
49 - entry.Links = c_notAvailable;
46 + entry.Group = c_volumeNotAvailable;
47 + entry.Links = c_volumeNotAvailable;
48 entry.Mountpoint = volume.Mountpoint;
49 entry.Name = volume.Name;
50 entry.Scope = volume.Scope;
53 - entry.Size = c_notAvailable;
54 - entry.Status = c_notAvailable;
51 + entry.Size = c_volumeNotAvailable;
52 + entry.Status = c_volumeNotAvailable;
53
54 for (const auto& [key, value] : volume.Labels)
55 {
test/windows/StringUnitTests.cpp
+2 -1
@@ -4,6 +4,7 @@
4 #include "Common.h"
5 #include "string.hpp"
6
7 +using wsl::windows::common::string::c_reclaimedSpacePrecision;
8 using wsl::windows::common::string::FormatHumanReadableSize;
9 using wsl::windows::common::string::ParseStorageSize;
10 using wsl::windows::common::string::StorageSizeUnit;
@@ -263,7 +264,7 @@ class StringUnitTests
264
265 for (const auto& [bytes, expected] : TestCases)
266 {
266 - VERIFY_ARE_EQUAL(expected, FormatHumanReadableSize(bytes, 4));
267 + VERIFY_ARE_EQUAL(expected, FormatHumanReadableSize(bytes, c_reclaimedSpacePrecision));
268 }
269 }
270