MCPcopy Create free account
hub / github.com/TanStack/cli / shouldUpdateFile

Method shouldUpdateFile

packages/cli/src/file-syncer.ts:157–183  ·  view source on GitHub ↗
(
    sourcePath: string,
    targetPath: string,
  )

Source from the content-addressed store, hash-verified

155 }
156
157 private async shouldUpdateFile(
158 sourcePath: string,
159 targetPath: string,
160 ): Promise<boolean> {
161 // If target doesn't exist, definitely update
162 if (!fs.existsSync(targetPath)) {
163 return true
164 }
165
166 // Compare file sizes first (quick check)
167 const [sourceStats, targetStats] = await Promise.all([
168 fs.promises.stat(sourcePath),
169 fs.promises.stat(targetPath),
170 ])
171
172 if (sourceStats.size !== targetStats.size) {
173 return true
174 }
175
176 // Compare MD5 hashes for content
177 const [sourceHash, targetHash] = await Promise.all([
178 this.calculateHash(sourcePath),
179 this.calculateHash(targetPath),
180 ])
181
182 return sourceHash !== targetHash
183 }
184
185 private async calculateHash(filePath: string): Promise<string> {
186 return new Promise((resolve, reject) => {

Callers 1

syncDirectoryMethod · 0.95

Calls 1

calculateHashMethod · 0.95

Tested by

no test coverage detected