From f724be2e8b04303d5a6a40699a73983cd1843d58 Mon Sep 17 00:00:00 2001 From: Keyyard Date: Sat, 23 Aug 2025 02:35:42 +0700 Subject: [PATCH 1/5] feat(copyFiles): improve with size filter --- .../src/tasks/helpers/copyFiles.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts index c26f4b0..4401a32 100644 --- a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts +++ b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts @@ -13,8 +13,22 @@ export function copyFiles(originPaths: string[], outputPath: string) { console.log(`Copying folder ${inputPath} to ${destinationPath}`); } else { const filename = path.parse(inputPath).base; - destinationPath = path.resolve(destinationPath, filename); - console.log(`Copying file ${inputPath} to ${destinationPath}`); + const fileDestinationPath = path.resolve(destinationPath, filename); + console.log(`Copying file ${inputPath} to ${fileDestinationPath}`); + try { + const destFileStats = FileSystem.getStatistics(fileDestinationPath); + if (destFileStats.size === pathStats.size) { + continue; + } + } catch (e) { + // If getStatistics throws, destination likely doesn't exist — proceed to copy + } + + FileSystem.copyFiles({ + sourcePath: inputPath, + destinationPath: fileDestinationPath, + }); + continue; } FileSystem.copyFiles({ From c7a521cf63a5d8d52158a332f5dbf79d9fa9fc87 Mon Sep 17 00:00:00 2001 From: Keyyard Date: Sat, 23 Aug 2025 03:09:05 +0700 Subject: [PATCH 2/5] feat(copyFiles): enhance file copy logic with mtime checks and logging --- .../src/tasks/helpers/copyFiles.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts index 4401a32..bf9688e 100644 --- a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts +++ b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts @@ -6,6 +6,7 @@ import path from 'path'; export function copyFiles(originPaths: string[], outputPath: string) { let destinationPath = path.resolve(outputPath); + const MTIME_TOLERANCE_MS = 1000; // 1 second tolerance, avoid the case when file copying across system get delayed for (const originPath of originPaths) { const inputPath = path.resolve(originPath); const pathStats = FileSystem.getLinkStatistics(inputPath); @@ -14,19 +15,38 @@ export function copyFiles(originPaths: string[], outputPath: string) { } else { const filename = path.parse(inputPath).base; const fileDestinationPath = path.resolve(destinationPath, filename); - console.log(`Copying file ${inputPath} to ${fileDestinationPath}`); + + let shouldCopy = true; try { const destFileStats = FileSystem.getStatistics(fileDestinationPath); - if (destFileStats.size === pathStats.size) { - continue; + // If sizes differ => must copy + if (destFileStats.size !== pathStats.size) { + shouldCopy = true; + } else { + // sizes equal -> check mtimes within tolerance + const srcMtime = (pathStats as any).mtimeMs ?? new Date((pathStats as any).mtime).getTime(); + const destMtime = (destFileStats as any).mtimeMs ?? new Date((destFileStats as any).mtime).getTime(); + if (Math.abs(srcMtime - destMtime) > MTIME_TOLERANCE_MS) { + shouldCopy = true; + } else { + // sizes equal and mtimes within tolerance -> skip copy + shouldCopy = false; + } } - } catch (e) { - // If getStatistics throws, destination likely doesn't exist — proceed to copy + } catch (e: any) { + shouldCopy = true; } + if (!shouldCopy) { + console.log(`Skipping copy for ${inputPath}; no change detected`); + continue; + } + + console.log(`Copying file ${inputPath} to ${fileDestinationPath}`); FileSystem.copyFiles({ sourcePath: inputPath, destinationPath: fileDestinationPath, + preserveTimestamps: true, }); continue; } @@ -34,6 +54,7 @@ export function copyFiles(originPaths: string[], outputPath: string) { FileSystem.copyFiles({ sourcePath: inputPath, destinationPath: destinationPath, + preserveTimestamps: true, }); } } From 0b4d0c26b3f3800bb528b27a7febb00cf279da15 Mon Sep 17 00:00:00 2001 From: Keyyard Date: Sun, 7 Sep 2025 21:30:54 +0700 Subject: [PATCH 3/5] Change files --- ...e-build-tasks-c8da36d5-bd16-4a72-8285-57aeedfdb73a.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@minecraft-core-build-tasks-c8da36d5-bd16-4a72-8285-57aeedfdb73a.json diff --git a/change/@minecraft-core-build-tasks-c8da36d5-bd16-4a72-8285-57aeedfdb73a.json b/change/@minecraft-core-build-tasks-c8da36d5-bd16-4a72-8285-57aeedfdb73a.json new file mode 100644 index 0000000..080540b --- /dev/null +++ b/change/@minecraft-core-build-tasks-c8da36d5-bd16-4a72-8285-57aeedfdb73a.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "added sizeCheck as a flag", + "packageName": "@minecraft/core-build-tasks", + "email": "keyyard8888@gmail.com", + "dependentChangeType": "patch" +} From 89af607d2fa8e97a9dfe4cfb39de94acf9209025 Mon Sep 17 00:00:00 2001 From: Keyyard Date: Sun, 7 Sep 2025 21:32:48 +0700 Subject: [PATCH 4/5] feat(copyFiles): add configurable skipIfPossible flag --- .../src/tasks/helpers/copyFiles.ts | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts index bf9688e..80b7972 100644 --- a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts +++ b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts @@ -4,7 +4,7 @@ import { FileSystem } from '@rushstack/node-core-library'; import path from 'path'; -export function copyFiles(originPaths: string[], outputPath: string) { +export function copyFiles(originPaths: string[], outputPath: string, skipIfPossible: boolean = true) { let destinationPath = path.resolve(outputPath); const MTIME_TOLERANCE_MS = 1000; // 1 second tolerance, avoid the case when file copying across system get delayed for (const originPath of originPaths) { @@ -17,24 +17,26 @@ export function copyFiles(originPaths: string[], outputPath: string) { const fileDestinationPath = path.resolve(destinationPath, filename); let shouldCopy = true; - try { - const destFileStats = FileSystem.getStatistics(fileDestinationPath); - // If sizes differ => must copy - if (destFileStats.size !== pathStats.size) { - shouldCopy = true; - } else { - // sizes equal -> check mtimes within tolerance - const srcMtime = (pathStats as any).mtimeMs ?? new Date((pathStats as any).mtime).getTime(); - const destMtime = (destFileStats as any).mtimeMs ?? new Date((destFileStats as any).mtime).getTime(); - if (Math.abs(srcMtime - destMtime) > MTIME_TOLERANCE_MS) { + if (skipIfPossible) { + try { + const destFileStats = FileSystem.getStatistics(fileDestinationPath); + // If sizes differ => must copy + if (destFileStats.size !== pathStats.size) { shouldCopy = true; } else { - // sizes equal and mtimes within tolerance -> skip copy - shouldCopy = false; + // sizes equal -> check mtimes within tolerance + const srcMtime = (pathStats as any).mtimeMs ?? new Date((pathStats as any).mtime).getTime(); + const destMtime = (destFileStats as any).mtimeMs ?? new Date((destFileStats as any).mtime).getTime(); + if (Math.abs(srcMtime - destMtime) > MTIME_TOLERANCE_MS) { + shouldCopy = true; + } else { + // sizes equal and mtimes within tolerance -> skip copy + shouldCopy = false; + } } + } catch (e: any) { + shouldCopy = true; } - } catch (e: any) { - shouldCopy = true; } if (!shouldCopy) { From 65d8c6d80053a657b98e22dda62f0ea4ab1d30de Mon Sep 17 00:00:00 2001 From: Keyyard Date: Wed, 10 Sep 2025 11:32:33 +0700 Subject: [PATCH 5/5] fix(copyFiles): passed all tests in test:ci --- tools/core-build-tasks/src/tasks/helpers/copyFiles.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts index 80b7972..0db8ade 100644 --- a/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts +++ b/tools/core-build-tasks/src/tasks/helpers/copyFiles.ts @@ -5,7 +5,7 @@ import { FileSystem } from '@rushstack/node-core-library'; import path from 'path'; export function copyFiles(originPaths: string[], outputPath: string, skipIfPossible: boolean = true) { - let destinationPath = path.resolve(outputPath); + const destinationPath = path.resolve(outputPath); const MTIME_TOLERANCE_MS = 1000; // 1 second tolerance, avoid the case when file copying across system get delayed for (const originPath of originPaths) { const inputPath = path.resolve(originPath); @@ -25,8 +25,8 @@ export function copyFiles(originPaths: string[], outputPath: string, skipIfPossi shouldCopy = true; } else { // sizes equal -> check mtimes within tolerance - const srcMtime = (pathStats as any).mtimeMs ?? new Date((pathStats as any).mtime).getTime(); - const destMtime = (destFileStats as any).mtimeMs ?? new Date((destFileStats as any).mtime).getTime(); + const srcMtime = pathStats.mtimeMs ?? pathStats.mtime.getTime(); + const destMtime = destFileStats.mtimeMs ?? destFileStats.mtime.getTime(); if (Math.abs(srcMtime - destMtime) > MTIME_TOLERANCE_MS) { shouldCopy = true; } else { @@ -34,7 +34,7 @@ export function copyFiles(originPaths: string[], outputPath: string, skipIfPossi shouldCopy = false; } } - } catch (e: any) { + } catch { shouldCopy = true; } }