Skip to content

Commit 256b8bb

Browse files
committed
fix: make sure temp directory exists
1 parent c61bb75 commit 256b8bb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/grammar-utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ temp.track()
1111
const GrammarUtils = {
1212
tempFilesDir: path.join(os.tmpdir(), "atom_script_tempfiles"),
1313

14+
ensureTempDir() {
15+
if (!fs.existsSync(this.tempFilesDir)) {
16+
fs.mkdirSync(this.tempFilesDir)
17+
}
18+
},
19+
1420
// Public: Create a temporary path
1521
//
1622
// Returns the {String} filepath of the new file
1723
createTempPath(prefix = "", extension = "") {
24+
this.ensureTempDir()
1825
return temp.path({ dir: this.tempFilesDir, prefix, suffix: extension })
1926
},
2027

@@ -25,6 +32,7 @@ const GrammarUtils = {
2532
// Returns the {String} filepath of the new file
2633
createTempFileWithCode(code, extension = "") {
2734
try {
35+
this.ensureTempDir()
2836
const tempFile = temp.openSync({ dir: this.tempFilesDir, suffix: extension })
2937
fs.writeSync(tempFile.fd, code)
3038
fs.closeSync(tempFile.fd)

0 commit comments

Comments
 (0)