Skip to content

Fix FileStatisticsDataEx reading the access time as the modified time - #141

Merged
wherewhere merged 3 commits into
SharpAdb:mainfrom
Alex4SSB:fix/stat-v2-offsets
Nov 17, 2026
Merged

wherewhere merged 3 commits into
SharpAdb:mainfrom
Alex4SSB:fix/stat-v2-offsets

Conversation

@Alex4SSB

@Alex4SSB Alex4SSB commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

FileStatisticsDataEx (used by StatEx and GetDirectoryListingEx) places ModifiedTime and ChangedTime one 8-byte field too early:

Field Offset before Correct offset
AccessTime 44 44
ModifiedTime 44 52
ChangedTime 52 60

So ModifiedTime returns the access time, ChangedTime returns the modified time, and the real ctime is never read. IFileStatistics.Time and ToString() both use ModifiedTime, so every V2 listing shows access times as modification times.

Source

adbd's packed sync_stat_v2 / sync_dent_v2 in file_sync_protocol.h (lines 55-68 and 78-92) declare, after the id that ReadSyncResponse consumes:

error (u32) · dev (u64) · ino (u64) · mode (u32) · nlink (u32) · uid (u32) · gid (u32) · size (u64) · atime (i64) · mtime (i64) · ctime (i64)

That puts atime at 5×4 + 3×8 = 44, mtime at 52 and ctime at 60, for the 68-byte Length the struct already declares. This file is the one linked in the struct's own <remarks>.

Changes

  • FileStatisticsData.V2.cs: ModifiedTime at (5 * sizeof(uint)) + (3 * sizeof(ulong)) + sizeof(long), ChangedTime at ... + (2 * sizeof(long)).
  • Tests: the listing tests gave all three times the same value, which hid the overlap. The first entry in GetListingExTest, GetListingExAsyncTest and GetAsyncListingExTest now has atime/mtime/ctime one second apart. Those three tests fail without the fix and pass with it; all 28 SyncServiceTests pass.

Also: split install counts in InstallMultiplePackageAsync

The first CI run failed PackageManagerTests.InstallMultiplePackageAsyncTest on Windows. That's unrelated to the stat change: on an unmodified main build it fails about 2 runs in 10. The cause is in PackageManager.Async.cs, where the parallel continuations count finished splits with callback?.Invoke(new InstallProgressEventArgs(++count, ...)):

  • No callback: ?. skips evaluating the argument, so ++count never runs and every multi-package install without a callback throws ... 2 should process but only 0 processed.
  • Lost increment: two continuations (ConfigureAwait(false), so on pool threads) can increment at once and lose one, throwing ... only 1 processed. This is the CI failure.
  • Out of order: reports can arrive with PackageFinished going 2 then 1, which the test's progress checker rejects.

The count now increments on its own line, under a lock together with the callback, in all four parallel blocks (remove after install, both overloads; write session, both overloads). The synchronous versions are sequential and don't check the count, so they're unchanged.

New test InstallMultiplePackageWithoutCallbackAsyncTest fails on main and passes with the fix. PackageManagerTests passed 50 of 50 runs locally, and the full suite passes (689 tests).

🤖 Generated with Claude Code

ModifiedTime and ChangedTime were placed one 8-byte field early, so
ModifiedTime overlapped AccessTime (offset 44) and ChangedTime read the
modified time (52). Per adbd's sync_stat_v2 layout they sit at 52 and 60.

The listing tests used one timestamp for all three times, which hid the
overlap; the first entry now has distinct times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alex4SSB

Copy link
Copy Markdown
Contributor Author

Here again as with the previous PR - Claude found a bug with the parsing of LIS2 vs ADB source code, confirmed by comparing it against adb shell stat. That's where I first noticed the difference.

InstallMultiplePackageAsync counted finished splits with ++count inside
callback?.Invoke(...) in parallel continuations, which had three effects:
- Without a callback, the argument (and ++count) was never evaluated, so
  every multi-package install threw "2 should process but only 0 processed".
- Two continuations could increment at once and lose one, throwing
  "only 1 processed" (the intermittent InstallMultiplePackageAsyncTest
  failure).
- Reports could arrive out of order, PackageFinished going 2 then 1.

The count now increments on its own, and with the callback under a lock.
InstallMultiplePackageWithoutCallbackAsyncTest covers the first case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the timestamp-decoding and asynchronous split-install completion-counting changes.

No open issues 🎉

What changed in this PR

Corrects timestamp decoding for StatEx and extended directory listings, and fixes completion counting during asynchronous split-package installation.

Changes:

  • Moves ModifiedTime and ChangedTime to their correct protocol offsets.
  • Synchronizes split completion counts and progress callbacks, while counting completions even without a callback.
  • Adds regression coverage for distinct timestamps and callback-free installs.
File Description
AdvancedSharpAdbClient/​Models/​FileStatisticsData.V2.cs Corrects modification and change timestamp offsets.
AdvancedSharpAdbClient/​DeviceCommands/​PackageManager.Async.cs Protects completion counts and orders progress reports in four parallel blocks.
AdvancedSharpAdbClient.Tests/​SyncServiceTests.cs Uses distinct timestamps to detect incorrect field offsets.
AdvancedSharpAdbClient.Tests/​SyncServiceTests.Async.cs Adds distinct timestamp checks to both asynchronous listing variants.
AdvancedSharpAdbClient.Tests/​DeviceCommands/​PackageManagerTests.Async.cs Tests both split-package install overloads without callbacks.

Review effort: Balanced

Fix warning

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the timestamp-decoding and asynchronous split-installation fixes.

No open issues 🎉

Review effort: Balanced

@wherewhere
wherewhere merged commit ba78336 into SharpAdb:main Nov 17, 2026
8 of 9 checks passed
@wherewhere

Copy link
Copy Markdown
Member

Thanks for your AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants