Enhance loadProcessedItems function to handle directory case by removing it before processing
This commit is contained in:
parent
0e56d0fc65
commit
4d32202961
1 changed files with 8 additions and 1 deletions
|
|
@ -1,9 +1,16 @@
|
||||||
import { readFileSync, writeFileSync, existsSync } from "fs";
|
import { readFileSync, writeFileSync, existsSync, statSync, rmSync } from "fs";
|
||||||
import { PROCESSED_FILE } from "./config";
|
import { PROCESSED_FILE } from "./config";
|
||||||
|
|
||||||
export function loadProcessedItems(): Record<string, string[]> {
|
export function loadProcessedItems(): Record<string, string[]> {
|
||||||
if (existsSync(PROCESSED_FILE)) {
|
if (existsSync(PROCESSED_FILE)) {
|
||||||
try {
|
try {
|
||||||
|
// 디렉토리인 경우 삭제
|
||||||
|
const stat = statSync(PROCESSED_FILE);
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
console.warn(`${PROCESSED_FILE}이(가) 디렉토리입니다. 삭제 후 새로 생성합니다.`);
|
||||||
|
rmSync(PROCESSED_FILE, { recursive: true });
|
||||||
|
return {};
|
||||||
|
}
|
||||||
return JSON.parse(readFileSync(PROCESSED_FILE, "utf-8"));
|
return JSON.parse(readFileSync(PROCESSED_FILE, "utf-8"));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("처리된 항목 파일 읽기 실패:", error);
|
console.error("처리된 항목 파일 읽기 실패:", error);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue