( store: Store, fileSystem: FileSystem, storeId: string, repoRoot: string, dryRun?: boolean, onProgress?: (info: InitialSyncProgress) => void, config?: MgrepConfig, )
| 276 | } |
| 277 | |
| 278 | export async function initialSync( |
| 279 | store: Store, |
| 280 | fileSystem: FileSystem, |
| 281 | storeId: string, |
| 282 | repoRoot: string, |
| 283 | dryRun?: boolean, |
| 284 | onProgress?: (info: InitialSyncProgress) => void, |
| 285 | config?: MgrepConfig, |
| 286 | ): Promise<InitialSyncResult> { |
| 287 | const storeMetadata = await listStoreFileMetadata(store, storeId, repoRoot); |
| 288 | const allFiles = Array.from(fileSystem.getFiles(repoRoot)); |
| 289 | const repoFiles = allFiles.filter( |
| 290 | (filePath) => !fileSystem.isIgnored(filePath, repoRoot), |
| 291 | ); |
| 292 | |
| 293 | const repoFileSet = new Set(repoFiles); |
| 294 | |
| 295 | const filesToDelete = Array.from(storeMetadata.keys()).filter( |
| 296 | (filePath) => isSubpath(repoRoot, filePath) && !repoFileSet.has(filePath), |
| 297 | ); |
| 298 | |
| 299 | // Check files that potentially need uploading (new or modified) |
| 300 | const filesToPotentiallyUpload = repoFiles.filter((filePath) => { |
| 301 | if (config && exceedsMaxFileSize(filePath, config.maxFileSize)) { |
| 302 | return false; |
| 303 | } |
| 304 | const stored = storeMetadata.get(filePath); |
| 305 | // If not in store, it needs uploading |
| 306 | if (!stored) { |
| 307 | return true; |
| 308 | } |
| 309 | // If no mtime stored, we need to check (conservative) |
| 310 | if (!stored.mtime) { |
| 311 | return true; |
| 312 | } |
| 313 | // Check mtime to see if file might have changed |
| 314 | try { |
| 315 | const stat = fs.statSync(filePath); |
| 316 | return stat.mtimeMs > stored.mtime; |
| 317 | } catch { |
| 318 | return true; |
| 319 | } |
| 320 | }); |
| 321 | |
| 322 | const filesToSync = filesToPotentiallyUpload.length + filesToDelete.length; |
| 323 | if (config && filesToSync > config.maxFileCount) { |
| 324 | throw new MaxFileCountExceededError(filesToSync, config.maxFileCount); |
| 325 | } |
| 326 | |
| 327 | const total = repoFiles.length + filesToDelete.length; |
| 328 | let processed = 0; |
| 329 | let uploaded = 0; |
| 330 | let deleted = 0; |
| 331 | let errors = 0; |
| 332 | let quotaExceeded = false; |
| 333 | let quotaErrorMessage = ""; |
| 334 | |
| 335 | const concurrency = 100; |
no test coverage detected