Skip to content

Commit 276eaa5

Browse files
author
Lucas Araujo
committed
[DDW-1088] Cover log file not yet created case
1 parent 1c62127 commit 276eaa5

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

source/main/utils/handleCheckBlockReplayProgress.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,14 @@ const createHandleNewLogLine = (mainWindow: BrowserWindow) => {
7878
};
7979
};
8080

81-
export const handleCheckBlockReplayProgress = (
82-
mainWindow: BrowserWindow,
83-
logsDirectoryPath: string
84-
) => {
85-
const filename = 'node.log';
86-
const logFilePath = `${logsDirectoryPath}/pub/`;
87-
const filePath = path.join(logFilePath, filename);
88-
if (!fs.existsSync(filePath)) return;
89-
90-
const tail = new Tail(filePath, {
81+
const watchLogFile = ({
82+
logFilePath,
83+
mainWindow,
84+
}: {
85+
logFilePath: string;
86+
mainWindow: BrowserWindow;
87+
}) => {
88+
const tail = new Tail(logFilePath, {
9189
// using fs.watchFile instead of fs.watch on Windows because of Node API issues:
9290
// https://github.com/nodejs/node/issues/36888
9391
// https://github.com/lucagrulla/node-tail/issues/137
@@ -98,3 +96,41 @@ export const handleCheckBlockReplayProgress = (
9896
const handleNewLogLine = createHandleNewLogLine(mainWindow);
9997
tail.on('line', handleNewLogLine);
10098
};
99+
100+
const watchLogFileDir = ({
101+
logFileName,
102+
logFileDirPath,
103+
mainWindow,
104+
}: {
105+
logFileName: string;
106+
logFileDirPath: string;
107+
mainWindow: BrowserWindow;
108+
}) => {
109+
const watcher = fs.watch(logFileDirPath, {}, (eventname, file) => {
110+
if (eventname === 'rename' && logFileName === file) {
111+
watchLogFile({
112+
logFilePath: path.join(logFileDirPath, logFileName),
113+
mainWindow,
114+
});
115+
watcher.close();
116+
}
117+
});
118+
};
119+
120+
export const handleCheckBlockReplayProgress = (
121+
mainWindow: BrowserWindow,
122+
logsDirectoryPath: string
123+
) => {
124+
const logFileName = 'node.log';
125+
const logFileDirPath = `${logsDirectoryPath}/pub/`;
126+
const logFilePath = path.join(logFileDirPath, logFileName);
127+
128+
if (!fs.existsSync(logFilePath)) {
129+
watchLogFileDir({ logFileDirPath, logFileName, mainWindow });
130+
} else {
131+
watchLogFile({
132+
logFilePath,
133+
mainWindow,
134+
});
135+
}
136+
};

0 commit comments

Comments
 (0)