Skip to content

fix(backup): use BigInt for NTFS inode checks - #1440

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-win32-bigint-ino-r1
Nov 3, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-win32-bigint-ino-r1

Conversation

@khaira777

@khaira777 khaira777 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Use BigInt statSync({ bigint: true }) device and inode comparison in isSameFileOrPath so 64-bit Windows NTFS file indices above Number.MAX_SAFE_INTEGER never lose precision or falsely collide during backup discovery and downgrade recovery.

Fixes #1439

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix NTFS inode collisions in backup discovery and restore

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Compare full-width NTFS file IDs so distinct backups are not mistaken for the live database.
• Preserve rejection of genuine live-database hardlinks during discovery and restore.
• Add deterministic regression coverage for colliding file IDs across both restore paths.
Diagram

graph TD
  Scan["Backup scan"] --> Stat["BigInt file IDs"] --> Live{"Live target?"}
  Live -- Yes --> Skip["Skip hardlink"]
  Live -- No --> Inspect["Classify candidate"] --> Validate["Validate restore source"] --> Stage["Stage snapshot"]
Loading
High-Level Assessment

Use native BigInt filesystem stats at each identity check, as this preserves exact NTFS file IDs while retaining hardlink protection. Path-only checks would miss hardlinks, and Number-based comparisons cannot distinguish the colliding IDs.

Files changed (2) +163 / -13

Bug fix (1) +23 / -13
db.tsUse exact file identity in backup discovery and restore +23/-13

Use exact file identity in backup discovery and restore

• Switches relevant stat, lstat, and fstat calls to BigInt stats so large NTFS inode values remain distinct. Guards zero-inode live-target comparisons and converts the reported backup size to a number for the existing result shape.

main/db.ts

Tests (1) +140 / -0
newer-db-downgrade-recovery.test.tsCover colliding NTFS file IDs and genuine hardlinks +140/-0

Cover colliding NTFS file IDs and genuine hardlinks

• Simulates distinct 64-bit file IDs that round to the same Number and verifies backup classification and successful downgrade and direct restores. Also verifies that both restore paths continue rejecting genuine hardlinks to the live database.

tests/newer-db-downgrade-recovery.test.ts

@qodo-code-review

qodo-code-review Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Zero-inode hardlinks can be restored ✓ Resolved

Resolving commit: cc25703

Resolution reason
Added a shared fallback identity check for zero-inode files using device, link count, size, and
modification time. Both live-target detection and restore-source validation use this check,
preventing ambiguous hardlinks from being accepted.
Description
isLiveDatabaseTarget and materializeRestoreSource both skip device-and-inode identity checks
when the candidate inode is 0n. On a filesystem that reports zero for a hardlink to the live
database, its distinct pathname also passes the path and realpath checks, allowing discovery to
include it and either restore entry point to stage it as a source.

Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #39
  🌐 PR #10
  🌐 PR #34
✅ Compliance rules (platform): 5 rules
✅ Web pages:
  +12 more
✅ Cross-repo context — repo relationships
Review mode: Auto: ⚖️ Balanced: Targeted filesystem and database recovery behavior warrants careful single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread main/db.ts Resolved
@khaira777 khaira777 changed the title fix(main): use BigInt inode checks for NTFS file IDs in backup discovery and restore fix(backup): use BigInt for NTFS inode checks Nov 3, 2026
Use { bigint: true } in isLiveDatabaseTarget, evaluateDowngradeBackupCandidate, and materializeRestoreSource so 64-bit NTFS File Reference Numbers (st_ino >= 2^53) do not collide under IEEE-754 Number rounding.

Fixes #1439
@khaira777
khaira777 force-pushed the fm/flocafe-win32-bigint-ino-r1 branch from 1bf5a4f to cc25703 Compare November 3, 2026 20:47
@khaira777
khaira777 merged commit 9e51d5b into main Nov 3, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-win32-bigint-ino-r1 branch November 3, 2026 20:58
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.

fix(db): use BigInt stat ino checks to prevent Windows NTFS file ID collisions

1 participant