MCPcopy
hub / github.com/codeaashu/claude-code / compareStatsAndContent

Function compareStatsAndContent

src/utils/fileHistory.ts:640–672  ·  view source on GitHub ↗

* Shared stat/content comparison logic for sync and async change checks. * Returns true if the file has changed relative to the backup.

(
  originalStats: Stats | null,
  backupStats: Stats | null,
  compareContent: () => T,
)

Source from the content-addressed store, hash-verified

638 * Returns true if the file has changed relative to the backup.
639 */
640function compareStatsAndContent<T extends boolean | Promise<boolean>>(
641 originalStats: Stats | null,
642 backupStats: Stats | null,
643 compareContent: () => T,
644): T | boolean {
645 // One exists, one missing -> changed
646 if ((originalStats === null) !== (backupStats === null)) {
647 return true
648 }
649 // Both missing -> no change
650 if (originalStats === null || backupStats === null) {
651 return false
652 }
653
654 // Check file stats like permission and file size
655 if (
656 originalStats.mode !== backupStats.mode ||
657 originalStats.size !== backupStats.size
658 ) {
659 return true
660 }
661
662 // This is an optimization that depends on the correct setting of the modified
663 // time. If the original file's modified time was before the backup time, then
664 // we can skip the file content comparison.
665 if (originalStats.mtimeMs < backupStats.mtimeMs) {
666 return false
667 }
668
669 // Use the more expensive file content comparison. The callback handles its
670 // own read errors — a try/catch here is dead for async callbacks anyway.
671 return compareContent()
672}
673
674/**
675 * Computes the number of lines changed in the diff.

Callers 1

checkOriginFileChangedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected