Skip to content

Commit 4d312d7

Browse files
Hristo HristovHristo Hristov
authored andcommitted
fix: potential file system race conditions fixes
1 parent 1f86df3 commit 4d312d7

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

packages/cli/lib/templates/ReactTemplate.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,16 @@ export class ReactTemplate implements Template {
123123
igniteuiResFile = igniteuiResFile.replace(freeVersionPath, fullVersionPath);
124124
igniteuiResFile = igniteuiResFile.replace("-lite", "");
125125
}
126-
fs.writeFileSync(igResPath, igniteuiResFile);
126+
127+
const fd = fs.openSync(igResPath, fs.constants.O_WRONLY | fs.constants.O_TRUNC);
128+
fs.writeSync(fd, igniteuiResFile);
129+
fs.closeSync(fd);
127130
}
128131

129132
if (dvDep && !igniteuiResFile.includes(dvPath)) {
130-
fs.appendFileSync(igResPath, `${'\r\n// Ignite UI Charts Required JavaScript File\r\nimport "'
131-
+ dvPath + '";\r\n'}`);
133+
const fd = fs.openSync(igResPath, fs.constants.O_WRONLY | fs.constants.O_APPEND);
134+
fs.writeSync(fd, `\r\n// Ignite UI Charts Required JavaScript File\r\nimport "${dvPath}";\r\n`);
135+
fs.closeSync(fd);
132136
}
133137

134138
} else {

packages/core/util/GoogleAnalytics.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ class GoogleAnalytics {
6969
protected static getUUID(): string {
7070
const absolutePath = path.join(this.userDataFolder, this.appFolder, this.userSettings);
7171
let UUID = "";
72-
if (fs.existsSync(absolutePath)) {
73-
UUID = require(absolutePath).UUID;
74-
} else {
75-
const dirName = path.dirname(absolutePath);
76-
if (!fs.existsSync(dirName)) {
77-
fs.mkdirSync(dirName);
78-
}
72+
const dirName = path.dirname(absolutePath);
73+
fs.mkdirSync(dirName, { recursive: true });
7974

75+
try {
76+
const fd = fs.openSync(absolutePath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR, 0o600);
8077
UUID = this.getUserID();
81-
fs.writeFileSync(absolutePath, JSON.stringify({ UUID }));
78+
fs.writeFileSync(fd, JSON.stringify({ UUID }));
79+
fs.closeSync(fd);
80+
} catch {
81+
UUID = JSON.parse(fs.readFileSync(absolutePath, "utf8")).UUID;
8282
}
8383

8484
return UUID;

0 commit comments

Comments
 (0)