refactor(artifacts): remove unused root classifier
This commit is contained in:
@@ -28,21 +28,6 @@ const classifyContainerExtension = (
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const classifyRoot = async (
|
||||
path: string,
|
||||
directory: boolean,
|
||||
): Promise<ArtifactOccurrence["artifact_format"]> => {
|
||||
if (directory) return "directory";
|
||||
const extensionFormat = classifyContainerExtension(path);
|
||||
if (extensionFormat !== undefined) return extensionFormat;
|
||||
const handle = await openRootFile(path);
|
||||
try {
|
||||
return await classifyOpenedRoot(path, handle);
|
||||
} finally {
|
||||
await handle.close();
|
||||
}
|
||||
};
|
||||
|
||||
/** Classify and hash one file root through the same stable open descriptor. */
|
||||
export const classifyAndHashRoot = async (
|
||||
path: string,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { constants } from "node:fs";
|
||||
import type { BigIntStats, Stats } from "node:fs";
|
||||
import { open, type FileHandle } from "node:fs/promises";
|
||||
|
||||
/** Identifies a selected path that cannot be read as one regular file. */
|
||||
export class NonRegularFileReadError extends Error {
|
||||
readonly code: "EISDIR" | "ENOTFILE";
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { lstat, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { classifyRoot } from "../../../src/artifacts/inventory/classify.js";
|
||||
import { classifyAndHashRoot } from "../../../src/artifacts/inventory/classify.js";
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -19,7 +19,9 @@ describe("ZIP signature detection", () => {
|
||||
const root = await createTestTempDirectory("rea-zip-signature-");
|
||||
const path = join(root, "input");
|
||||
await writeFile(path, Buffer.from(signature));
|
||||
expect(await classifyRoot(path, false)).toBe(archive ? "zip" : "file");
|
||||
expect(
|
||||
(await classifyAndHashRoot(path, false, await lstat(path))).format,
|
||||
).toBe(archive ? "zip" : "file");
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (archive)
|
||||
expect(target).toMatchObject({ ok: true, value: { format: "zip" } });
|
||||
@@ -37,7 +39,9 @@ describe("ZIP signature detection", () => {
|
||||
const root = await createTestTempDirectory("rea-zip-short-");
|
||||
const path = join(root, "input");
|
||||
await writeFile(path, Buffer.from(bytes));
|
||||
expect(await classifyRoot(path, false)).toBe("file");
|
||||
expect(
|
||||
(await classifyAndHashRoot(path, false, await lstat(path))).format,
|
||||
).toBe("file");
|
||||
expect((await parseBinaryTarget(path)).ok).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user