2026-02-17 13:39:47 -06:00
|
|
|
import fs from "node:fs";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import type { PaperclipConfig } from "../config/schema.js";
|
|
|
|
|
import type { CheckResult } from "./index.js";
|
|
|
|
|
|
2026-02-18 16:47:15 -06:00
|
|
|
function resolveConfigRelativePath(value: string, configPath?: string): string {
|
|
|
|
|
if (path.isAbsolute(value)) return value;
|
|
|
|
|
const candidates = [path.resolve(value)];
|
|
|
|
|
if (configPath) {
|
|
|
|
|
candidates.unshift(path.resolve(path.dirname(configPath), "..", "server", value));
|
|
|
|
|
candidates.unshift(path.resolve(path.dirname(configPath), value));
|
|
|
|
|
}
|
|
|
|
|
candidates.push(path.resolve(process.cwd(), "server", value));
|
|
|
|
|
const uniqueCandidates = Array.from(new Set(candidates));
|
|
|
|
|
return uniqueCandidates.find((candidate) => fs.existsSync(candidate)) ?? uniqueCandidates[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function logCheck(config: PaperclipConfig, configPath?: string): CheckResult {
|
|
|
|
|
const logDir = resolveConfigRelativePath(config.logging.logDir, configPath);
|
|
|
|
|
const reportedDir = logDir;
|
2026-02-17 13:39:47 -06:00
|
|
|
|
|
|
|
|
if (!fs.existsSync(logDir)) {
|
|
|
|
|
return {
|
|
|
|
|
name: "Log directory",
|
|
|
|
|
status: "warn",
|
2026-02-18 16:47:15 -06:00
|
|
|
message: `Log directory does not exist: ${reportedDir}`,
|
2026-02-17 13:39:47 -06:00
|
|
|
canRepair: true,
|
|
|
|
|
repair: () => {
|
2026-02-18 16:47:15 -06:00
|
|
|
fs.mkdirSync(reportedDir, { recursive: true });
|
2026-02-17 13:39:47 -06:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-02-18 16:47:15 -06:00
|
|
|
fs.accessSync(reportedDir, fs.constants.W_OK);
|
2026-02-17 13:39:47 -06:00
|
|
|
return {
|
|
|
|
|
name: "Log directory",
|
|
|
|
|
status: "pass",
|
2026-02-18 16:47:15 -06:00
|
|
|
message: `Log directory is writable: ${reportedDir}`,
|
2026-02-17 13:39:47 -06:00
|
|
|
};
|
|
|
|
|
} catch {
|
|
|
|
|
return {
|
|
|
|
|
name: "Log directory",
|
|
|
|
|
status: "fail",
|
|
|
|
|
message: `Log directory is not writable: ${logDir}`,
|
|
|
|
|
canRepair: false,
|
|
|
|
|
repairHint: "Check file permissions on the log directory",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|