fix: resolve symlinks in project directory paths (#1316)
* fix: resolve symlinks in project directory paths OpenCode stores sessions using the canonical (realpath) directory, but OpenChamber passed the unresolved symlink path in several places. The string-match directory filter would fail when a project was accessed via a symlink, making sessions invisible. Changes: - Add safeRealpathSync to settings normalization — project paths and lastDirectory are canonicalized at persistence time - Add Express middleware before the API proxy to resolve symlinks in ?directory= query params on in-flight requests - Resolve symlinks in /api/fs/list so the directory browser returns canonical paths, allowing the "already added" check to work correctly - Reconcile the in-memory projects store when the server responds with normalized paths, preventing temporary duplicates Fixes #1315 * fix: avoid sync realpath in opencode proxy --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
90b3d4760e
commit
c5862cc6ee
@@ -3,6 +3,7 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
||||
os,
|
||||
path,
|
||||
processLike,
|
||||
realpathSync,
|
||||
tunnelBootstrapTtlDefaultMs,
|
||||
tunnelBootstrapTtlMinMs,
|
||||
tunnelBootstrapTtlMaxMs,
|
||||
@@ -32,7 +33,19 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
const normalizePathForPersistence = (value) => {
|
||||
// Resolve symlinks, falling back to the original value on failure.
|
||||
const safeRealpathSync = (value) => {
|
||||
if (!realpathSync || typeof value !== 'string' || !value) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
return realpathSync(value);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
const normalizePathForPersistence = (value, options = {}) => {
|
||||
if (typeof value !== 'string') {
|
||||
return value;
|
||||
}
|
||||
@@ -47,11 +60,13 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
const resolved = options.resolveRealpath === false ? trimmed : safeRealpathSync(trimmed);
|
||||
|
||||
if (processLike.platform !== 'win32') {
|
||||
return trimmed;
|
||||
return resolved;
|
||||
}
|
||||
|
||||
return trimmed.replace(/\//g, '\\');
|
||||
return resolved.replace(/\//g, '\\');
|
||||
};
|
||||
|
||||
const areStringArraysEqual = (a, b) => {
|
||||
@@ -107,8 +122,8 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
||||
const candidate = entry;
|
||||
const id = typeof candidate.id === 'string' ? candidate.id.trim() : '';
|
||||
const rawPath = typeof candidate.path === 'string' ? candidate.path.trim() : '';
|
||||
const resolvedPath = rawPath ? path.resolve(normalizeDirectoryPath(rawPath)) : '';
|
||||
const normalizedPath = resolvedPath ? normalizePathForPersistence(resolvedPath) : '';
|
||||
const resolvedPath = rawPath ? safeRealpathSync(path.resolve(normalizeDirectoryPath(rawPath))) : '';
|
||||
const normalizedPath = resolvedPath ? normalizePathForPersistence(resolvedPath, { resolveRealpath: false }) : '';
|
||||
const label = typeof candidate.label === 'string' ? candidate.label.trim() : '';
|
||||
const icon = typeof candidate.icon === 'string' ? candidate.icon.trim() : '';
|
||||
const iconImage = candidate.iconImage && typeof candidate.iconImage === 'object'
|
||||
|
||||
Reference in New Issue
Block a user