(sshConfigPath: string)
| 145 | } |
| 146 | |
| 147 | async function resolveSSHConfigWritePath(sshConfigPath: string): Promise<string> { |
| 148 | try { |
| 149 | const stats = await fs.lstat(sshConfigPath); |
| 150 | if (!stats.isSymbolicLink()) { |
| 151 | return sshConfigPath; |
| 152 | } |
| 153 | |
| 154 | try { |
| 155 | // Fast path: realpath follows full chain when target exists. |
| 156 | return await fs.realpath(sshConfigPath); |
| 157 | } catch (error) { |
| 158 | if ((error as NodeJS.ErrnoException | undefined)?.code === "ENOENT") { |
| 159 | // Dangling symlink: target doesn't exist yet. |
| 160 | // Manually follow the chain to find the intended write target. |
| 161 | return await followSymlinkChain(sshConfigPath); |
| 162 | } |
| 163 | throw error; |
| 164 | } |
| 165 | } catch (error) { |
| 166 | if ((error as NodeJS.ErrnoException | undefined)?.code === "ENOENT") { |
| 167 | // Path itself doesn't exist (not even as a symlink). |
| 168 | return sshConfigPath; |
| 169 | } |
| 170 | |
| 171 | throw error; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | async function loadSSHConfigContent( |
| 176 | sshConfigPath: string |
no test coverage detected