@@ -1157,9 +1157,7 @@ public async Task PublishContent(AutoSnapshotType autoSnapshotType, int maxLocal
11571157 } ) . ToArray ( )
11581158 } ;
11591159
1160- // The platform derives a content version from the payload it stored, and returns it per item. Index it
1161- // so each published file can record which remote payload its local checksum now describes. The same id
1162- // comes back once per visibility, carrying the same version.
1160+ // The platform returns the content version it assigned to each item, repeated once per visibility.
11631161 var publishedVersions = saveContentResponses
11641162 . SelectMany ( response => response . content )
11651163 . GroupBy ( c => c . id )
@@ -1178,8 +1176,7 @@ public async Task PublishContent(AutoSnapshotType autoSnapshotType, int maxLocal
11781176 {
11791177 ContentFile contentFile = c ;
11801178
1181- // We just uploaded these exact properties, so the local checksum is now the reference for the
1182- // version the platform assigned to them.
1179+ // We just uploaded these properties, so our checksum describes the version the platform assigned.
11831180 if ( publishedVersions . TryGetValue ( contentFile . Id , out var publishedVersion ) )
11841181 {
11851182 contentFile . Reference = new LocalContentReference ( contentFile . PropertiesChecksum , publishedVersion ) ;
@@ -1401,10 +1398,8 @@ public async Task<ContentSyncReport> SyncLocalContent(ClientManifestJsonResponse
14011398 contentFile . Tags = JsonSerializer . SerializeToElement ( c . ReferenceContent . tags ) ;
14021399 contentFile . FetchedFromManifestUid = targetManifestUid ;
14031400
1404- // Hash the payload we just downloaded using our own canonicalization, and record that rather than
1405- // trusting the publisher-supplied manifest checksum. The file about to be written is serialized from
1406- // this same element, so local and reference agree by construction regardless of how the publisher
1407- // ordered, escaped or formatted its JSON.
1401+ // Hash the downloaded payload ourselves rather than trusting the publisher's manifest checksum. The
1402+ // file we are about to write is serialized from this same element, so the two agree by construction.
14081403 contentFile . PropertiesChecksum = CalculateChecksum ( in contentFile ) ;
14091404 contentFile . Reference = new LocalContentReference ( contentFile . PropertiesChecksum , c . ReferenceContent . version ) ;
14101405 saveTasks . Add ( SaveContentFile ( contentFolder , contentFile , cancellationToken ) ) ;
@@ -1420,8 +1415,7 @@ public async Task<ContentSyncReport> SyncLocalContent(ClientManifestJsonResponse
14201415 contentFile . Tags = JsonSerializer . SerializeToElement ( c . ReferenceContent . tags ) ;
14211416 }
14221417
1423- // This set also contains locally modified and locally created files, whose local bytes are NOT the
1424- // remote ones, so only record a reference for the entries that actually match the target.
1418+ // This set also holds locally modified and created files, whose bytes are not the remote ones.
14251419 if ( c . ReferenceContent != null && contentFile . GetStatus ( ) == ContentStatus . UpToDate )
14261420 {
14271421 contentFile . Reference = new LocalContentReference ( contentFile . PropertiesChecksum , c . ReferenceContent . version ) ;
@@ -1987,8 +1981,6 @@ public static IEnumerable<LocalContentManifestEntry> ContentFileToLocalContentMa
19871981
19881982 /// <summary>
19891983 /// Reads the locally derived reference off a parsed content file, if it carries one.
1990- /// Absence is meaningful rather than exceptional: files written by an older CLI simply do not have it, and
1991- /// resolving that here keeps every downstream reader working with a reference that is whole or not there.
19921984 /// </summary>
19931985 private static LocalContentReference ? ReadReference ( in JsonElement json ) =>
19941986 json . TryGetProperty ( ContentFile . JSON_NAME_REFERENCE , out var reference )
@@ -2053,14 +2045,8 @@ public static JsonSerializerOptions GetContentFileSerializationOptions(bool inde
20532045 {
20542046 WriteIndented = indent ,
20552047 IncludeFields = true ,
2056-
2057- // Pinned deliberately. The bytes these options produce are hashed by CalculateChecksum and the
2058- // result is published as the manifest checksum, so this is a wire format rather than a style
2059- // preference: changing any value here re-hashes every content item and makes this CLI disagree
2060- // with every other CLI version in the realm. JavaScriptEncoder.Default is what System.Text.Json
2061- // used implicitly before this was written down, so naming it changes no existing checksum.
2048+ // Pinned: these bytes get hashed, so a change here re-checksums every content item in the realm.
20622049 Encoder = JavaScriptEncoder . Default ,
2063-
20642050 Converters =
20652051 {
20662052 new SortedJsonElementConverter ( ) , new SortedSnapshotConverter ( )
@@ -2241,10 +2227,8 @@ public struct LocalContentFiles
22412227}
22422228
22432229/// <summary>
2244- /// A checksum this CLI computed over a remote content payload, paired with the platform content version that
2245- /// says which payload it was. Neither half means anything on its own -- a checksum without its version would
2246- /// let a stale reference mask a genuine remote change -- so the two are only ever constructed together and an
2247- /// absent reference is represented by a null, not by empty strings.
2230+ /// A checksum this CLI computed over a remote content payload, paired with the content version identifying
2231+ /// which payload it was. The version is required: without it a stale checksum can mask a real remote change.
22482232/// </summary>
22492233[ Serializable ]
22502234public struct LocalContentReference
@@ -2262,8 +2246,7 @@ public LocalContentReference(string checksum, string version)
22622246 }
22632247
22642248 /// <summary>
2265- /// Reads a reference from the object a content file stores it under, yielding one only when both halves
2266- /// are present. A file carrying half a reference is treated as carrying none.
2249+ /// Reads a reference, yielding one only when both halves are present.
22672250 /// </summary>
22682251 public static bool TryRead ( in JsonElement json , out LocalContentReference reference )
22692252 {
@@ -2281,8 +2264,7 @@ public static bool TryRead(in JsonElement json, out LocalContentReference refere
22812264 }
22822265
22832266 /// <summary>
2284- /// True when this reference was taken from the very payload <paramref name="remote"/> points at, which is
2285- /// the only situation where comparing a local checksum against it means anything.
2267+ /// True when this reference was taken from the payload <paramref name="remote"/> points at.
22862268 /// </summary>
22872269 public bool Describes ( ClientContentInfoJson remote ) => Version == remote . version ;
22882270}
@@ -2312,9 +2294,9 @@ public struct ContentFile : IEquatable<ContentFile>
23122294 public string FetchedFromManifestUid ;
23132295
23142296 /// <summary>
2315- /// What the remote payload hashed to when we last synced it, as computed by this CLI rather than supplied
2316- /// by whoever published it . Null on files written before this existed, and on files restored from a
2317- /// snapshot, both of which fall back to comparing against the manifest checksum.
2297+ /// What the remote payload hashed to when we last synced it, computed by this CLI rather than supplied by
2298+ /// the publisher . Null on files written before this existed and on snapshot restores, which fall back to
2299+ /// the manifest checksum.
23182300 /// </summary>
23192301 [ JsonPropertyName ( JSON_NAME_REFERENCE ) ]
23202302 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
@@ -2333,10 +2315,9 @@ public ContentStatus GetStatus()
23332315
23342316 /// <summary>
23352317 /// Compares the local properties against the remote ones we last synced.
2336- /// Prefers <see cref="Reference"/>, which both sides of the comparison canonicalized the same way, and which
2337- /// is only usable for the remote payload it was taken from. Otherwise falls back to the publisher-supplied
2338- /// manifest checksum, which is the historical behaviour and is only correct when the publisher happened to
2339- /// match our serialization.
2318+ /// Prefers <see cref="Reference"/> when it describes the manifest entry in hand, since both sides of that
2319+ /// comparison were canonicalized the same way. Otherwise falls back to the publisher-supplied manifest
2320+ /// checksum, which is the historical behavior.
23402321 /// </summary>
23412322 private bool IsPropertiesDiff ( ) => Reference . HasValue && Reference . Value . Describes ( ReferenceContent )
23422323 ? Reference . Value . Checksum != PropertiesChecksum
@@ -2470,8 +2451,7 @@ private static void WriteSortedJsonElement(Utf8JsonWriter writer, JsonElement el
24702451 writer . WriteStartObject ( ) ;
24712452 foreach ( var property in element . EnumerateObject ( )
24722453 . OrderBy ( p => p . Name , StringComparer . OrdinalIgnoreCase )
2473- // OrderBy is a stable sort, so without this two keys that differ only in case would
2474- // keep whatever order they arrived in -- exactly the instability we are removing.
2454+ // OrderBy is stable, so without this, keys differing only in case keep arrival order.
24752455 . ThenBy ( p => p . Name , StringComparer . Ordinal ) )
24762456 {
24772457 writer . WritePropertyName ( property . Name ) ;
0 commit comments