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

Function compareStatsAndContent

src/utils/fileHistory.ts:642–674  ·  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

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

Callers 1

checkOriginFileChangedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected