Skip to content

Commit cfed5b8

Browse files
fbrvmpminardi
authored andcommitted
store tailscale.tgz and tailscaled.pid in XDG cache/runtime dirs instead of the working directory
1 parent 31d93e6 commit cfed5b8

5 files changed

Lines changed: 45 additions & 9 deletions

File tree

dist/index.js

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/logout/index.js

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/logout/logout.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import * as core from "@actions/core";
55
import * as exec from "@actions/exec";
66
import * as fs from "fs";
7+
import * as os from "os";
8+
import * as path from "path";
79

810
const runnerWindows = "Windows";
911
const runnerMacOS = "macOS";
@@ -61,7 +63,13 @@ async function logout(): Promise<void> {
6163
await exec.exec("net", ["stop", "Tailscale"]);
6264
await exec.exec("taskkill", ["/F", "/IM", "tailscale-ipn.exe"]);
6365
} else {
64-
const pid = fs.readFileSync("tailscaled.pid").toString();
66+
const xdgRuntimeDir =
67+
process.env.XDG_RUNTIME_DIR ||
68+
process.env.XDG_CACHE_HOME ||
69+
path.join(os.homedir(), ".cache");
70+
const pid = fs
71+
.readFileSync(path.join(xdgRuntimeDir, "tailscaled.pid"))
72+
.toString();
6573
if (pid === "") {
6674
throw new Error("pid file empty");
6775
}

src/main.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ const runnerLinux = "Linux";
2222
const runnerWindows = "Windows";
2323
const runnerMacOS = "macOS";
2424

25+
// XDG base directories with sensible defaults.
26+
function xdgCacheDir(): string {
27+
return process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
28+
}
29+
30+
function xdgRuntimeDir(): string {
31+
return process.env.XDG_RUNTIME_DIR || xdgCacheDir();
32+
}
33+
2534
const versionLatest = "latest";
2635
const versionUnstable = "unstable";
2736

@@ -420,7 +429,9 @@ async function installTailscaleLinux(
420429
const downloadUrl = `${baseUrl}/tailscale_${config.resolvedVersion}_${config.arch}.tgz`;
421430
core.info(`Downloading ${downloadUrl}`);
422431

423-
const tarPath = await tc.downloadTool(downloadUrl, "tailscale.tgz");
432+
const tarDest = path.join(xdgCacheDir(), "tailscale.tgz");
433+
fs.mkdirSync(path.dirname(tarDest), { recursive: true });
434+
const tarPath = await tc.downloadTool(downloadUrl, tarDest);
424435

425436
// Verify checksum
426437
const actualSha = await calculateFileSha256(tarPath);
@@ -651,7 +662,9 @@ async function startTailscaleDaemon(config: TailscaleConfig): Promise<void> {
651662
});
652663

653664
// Store PID for cleaning up daemon process in logout.ts.
654-
fs.writeFileSync("tailscaled.pid", `${daemon.pid}`);
665+
const pidFile = path.join(xdgRuntimeDir(), "tailscaled.pid");
666+
fs.mkdirSync(path.dirname(pidFile), { recursive: true });
667+
fs.writeFileSync(pidFile, `${daemon.pid}`);
655668

656669
daemon.unref(); // Ensure daemon doesn't keep Node.js process alive
657670

0 commit comments

Comments
 (0)