diff --git a/src/main/extractor.ts b/src/main/extractor.ts index 77b6609..86d7e0f 100644 --- a/src/main/extractor.ts +++ b/src/main/extractor.ts @@ -2907,9 +2907,16 @@ export async function extractPackageArchives(options: ExtractOptions): Promise<{ let learnedPassword = cachedPackagePassword; let packageNeedsFlatMode = false; const extractedArchives = new Set(); + const skippedNonArchives = new Set(); const failedArchiveCategories = new Map(); for (const archivePath of candidates) { 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); } } @@ -3026,7 +3033,7 @@ export async function extractPackageArchives(options: ExtractOptions): Promise<{ logger.info(`Generische Split-Datei übersprungen (keine Archiv-Signatur): ${archiveName}`); extracted += 1; resumeCompleted.add(archiveResumeKey); - extractedArchives.add(archivePath); + skippedNonArchives.add(pathSetKey(archivePath)); await writeExtractResumeState(options.packageDir, resumeCompleted, options.packageId); clearInterval(pulseTimer); 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.`); } else { 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 removedArchives = sourceAndTargetEqual ? 0 diff --git a/tests/extractor.test.ts b/tests/extractor.test.ts index 043d429..5e55e58 100644 --- a/tests/extractor.test.ts +++ b/tests/extractor.test.ts @@ -858,6 +858,40 @@ describe("extractor", () => { expect(targets.has(p003)).toBe(true); 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", () => {