Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate machine socket path for linux #3070

Merged
merged 1 commit into from Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions extensions/podman/src/extension.ts
Expand Up @@ -36,7 +36,7 @@ import { getSocketCompatibility } from './compatibility-mode';
type StatusHandler = (name: string, event: extensionApi.ProviderConnectionStatus) => void;

const listeners = new Set<StatusHandler>();
const podmanMachineSocketsDirectoryMac = path.resolve(os.homedir(), appHomeDir(), 'machine');
const podmanMachineSocketsDirectory = path.resolve(os.homedir(), appHomeDir(), 'machine');
const podmanMachineSocketsSymlinkDirectoryMac = path.resolve(os.homedir(), '.podman');
const MACOS_MAX_SOCKET_PATH_LENGTH = 104;
let storedExtensionContext;
Expand Down Expand Up @@ -160,6 +160,8 @@ async function updateMachines(provider: extensionApi.Provider): Promise<void> {
if (!socketPath) {
if (isMac()) {
socketPath = calcMacosSocketPath(machineName);
} else if (isLinux()) {
socketPath = calcLinuxSocketPath(machineName);
} else if (isWindows()) {
socketPath = calcWinPipeName(machineName);
}
Expand Down Expand Up @@ -255,13 +257,17 @@ async function updateContainerConfiguration(

function calcMacosSocketPath(machineName: string): string {
// max length for the path of a socket in macos is 104 chars
let socketPath = path.resolve(podmanMachineSocketsDirectoryMac, machineName, 'podman.sock');
let socketPath = path.resolve(podmanMachineSocketsDirectory, machineName, 'podman.sock');
if (socketPath.length > MACOS_MAX_SOCKET_PATH_LENGTH) {
socketPath = path.resolve(podmanMachineSocketsSymlinkDirectoryMac, machineName, 'podman.sock');
}
return socketPath;
}

function calcLinuxSocketPath(machineName: string): string {
return path.resolve(podmanMachineSocketsDirectory, machineName, 'podman.sock');
}

function calcWinPipeName(machineName: string): string {
const name = machineName.startsWith('podman') ? machineName : 'podman-' + machineName;
return `//./pipe/${name}`;
Expand Down