Fix: Nicht-Archiv-".00x"-Dateien werden beim Aufräumen nicht mehr gelöscht (Datenverlust)
findArchiveCandidates behandelt jede "*.001"-Datei (nicht .zip.001/.7z.001) als generischen Split-Kandidaten. Hatte so eine Datei KEINE Archiv-Signatur (also gar kein Archiv — z.B. eine eigene gesplittete Datendatei, ein Media-Chunk), wurde sie zwar korrekt als "kein Archiv" erkannt und übersprungen — aber dabei trotzdem zu extractedArchives gezählt. Stand daneben ein echtes Archiv (das Ausgabe erzeugt, failed===0), nahm der Cleanup ALLE candidates als Quelle und collectArchiveCleanupTargets löschte die komplette ".00x"-Familie (.001/.002/...) — obwohl daraus nie etwas entpackt wurde. Echter Datenverlust. Fix: Generische Split-Dateien ohne Archiv-Signatur landen jetzt in einem eigenen Set skippedNonArchives (per pathSetKey normalisiert) statt in extractedArchives und werden vor dem Cleanup explizit aus den cleanupSources gefiltert. Greift in beiden Pfaden: frischer Lauf (no-signature-Branch) und Resume (die Vorab- Befüllung aus dem Resume-State prüft die Signatur erneut). Die Datei bleibt für Fortschritt/Resume als erledigt markiert (resumeCompleted), zählt aber weder als "failed" noch als Cleanup-Ziel. Test: end-to-end über das echte extractPackageArchives — echtes movie.zip plus mydata.001/.002/.003 (kein Archiv) mit cleanupMode=delete; nach dem Lauf ist die ZIP-Ausgabe da und die .00x-Familie unangetastet. Ohne den Filter wird die Familie gelöscht (rot bewiesen).
This commit is contained in:
parent
2646cba1c7
commit
56bae4a384
@ -2907,9 +2907,16 @@ export async function extractPackageArchives(options: ExtractOptions): Promise<{
|
|||||||
let learnedPassword = cachedPackagePassword;
|
let learnedPassword = cachedPackagePassword;
|
||||||
let packageNeedsFlatMode = false;
|
let packageNeedsFlatMode = false;
|
||||||
const extractedArchives = new Set<string>();
|
const extractedArchives = new Set<string>();
|
||||||
|
const skippedNonArchives = new Set<string>();
|
||||||
const failedArchiveCategories = new Map<string, ExtractErrorCategory>();
|
const failedArchiveCategories = new Map<string, ExtractErrorCategory>();
|
||||||
for (const archivePath of candidates) {
|
for (const archivePath of candidates) {
|
||||||
if (resumeCompleted.has(archiveNameKey(path.basename(archivePath)))) {
|
if (resumeCompleted.has(archiveNameKey(path.basename(archivePath)))) {
|
||||||
|
const resumedName = path.basename(archivePath);
|
||||||
|
const resumedIsGenericSplit = /\.\d{3}$/i.test(resumedName) && !/\.(zip|7z)\.\d{3}$/i.test(resumedName);
|
||||||
|
if (resumedIsGenericSplit && !(await detectArchiveSignature(archivePath))) {
|
||||||
|
skippedNonArchives.add(pathSetKey(archivePath));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
extractedArchives.add(archivePath);
|
extractedArchives.add(archivePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3026,7 +3033,7 @@ export async function extractPackageArchives(options: ExtractOptions): Promise<{
|
|||||||
logger.info(`Generische Split-Datei übersprungen (keine Archiv-Signatur): ${archiveName}`);
|
logger.info(`Generische Split-Datei übersprungen (keine Archiv-Signatur): ${archiveName}`);
|
||||||
extracted += 1;
|
extracted += 1;
|
||||||
resumeCompleted.add(archiveResumeKey);
|
resumeCompleted.add(archiveResumeKey);
|
||||||
extractedArchives.add(archivePath);
|
skippedNonArchives.add(pathSetKey(archivePath));
|
||||||
await writeExtractResumeState(options.packageDir, resumeCompleted, options.packageId);
|
await writeExtractResumeState(options.packageDir, resumeCompleted, options.packageId);
|
||||||
clearInterval(pulseTimer);
|
clearInterval(pulseTimer);
|
||||||
archiveOutcome = "skipped";
|
archiveOutcome = "skipped";
|
||||||
@ -3370,7 +3377,8 @@ export async function extractPackageArchives(options: ExtractOptions): Promise<{
|
|||||||
logger.error(`Entpacken ohne neue Ausgabe erkannt: ${options.targetDir}. Cleanup wird NICHT ausgeführt.`);
|
logger.error(`Entpacken ohne neue Ausgabe erkannt: ${options.targetDir}. Cleanup wird NICHT ausgeführt.`);
|
||||||
} else {
|
} else {
|
||||||
if (!options.skipPostCleanup) {
|
if (!options.skipPostCleanup) {
|
||||||
const cleanupSources = failed === 0 ? candidates : Array.from(extractedArchives.values());
|
const cleanupSources = (failed === 0 ? candidates : Array.from(extractedArchives.values()))
|
||||||
|
.filter((archivePath) => !skippedNonArchives.has(pathSetKey(archivePath)));
|
||||||
const sourceAndTargetEqual = pathSetKey(path.resolve(options.packageDir)) === pathSetKey(path.resolve(options.targetDir));
|
const sourceAndTargetEqual = pathSetKey(path.resolve(options.packageDir)) === pathSetKey(path.resolve(options.targetDir));
|
||||||
const removedArchives = sourceAndTargetEqual
|
const removedArchives = sourceAndTargetEqual
|
||||||
? 0
|
? 0
|
||||||
|
|||||||
@ -858,6 +858,40 @@ describe("extractor", () => {
|
|||||||
expect(targets.has(p003)).toBe(true);
|
expect(targets.has(p003)).toBe(true);
|
||||||
expect(targets.has(other)).toBe(false);
|
expect(targets.has(other)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does NOT delete a non-archive .00x family that sits beside a real archive (no-signature data-loss guard)", async () => {
|
||||||
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-split-noarch-"));
|
||||||
|
tempDirs.push(root);
|
||||||
|
const packageDir = path.join(root, "pkg");
|
||||||
|
const targetDir = path.join(root, "out");
|
||||||
|
fs.mkdirSync(packageDir, { recursive: true });
|
||||||
|
|
||||||
|
const realZip = new AdmZip();
|
||||||
|
realZip.addFile("release.txt", Buffer.from("ok"));
|
||||||
|
realZip.writeZip(path.join(packageDir, "movie.zip"));
|
||||||
|
|
||||||
|
const d001 = path.join(packageDir, "mydata.001");
|
||||||
|
const d002 = path.join(packageDir, "mydata.002");
|
||||||
|
const d003 = path.join(packageDir, "mydata.003");
|
||||||
|
fs.writeFileSync(d001, "raw user split data, not an archive at all 0123456789", "utf8");
|
||||||
|
fs.writeFileSync(d002, "second raw chunk, also no archive magic bytes here", "utf8");
|
||||||
|
fs.writeFileSync(d003, "third raw chunk likewise plain content payload", "utf8");
|
||||||
|
|
||||||
|
const result = await extractPackageArchives({
|
||||||
|
packageDir,
|
||||||
|
targetDir,
|
||||||
|
cleanupMode: "delete",
|
||||||
|
conflictMode: "overwrite",
|
||||||
|
removeLinks: false,
|
||||||
|
removeSamples: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.failed).toBe(0);
|
||||||
|
expect(fs.existsSync(path.join(targetDir, "release.txt"))).toBe(true);
|
||||||
|
expect(fs.existsSync(d001)).toBe(true);
|
||||||
|
expect(fs.existsSync(d002)).toBe(true);
|
||||||
|
expect(fs.existsSync(d003)).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("detectArchiveSignature", () => {
|
describe("detectArchiveSignature", () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user