Skip to content

[BUG] Windows Analyze counts NTFS hard links more than once #2011

Closed

Description

@luojiyin1987

Describe the bug

On NTFS, mo analyze counts each directory entry for a hard-linked file.
Two names for one 4,096-byte file report 8,192 bytes.
This affects directory totals and --json output.

The windows source at 59f3dc5a reported 6,911,541,248 bytes for a 100,000-entry fixture.
The fixture held 30,000 unique files and 70,000 extra hard links.
The unique file bytes totaled 2,073,501,696.

Steps to reproduce

Run these commands on an NTFS volume:

$root = Join-Path $env:TEMP ("mole-hardlink-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $root | Out-Null
$first = Join-Path $root "first.bin"
[IO.File]::WriteAllBytes($first, (New-Object byte[] 4096))
New-Item -ItemType HardLink -Path (Join-Path $root "second.bin") -Target $first | Out-Null
mo analyze --json $root

Expected behavior

The scan counts the file once and reports 4,096 bytes.
Both names remain visible. A later link can show 0 B.

Environment

Windows 11 on NTFS. Reproduced with Mole CLI (Windows) source 59f3dc5a.
The test used mo analyze --json; it changed no files.

Proposed fix

Use the volume serial number and file ID from Windows directory records.
Share the identity set across one scan and keep the result out of reusable caches.
Draft implementation: luojiyin1987:fix/analyze-hardlink-dedup.

Activity

  1. tw93 commented on Nov 16, 2026

    @tw93
    Owner

    @luojiyin1987 Thanks for the report and the fix. #2012 is merged into the windows branch, so each NTFS file now counts once per scan and later links show 0 B. #2015 follows up on the memory cost you measured, keeping NTFS identities as one bit per MFT record. Both ship with the next Mole CLI (Windows) release, and a clone install of the windows branch picks them up with mo update now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions