Skip to content

Commit

Permalink
fix(agent): handle long socket file path
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jul 27, 2024
1 parent 6fb47d3 commit 27ab382
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createId } from "../deps.ts";
import { dir, brightGreen, wait, green, procfile } from "../deps.ts";

export async function isLogged(): Promise<boolean> {
Expand Down Expand Up @@ -478,6 +479,18 @@ export async function stopServices(cwd: string) {
const services = [];
// deno-lint-ignore no-explicit-any
let infos: Record<string, any> = {};
const id = createId();

if (cwd.length > 64) {
const ln = new Deno.Command("bash", {
args: ["-c", `ln -s ${cwd} $HOME/${id}`],
stdout: "inherit",
stderr: "inherit",
}).spawn();
await ln.status;
}

const home = Deno.env.get("HOME")!;

for (const file of files) {
const manifest = procfile.parse(Deno.readTextFileSync(cwd + "/" + file));
Expand All @@ -491,7 +504,18 @@ export async function stopServices(cwd: string) {
const socket = file.replace("Procfile", ".overmind.sock");

try {
await writeToSocket(cwd + "/" + socket, "stop\n");
await writeToSocket(
(cwd.length > 64 ? `${home}/${id}` : cwd) + "/" + socket,
"stop\n"
);
if (cwd.length > 64) {
const rm = new Deno.Command("bash", {
args: ["-c", `rm $HOME/${id}`],
stdout: "inherit",
stderr: "inherit",
}).spawn();
await rm.status;
}
} catch (e) {
console.log(`Failed to stop ${green(service)}`);
console.log(e);
Expand Down

0 comments on commit 27ab382

Please sign in to comment.