From 501f380644638318a5eb6e379fa49df3a4c5ba40 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Tue, 4 Nov 2025 11:09:47 +0100 Subject: [PATCH] Simplifies path handling for Windows Refactors the code to leverage `path.join` for cross-platform path manipulation, especially improving handling of absolute paths on Windows. Removes redundant normalizations and simplifies the logic for determining temporary directories. This change ensures consistent behavior across different operating systems and reduces code complexity. --- src/core/TempDirectoryManager.ts | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/core/TempDirectoryManager.ts b/src/core/TempDirectoryManager.ts index 59d63ea..4efc75e 100644 --- a/src/core/TempDirectoryManager.ts +++ b/src/core/TempDirectoryManager.ts @@ -35,26 +35,9 @@ export class TempDirectoryManager { * Handles absolute paths correctly on Windows */ private getPluginDir(): string { - // Use path.join to properly handle absolute paths - const segments = [this.vaultPath, this.configDir, 'plugins', this.pluginName]; - let result = ''; - - for (const segment of segments) { - if (!segment) continue; - - if (path.isAbsolute(segment)) { - // This segment is absolute, use it as the new base - result = segment; - } else if (result) { - // Join with the current result - result = path.join(result, segment); - } else { - // First relative segment - result = segment; - } - } - - return normalizePath(path.normalize(result)); + // path.join automatically handles absolute paths correctly + const result = path.join(this.vaultPath, this.configDir, 'plugins', this.pluginName); + return normalizePath(result); } /** @@ -135,9 +118,8 @@ export class TempDirectoryManager { const normalizedDirPath = normalizePath(dirPath); const normalizedPluginDir = normalizePath(pluginDir); - // Use path.join to properly handle absolute paths - const tempImagesDir = normalizePath(path.normalize(path.join(normalizedPluginDir, PLUGIN_DIRS.TEMP_IMAGES))); - const tempPandocDir = normalizePath(path.normalize(path.join(normalizedPluginDir, PLUGIN_DIRS.TEMP_PANDOC))); + const tempImagesDir = normalizePath(path.join(normalizedPluginDir, PLUGIN_DIRS.TEMP_IMAGES)); + const tempPandocDir = normalizePath(path.join(normalizedPluginDir, PLUGIN_DIRS.TEMP_PANDOC)); return normalizedDirPath.startsWith(tempImagesDir) || normalizedDirPath.startsWith(tempPandocDir);