fix(launcher): preserve skipped files during game updates
Reuse source scan exclusions during stale-file cleanup so updates preserve user content and tool files copied by earlier installers. Verified with root and launcher typechecks and an update run against temporary folders.
This commit is contained in:
1 parent
1d3e47b082
commit
651b023d2a
2 files changed
+13
-4
No files matched your search
@@ -7,7 +7,7 @@ import type { Copies, GameFolderInspection, InstallRecord } from '@shared/schema
|
||||
import type { MaintenanceProgress } from '@shared/schemas/maintenance.ts';
|
||||
import { inspectGameFolder } from '../game-folder/inspect-game-folder.ts';
|
||||
import { sameVolume } from '../game-folder/inspect-target-folder.ts';
|
||||
import { copyPlannedFiles, planCopy, type CopyPlan } from '../install/copy-game.ts';
|
||||
import { copyPlannedFiles, isInSkippedSourceFolder, planCopy, type CopyPlan } from '../install/copy-game.ts';
|
||||
import {
|
||||
fileHash,
|
||||
linkVerifiedResource,
|
||||
@@ -57,7 +57,10 @@ export async function updateFromSource(record: InstallRecord, root: string, sign
|
||||
const linked = record.hardlinkedFiles ?? [];
|
||||
const linkedPaths = new Set(linked.map(key));
|
||||
const preserveHardlinks = await updatePreservesSpaceSaving(record, game, root);
|
||||
const remove = [...new Set([...(record.sourceFiles ?? []), ...linked])].filter((name) => !found.has(key(name)));
|
||||
// Older installs may have tracked files in folders that source scans now skip.
|
||||
const remove = [...new Set([...(record.sourceFiles ?? []), ...linked])].filter(
|
||||
(name) => !found.has(key(name)) && !isInSkippedSourceFolder(name),
|
||||
);
|
||||
const { copy, linksToStage, hardlinkedFiles } = await planUpdateFiles(
|
||||
game.path, root, dataPath, plan, linkedPaths, preserveHardlinks, signal,
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BigIntStats, Dirent } from 'node:fs';
|
||||
import { join, relative } from 'node:path';
|
||||
import { join, normalize, relative, sep } from 'node:path';
|
||||
import { Transform } from 'node:stream';
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import { AppError } from '@shared/errors.ts';
|
||||
@@ -42,6 +42,12 @@ const SKIPPED_SOURCE_FOLDERS = new Set([
|
||||
]);
|
||||
const LAUNCHER_EXECUTABLE_LOWER = 'wtoffline launcher.exe';
|
||||
|
||||
/** Whether a relative path starts with a top-level entry excluded from source scans. */
|
||||
export function isInSkippedSourceFolder(relativePath: string): boolean {
|
||||
const [topLevel = ''] = normalize(relativePath).split(sep, 1);
|
||||
return SKIPPED_SOURCE_FOLDERS.has(topLevel.toLowerCase());
|
||||
}
|
||||
|
||||
function isLauncherFolder(entries: readonly Dirent[]): boolean {
|
||||
return entries.some((entry) => entry.isFile() && entry.name.toLowerCase() === LAUNCHER_EXECUTABLE_LOWER);
|
||||
}
|
||||
@@ -80,7 +86,7 @@ export async function planCopy(source: string): Promise<CopyPlan> {
|
||||
}
|
||||
for (const entry of entries) {
|
||||
const path = join(folder, entry.name);
|
||||
if (folder === source && SKIPPED_SOURCE_FOLDERS.has(entry.name.toLowerCase())) continue;
|
||||
if (folder === source && isInSkippedSourceFolder(entry.name)) continue;
|
||||
if (entry.isDirectory()) {
|
||||
pending.push(path);
|
||||
} else if (entry.isFile()) {
|
||||
|
||||
Reference in new issue
Block a user