Skip to content

Commit

Permalink
fix(sync): ensure the sync daemon env is configured correctly
Browse files Browse the repository at this point in the history
Make sure that `MUTAGEN_SSH_PATH` pointing to the faus ssh is always set
when a native Mutagen daemon is used.

Co-authored-by: Steffen Neubauer <[email protected]>
  • Loading branch information
vvagaytsev and stefreak committed Jul 23, 2024
1 parent f651b2c commit 35b95db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
22 changes: 9 additions & 13 deletions core/src/mutagen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,10 @@ class _MutagenMonitor extends TypedEventEmitter<MonitorEvents> {
const mutagenOpts = [mutagenPath, "sync", "monitor", "--template", "{{ json . }}", "--long"]
log.silly(() => `Spawning mutagen using respawn: "${mutagenOpts.join(" ")}"`)

const sshPath = await getMutagenSshPath(log)
if (sshPath) {
log.debug(`Mutagen will be used with the faux SSH transport located in ${sshPath}`)
}
const proc = respawn(mutagenOpts, {
cwd: dataDir,
name: "mutagen",
env: getMutagenEnv({ dataDir, logLevel: "debug", sshPath }),
env: getMutagenEnv({ dataDir, logLevel: "debug" }, log),
maxRestarts,
sleep: 3000,
kill: 500,
Expand Down Expand Up @@ -708,7 +704,7 @@ export class Mutagen {
cwd: this.dataDir,
args,
log: this.log,
env: getMutagenEnv({ dataDir: this.dataDir }),
env: await getMutagenEnv({ dataDir: this.dataDir }, this.log),
})
} catch (err) {
if (!(err instanceof ChildProcessError)) {
Expand Down Expand Up @@ -892,24 +888,24 @@ export function getMutagenDataDir({ ctx, log }: MutagenDaemonParams) {
*/
type MutagenEnv = {
MUTAGEN_DATA_DIRECTORY: string
MUTAGEN_LOG_LEVEL?: string
MUTAGEN_SSH_PATH?: string
MUTAGEN_LOG_LEVEL?: string
}

type MutagenEnvValues = {
dataDir: string
logLevel?: string
sshPath?: string
}

export function getMutagenEnv({ dataDir, logLevel, sshPath }: MutagenEnvValues): MutagenEnv {
const env: MutagenEnv = { MUTAGEN_DATA_DIRECTORY: dataDir }
export async function getMutagenEnv({ dataDir, logLevel }: MutagenEnvValues, log: Log): Promise<MutagenEnv> {
const sshPath = await getMutagenSshPath(log)
if (sshPath) {
log.debug(`Mutagen will be used with the faux SSH transport located in ${sshPath}`)
}
const env: MutagenEnv = { MUTAGEN_DATA_DIRECTORY: dataDir, MUTAGEN_SSH_PATH: sshPath }
if (!!logLevel) {
env.MUTAGEN_LOG_LEVEL = logLevel
}
if (!!sshPath) {
env.MUTAGEN_SSH_PATH = sshPath
}
return env
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/kubernetes/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const syncPause: PluginCommand = {
await mutagen.exec({
cwd: dataDir,
log,
env: getMutagenEnv({ dataDir }),
env: await getMutagenEnv({ dataDir }, log),
args: ["sync", "pause", sessionName],
})
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export const syncResume: PluginCommand = {
await mutagen.exec({
cwd: dataDir,
log,
env: getMutagenEnv({ dataDir }),
env: await getMutagenEnv({ dataDir }, log),
args: ["sync", "resume", sessionName],
})
}
Expand All @@ -148,7 +148,7 @@ async function getMutagenSyncSessions({ mutagen, dataDir, log }: { mutagen: Plug
const res = await mutagen.exec({
cwd: dataDir,
log,
env: getMutagenEnv({ dataDir }),
env: await getMutagenEnv({ dataDir }, log),
args: ["sync", "list", "--template={{ json . }}"],
})
return parseSyncListResult(res)
Expand Down

0 comments on commit 35b95db

Please sign in to comment.