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.
This commit is contained in:
AlexKucera committed 2025-11-04 11:09:47 +01:00
1 parent 9ca299cafd
commit 501f380644
1 file changed
+5 -23
+5 -23
View File
@@ -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);