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
@@ -42,6 +42,18 @@ interface DirectoryTreeProps {
|
||||
disabledPaths?: Iterable<string>;
|
||||
}
|
||||
|
||||
const areStringSetsEqual = (left: Set<string>, right: Set<string>) => {
|
||||
if (left.size !== right.size) {
|
||||
return false;
|
||||
}
|
||||
for (const value of left) {
|
||||
if (!right.has(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
|
||||
currentPath,
|
||||
onSelectPath,
|
||||
@@ -244,7 +256,10 @@ export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
|
||||
const normalizedPath = path.replace(/\\/g, '/');
|
||||
return (stripTrailingSlashes(normalizedPath) as string) ?? normalizedPath;
|
||||
});
|
||||
setPinnedPaths(new Set(normalized));
|
||||
setPinnedPaths((prev) => {
|
||||
const next = new Set(normalized);
|
||||
return areStringSetsEqual(prev, next) ? prev : next;
|
||||
});
|
||||
};
|
||||
|
||||
const loadFromLocalStorage = () => {
|
||||
@@ -326,7 +341,8 @@ export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
|
||||
const filtered = Array.from(prev)
|
||||
.map((path) => (stripTrailingSlashes(path.replace(/\\/g, '/')) as string) ?? path)
|
||||
.filter((path) => isPathWithinHome(path));
|
||||
return new Set(filtered);
|
||||
const next = new Set(filtered);
|
||||
return areStringSetsEqual(prev, next) ? prev : next;
|
||||
});
|
||||
}, [effectiveRoot, isPathWithinHome, stripTrailingSlashes]);
|
||||
|
||||
|
||||
@@ -119,6 +119,13 @@ const persistToLocalStorage = (settings: DesktopSettings) => {
|
||||
}
|
||||
};
|
||||
|
||||
const dispatchSettingsSynced = (settings: DesktopSettings): void => {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent<DesktopSettings>('openchamber:settings-synced', { detail: settings }));
|
||||
};
|
||||
|
||||
type PersistApi = {
|
||||
hasHydrated?: () => boolean;
|
||||
onFinishHydration?: (callback: () => void) => (() => void) | undefined;
|
||||
@@ -1165,9 +1172,7 @@ export const syncDesktopSettings = async (): Promise<void> => {
|
||||
console.warn('applyDesktopUiPreferences failed:', error);
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.dispatchEvent(new CustomEvent<DesktopSettings>('openchamber:settings-synced', { detail: settings }));
|
||||
}
|
||||
dispatchSettingsSynced(settings);
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -1198,6 +1203,7 @@ const _flushSettingsUpdate = async (): Promise<void> => {
|
||||
if (updated) {
|
||||
persistToLocalStorage(updated);
|
||||
applyDesktopUiPreferences(updated);
|
||||
dispatchSettingsSynced(updated);
|
||||
}
|
||||
return;
|
||||
} catch (error) {
|
||||
@@ -1224,6 +1230,7 @@ const _flushSettingsUpdate = async (): Promise<void> => {
|
||||
if (updated) {
|
||||
persistToLocalStorage(updated);
|
||||
applyDesktopUiPreferences(updated);
|
||||
dispatchSettingsSynced(updated);
|
||||
// Invalidate GET cache so next read sees the fresh data
|
||||
_settingsCache = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user