Skip to content

Commit 25e8247

Browse files
committed
attempt to re-create TMPDIR if it doesn't exist
1 parent b6f1f4e commit 25e8247

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/core/temp.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*
66
*/
77

8-
import { warning } from "log/mod.ts";
8+
import { debug, warning } from "log/mod.ts";
99
import { join } from "path/mod.ts";
10-
import { ensureDirSync } from "fs/mod.ts";
10+
import { ensureDirSync, existsSync } from "fs/mod.ts";
1111
import { removeIfExists, safeRemoveIfExists } from "./path.ts";
1212
import { TempContext } from "./temp-types.ts";
1313

@@ -18,6 +18,21 @@ let tempDir: string | undefined;
1818
let tempContext: TempContext | undefined;
1919

2020
export function initSessionTempDir() {
21+
// if TMPDIR exists and has been removed (sometimes occurs for stale TMPDIR values
22+
// in resurrected RStudio terminal sessions) then try to re-create it
23+
const tmpEnv = Deno.env.get("TMPDIR");
24+
if (tmpEnv) {
25+
try {
26+
if (!existsSync(tmpEnv)) {
27+
ensureDirSync(tmpEnv);
28+
}
29+
} catch (err) {
30+
if (err.message) {
31+
debug("Error attempting to create TMPDIR: " + err.message);
32+
}
33+
}
34+
}
35+
2136
tempDir = Deno.makeTempDirSync({ prefix: "quarto-session" });
2237
}
2338

0 commit comments

Comments
 (0)