Skip to content

Commit a3c8ff9

Browse files
committed
🤖 fix: resolve symlinks in runtime.resolvePath
Change-Id: Ib3ce2b2401e3ce8e0ec0e41579d26be3f79e62a9 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 44654e2 commit a3c8ff9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/node/runtime/LocalRuntime.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,18 @@ export class LocalRuntime implements Runtime {
294294
}
295295
}
296296

297-
resolvePath(filePath: string): Promise<string> {
297+
async resolvePath(filePath: string): Promise<string> {
298298
// Expand tilde to actual home directory path
299299
const expanded = expandTilde(filePath);
300+
const absolute = path.resolve(expanded);
300301

301-
// Resolve to absolute path (handles relative paths like "./foo")
302-
return Promise.resolve(path.resolve(expanded));
302+
try {
303+
// Try to resolve symlinks (canonical path)
304+
return await fsPromises.realpath(absolute);
305+
} catch {
306+
// If file doesn't exist or other error, return absolute path
307+
return absolute;
308+
}
303309
}
304310

305311
normalizePath(targetPath: string, basePath: string): string {

src/node/runtime/SSHRuntime.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ export class SSHRuntime implements Runtime {
392392
// Use shell to expand tildes on remote system
393393
// Bash will expand ~ automatically when we echo the unquoted variable
394394
// This works with BusyBox (doesn't require GNU coreutils)
395-
const command = `bash -c 'p=${shescape.quote(filePath)}; echo $p'`;
395+
// We use readlink -f to resolve symlinks if possible, falling back to just echo
396+
const command = `bash -c 'p=${shescape.quote(filePath)}; readlink -f "$p" 2>/dev/null || echo "$p"'`;
396397
// Use 10 second timeout for path resolution to allow for slower SSH connections
397398
return this.execSSHCommand(command, 10000);
398399
}

0 commit comments

Comments
 (0)