fix(launcher): split copied and hardlinked bytes in space-saving install progress
Report actual disk-copied bytes separately from NTFS hardlinked asset bytes during space-saving installation, display both counts clearly in the installer progress view, and note that Windows Explorer folder properties double-count hardlinked space.
This commit is contained in:
1 parent
9e6e13895e
commit
29736870ac
7 files changed
+119
-20
No files matched your search
@@ -68,6 +68,12 @@ export interface CopyPlan {
|
||||
export interface CopyProgress {
|
||||
readonly doneBytes: number;
|
||||
readonly doneFiles: number;
|
||||
/** Bytes actually written to disk so far (excludes hard-linked files). */
|
||||
readonly copiedBytes: number;
|
||||
/** Bytes shared via hard links so far (occupies no extra disk space). */
|
||||
readonly linkedBytes: number;
|
||||
/** Number of hard-linked files created so far. */
|
||||
readonly linkedFiles: number;
|
||||
}
|
||||
|
||||
/** Every file and folder to copy, relative to `source`. Links and junctions are not followed. */
|
||||
@@ -129,12 +135,19 @@ export async function copyPlannedFiles(
|
||||
for (const folder of plan.folders) await fsPromises.mkdir(join(target, folder), { recursive: true });
|
||||
const linkedTargets = hardlinks ? new Map<string, BigIntStats>() : undefined;
|
||||
let next = 0;
|
||||
let doneBytes = 0;
|
||||
let copiedBytes = 0;
|
||||
let linkedBytes = 0;
|
||||
let linkedFiles = 0;
|
||||
let doneFiles = 0;
|
||||
const emitProgress = (): void => {
|
||||
// Keep doneBytes aligned with actual bytes written to disk so hard-linked files
|
||||
// do not inflate copy progress.
|
||||
onProgress({ doneBytes: copiedBytes, doneFiles, copiedBytes, linkedBytes, linkedFiles });
|
||||
};
|
||||
const countBytes = (): Transform => new Transform({
|
||||
transform(chunk: Buffer, _encoding, callback) {
|
||||
doneBytes += chunk.length;
|
||||
onProgress({ doneBytes, doneFiles });
|
||||
copiedBytes += chunk.length;
|
||||
emitProgress();
|
||||
callback(null, chunk);
|
||||
},
|
||||
});
|
||||
@@ -155,7 +168,8 @@ export async function copyPlannedFiles(
|
||||
if (verified) {
|
||||
const linked = await linkVerifiedResource(from, to, verified);
|
||||
linkedTargets?.set(to, linked);
|
||||
doneBytes += file.bytes;
|
||||
linkedBytes += file.bytes;
|
||||
linkedFiles += 1;
|
||||
} else {
|
||||
await pipeline(
|
||||
fs.createReadStream(from),
|
||||
@@ -168,7 +182,7 @@ export async function copyPlannedFiles(
|
||||
await fsPromises.utimes(to, modified, modified);
|
||||
}
|
||||
doneFiles += 1;
|
||||
onProgress({ doneBytes, doneFiles });
|
||||
emitProgress();
|
||||
}
|
||||
} catch (error) {
|
||||
if (!hasError && !stop.signal.aborted && !signal.aborted) {
|
||||
|
||||
@@ -219,8 +219,10 @@ async function copyGame(
|
||||
report({ phase: 'measuring', doneBytes: 0, totalBytes: 0, doneFiles: 0, totalFiles: 0 });
|
||||
const plan = await planCopy(source);
|
||||
const hardlinks = useHardLinks ? await prepareHardlinks(source, plan, signal, report) : undefined;
|
||||
const linkedBytes = hardlinks ? [...hardlinks.values()].reduce((total, file) => total + Number(file.size), 0) : 0;
|
||||
const neededBytes = plan.totalBytes - linkedBytes + SPARE_BYTES;
|
||||
const linkTotalBytes = hardlinks ? [...hardlinks.values()].reduce((total, file) => total + Number(file.size), 0) : 0;
|
||||
const linkTotalFiles = hardlinks ? hardlinks.size : 0;
|
||||
const copyTotalBytes = Math.max(0, plan.totalBytes - linkTotalBytes);
|
||||
const neededBytes = copyTotalBytes + SPARE_BYTES;
|
||||
if (hardlinks && (!await sameVolume(source, target) || (await inspectGameFolder(source)).version !== sourceVersion)) {
|
||||
throw new AppError('hardlink_file_changed');
|
||||
}
|
||||
@@ -229,11 +231,26 @@ async function copyGame(
|
||||
throw new AppError('not_enough_space', { neededGb: gigabytes(neededBytes), freeGb: gigabytes(available) });
|
||||
}
|
||||
const targetExisted = await exists(target);
|
||||
const totals = { totalBytes: plan.totalBytes, totalFiles: plan.files.length };
|
||||
report({ phase: 'copying', doneBytes: 0, doneFiles: 0, ...totals });
|
||||
// Track actual disk-copy bytes in doneBytes/totalBytes so hard-linked resource archives
|
||||
// do not inflate the progress bar or cause sudden jumps when links are created.
|
||||
const totals = {
|
||||
totalBytes: copyTotalBytes > 0 ? copyTotalBytes : plan.files.length,
|
||||
totalFiles: plan.files.length,
|
||||
copyTotalBytes,
|
||||
...(hardlinks ? { linkTotalBytes, linkTotalFiles } : {}),
|
||||
};
|
||||
const toProgress = (done: { doneFiles: number; copiedBytes: number; linkedBytes: number; linkedFiles: number }): InstallProgress => ({
|
||||
phase: 'copying',
|
||||
doneBytes: copyTotalBytes > 0 ? done.copiedBytes : done.doneFiles,
|
||||
doneFiles: done.doneFiles,
|
||||
copiedBytes: done.copiedBytes,
|
||||
...(hardlinks ? { linkedBytes: done.linkedBytes, linkedFiles: done.linkedFiles } : {}),
|
||||
...totals,
|
||||
});
|
||||
report(toProgress({ doneFiles: 0, copiedBytes: 0, linkedBytes: 0, linkedFiles: 0 }));
|
||||
try {
|
||||
await copyPlannedFiles(source, target, plan, signal,
|
||||
(done) => report({ phase: 'copying', ...done, ...totals }), hardlinks);
|
||||
(done) => report(toProgress(done)), hardlinks);
|
||||
if (hardlinks && (await inspectGameFolder(source)).version !== sourceVersion) throw new AppError('hardlink_file_changed');
|
||||
return {
|
||||
sourceFiles: plan.files.map((file) => file.relativePath),
|
||||
|
||||
@@ -158,7 +158,8 @@
|
||||
"copy": "Copy installation (recommended)",
|
||||
"copyBody": "Copies the game to a new folder. Requires about {{size}} of free space.",
|
||||
"spaceSaving": "Space-saving copy",
|
||||
"spaceSavingBody": "Shares read-only resource archives on the same volume. Estimated space required is {{size}}. An in-place update to the source client can change shared files in this client.",
|
||||
"spaceSavingBody": "Resource packs are shared with the online client via same-volume hard links, requiring only about {{size}} of additional copying. Windows Explorer Properties counts shared files toward both folders, but only the newly copied files use extra disk space. An in-place update to the online client can change shared files.",
|
||||
"spaceSavingBreakdown": "Estimated copy: about {{copy}} · Shared via hard links: about {{shared}} (no extra disk space)",
|
||||
"spaceSavingPending": "Calculating how much space can be saved.",
|
||||
"spaceSavingUnavailable": "This installation has no read-only resource archives eligible for space-saving copying.",
|
||||
"sameVolumeRequired": "Select a destination on the same volume as the original installation.",
|
||||
@@ -214,6 +215,8 @@
|
||||
"recording": "Finishing installation"
|
||||
},
|
||||
"copied": "Copied {{done}} / {{total}} · {{doneFiles}} / {{totalFiles}} files",
|
||||
"copiedActual": "Copied to disk: {{copied}} / {{copyTotal}} ({{copiedFiles}} / {{copyTotalFiles}} files)",
|
||||
"linkedShared": "Shared via hard links (no extra space): {{linked}} / {{linkTotal}} ({{linkedFiles}} / {{linkTotalFiles}} resource packs)",
|
||||
"verified": "Verified {{done}} / {{total}} · {{doneFiles}} / {{totalFiles}} files",
|
||||
"prepared": "Prepared {{done}} / {{total}} · {{doneFiles}} / {{totalFiles}} files",
|
||||
"cancelHint": "Can be cancelled at any time; copied files will be deleted",
|
||||
|
||||
@@ -158,7 +158,8 @@
|
||||
"copy": "复制安装(推荐)",
|
||||
"copyBody": "将游戏复制到新文件夹。需要约 {{size}} 的可用空间。",
|
||||
"spaceSaving": "节省空间的复制",
|
||||
"spaceSavingBody": "与同一磁盘卷上的原版共用只读资源包,预计需要 {{size}}。原版就地更新可能改变客户端中的共享文件。",
|
||||
"spaceSavingBody": "资源包通过同盘硬链接与在线版共享,仅需额外复制约 {{size}};Windows 资源管理器「属性」会重复统计共享文件大小,实际只占新增复制的磁盘空间。原版就地更新可能改变共享文件。",
|
||||
"spaceSavingBreakdown": "预计实际复制约 {{copy}} · 硬链接共享约 {{shared}}(不额外占用磁盘空间)",
|
||||
"spaceSavingPending": "正在估算可节省的空间。",
|
||||
"spaceSavingUnavailable": "该安装目录没有可用于省空间复制的只读资源包。",
|
||||
"sameVolumeRequired": "请选择与原版位于同一磁盘卷的目标文件夹。",
|
||||
@@ -214,6 +215,8 @@
|
||||
"recording": "完成安装"
|
||||
},
|
||||
"copied": "已复制 {{done}} / {{total}} · {{doneFiles}} / {{totalFiles}} 个文件",
|
||||
"copiedActual": "实际复制:已复制 {{copied}} / {{copyTotal}}({{copiedFiles}} / {{copyTotalFiles}} 个文件)",
|
||||
"linkedShared": "硬链接共享(不额外占空间):已链接共享 {{linked}} / {{linkTotal}}({{linkedFiles}} / {{linkTotalFiles}} 个资源包)",
|
||||
"verified": "已核对 {{done}} / {{total}} · {{doneFiles}} / {{totalFiles}} 个文件",
|
||||
"prepared": "已处理 {{done}} / {{total}} · {{doneFiles}} / {{totalFiles}} 个文件",
|
||||
"cancelHint": "可随时取消,已复制的文件将被删除",
|
||||
|
||||
@@ -89,6 +89,14 @@ export function MethodStep({ source, sourceSize, choice, onChoice, onError }: Me
|
||||
: t('method.spaceSavingPending')}
|
||||
onSelect={() => choose('hardlink')}
|
||||
>
|
||||
{sourceSize && savingAvailable && (
|
||||
<p className="small">
|
||||
{t('method.spaceSavingBreakdown', {
|
||||
copy: formatBytes(bytesToCopy(sourceSize, 'hardlink')),
|
||||
shared: formatBytes(sourceSize.linkableBytes ?? 0),
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
{targetPicker}
|
||||
</Choice>
|
||||
<Choice
|
||||
|
||||
@@ -19,6 +19,27 @@ export function ProgressStep({ progress, useHardLinks, importDecals }: {
|
||||
const current = phases.indexOf(phase);
|
||||
const tracking = (phase === 'copying' || phase === 'verifying') && progress !== null;
|
||||
const caption = phase === 'verifying' ? 'progress.verified' : useHardLinks ? 'progress.prepared' : 'progress.copied';
|
||||
const hardlinkStats = phase === 'copying'
|
||||
&& useHardLinks
|
||||
&& progress !== null
|
||||
&& progress.copiedBytes !== undefined
|
||||
&& progress.copyTotalBytes !== undefined
|
||||
&& progress.linkedBytes !== undefined
|
||||
&& progress.linkTotalBytes !== undefined
|
||||
&& progress.linkedFiles !== undefined
|
||||
&& progress.linkTotalFiles !== undefined
|
||||
&& progress.linkTotalFiles > 0
|
||||
? {
|
||||
copiedBytes: progress.copiedBytes,
|
||||
copyTotalBytes: progress.copyTotalBytes,
|
||||
linkedBytes: progress.linkedBytes,
|
||||
linkTotalBytes: progress.linkTotalBytes,
|
||||
linkedFiles: progress.linkedFiles,
|
||||
linkTotalFiles: progress.linkTotalFiles,
|
||||
copiedFiles: Math.max(0, progress.doneFiles - progress.linkedFiles),
|
||||
copyTotalFiles: Math.max(0, progress.totalFiles - progress.linkTotalFiles),
|
||||
}
|
||||
: null;
|
||||
return (
|
||||
<>
|
||||
{phases.map((name, position) => {
|
||||
@@ -32,14 +53,35 @@ export function ProgressStep({ progress, useHardLinks, importDecals }: {
|
||||
})}
|
||||
<ProgressBar value={tracking ? progress.doneBytes : 0} max={tracking ? progress.totalBytes : null} large />
|
||||
{tracking && (
|
||||
<div className="progress-caption">
|
||||
{t(caption, {
|
||||
done: formatBytes(progress.doneBytes),
|
||||
total: formatBytes(progress.totalBytes),
|
||||
doneFiles: progress.doneFiles.toLocaleString(),
|
||||
totalFiles: progress.totalFiles.toLocaleString(),
|
||||
})}
|
||||
</div>
|
||||
hardlinkStats ? (
|
||||
<>
|
||||
<div className="progress-caption">
|
||||
{t('progress.copiedActual', {
|
||||
copied: formatBytes(hardlinkStats.copiedBytes),
|
||||
copyTotal: formatBytes(hardlinkStats.copyTotalBytes),
|
||||
copiedFiles: hardlinkStats.copiedFiles.toLocaleString(),
|
||||
copyTotalFiles: hardlinkStats.copyTotalFiles.toLocaleString(),
|
||||
})}
|
||||
</div>
|
||||
<div className="progress-caption">
|
||||
{t('progress.linkedShared', {
|
||||
linked: formatBytes(hardlinkStats.linkedBytes),
|
||||
linkTotal: formatBytes(hardlinkStats.linkTotalBytes),
|
||||
linkedFiles: hardlinkStats.linkedFiles.toLocaleString(),
|
||||
linkTotalFiles: hardlinkStats.linkTotalFiles.toLocaleString(),
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="progress-caption">
|
||||
{t(caption, {
|
||||
done: formatBytes(progress.doneBytes),
|
||||
total: formatBytes(progress.totalBytes),
|
||||
doneFiles: progress.doneFiles.toLocaleString(),
|
||||
totalFiles: progress.totalFiles.toLocaleString(),
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -143,6 +143,18 @@ export const InstallProgressSchema = z.object({
|
||||
totalBytes: z.number(),
|
||||
doneFiles: z.number(),
|
||||
totalFiles: z.number(),
|
||||
/** Actual bytes written to disk during copying (excludes hard-linked files). */
|
||||
copiedBytes: z.number().nonnegative().optional(),
|
||||
/** Total bytes planned to be written to disk during copying (excludes hard-linked files). */
|
||||
copyTotalBytes: z.number().nonnegative().optional(),
|
||||
/** Bytes shared via hard links so far (occupies no extra disk space). */
|
||||
linkedBytes: z.number().nonnegative().optional(),
|
||||
/** Total bytes planned to be shared via hard links. */
|
||||
linkTotalBytes: z.number().nonnegative().optional(),
|
||||
/** Number of hard-linked files created so far. */
|
||||
linkedFiles: z.number().nonnegative().optional(),
|
||||
/** Total number of files planned to be shared via hard links. */
|
||||
linkTotalFiles: z.number().nonnegative().optional(),
|
||||
});
|
||||
export type InstallProgress = z.output<typeof InstallProgressSchema>;
|
||||
|
||||
|
||||
Reference in new issue
Block a user