(
sourcePath: string,
targetPath: string,
)
| 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) => { |
no test coverage detected