Enhances path handling and file resolution #5

Merged
AlexKucera merged 36 commits from 1.3.0 into master 2025-09-25 16:47:12 +02:00
Showing only changes of commit c4062d66b0 - Show all commits
+7 -3
View File
1
@@ -102,8 +102,12 @@ export class TempDirectoryManager {
*/
public isPluginTempDir(dirPath: string): boolean {
const pluginDir = this.getPluginDir();
// Simple string comparison for temp directory validation
return dirPath.startsWith(pluginDir) &&
(dirPath.includes(PLUGIN_DIRS.TEMP_IMAGES) || dirPath.includes(PLUGIN_DIRS.TEMP_PANDOC));
const normalizedDirPath = normalizePath(dirPath);
coderabbitai[bot] commented 2025-09-25 16:51:34 +02:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🔴 Critical

adapter.list/remove must use vault-relative too

Same issue during cleanup; operate with vault-relative path to list and remove files correctly.

-      const exists = await this.app.vault.adapter.exists(tempDir);
-      if (exists) {
-        const list = await this.app.vault.adapter.list(tempDir);
+      const rel = tempDir.startsWith(this.vaultPath)
+        ? tempDir.substring(this.vaultPath.length).replace(/^[/\\]+/, '')
+        : tempDir;
+      const exists = await this.app.vault.adapter.exists(rel);
+      if (exists) {
+        const list = await this.app.vault.adapter.list(rel);
         // Remove only files, not subdirectories (matching current pattern)
         for (const file of list.files) {
           await this.app.vault.adapter.remove(file);
         }
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			const rel = tempDir.startsWith(this.vaultPath)
				? tempDir.substring(this.vaultPath.length).replace(/^[/\\]+/, '')
				: tempDir;
			const exists = await this.app.vault.adapter.exists(rel);
			if (exists) {
				const list = await this.app.vault.adapter.list(rel);
				// Remove only files, not subdirectories (matching current pattern)
				for (const file of list.files) {
					await this.app.vault.adapter.remove(file);
				}
			}
			return true;
🤖 Prompt for AI Agents
In src/core/TempDirectoryManager.ts around lines 68-76, the cleanup currently
calls adapter.list and adapter.remove with paths that may be absolute; change
both calls to use vault-relative paths: pass a vault-relative tempDir into
adapter.list, then when iterating list.files map each entry to its
vault-relative path before calling adapter.remove so the adapter operates on
vault-relative paths consistently (i.e., compute/normalize vault-relative paths
for list and remove and use those).
_⚠️ Potential issue_ | _🔴 Critical_ **adapter.list/remove must use vault-relative too** Same issue during cleanup; operate with vault-relative path to list and remove files correctly. ```diff - const exists = await this.app.vault.adapter.exists(tempDir); - if (exists) { - const list = await this.app.vault.adapter.list(tempDir); + const rel = tempDir.startsWith(this.vaultPath) + ? tempDir.substring(this.vaultPath.length).replace(/^[/\\]+/, '') + : tempDir; + const exists = await this.app.vault.adapter.exists(rel); + if (exists) { + const list = await this.app.vault.adapter.list(rel); // Remove only files, not subdirectories (matching current pattern) for (const file of list.files) { await this.app.vault.adapter.remove(file); } } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const rel = tempDir.startsWith(this.vaultPath) ? tempDir.substring(this.vaultPath.length).replace(/^[/\\]+/, '') : tempDir; const exists = await this.app.vault.adapter.exists(rel); if (exists) { const list = await this.app.vault.adapter.list(rel); // Remove only files, not subdirectories (matching current pattern) for (const file of list.files) { await this.app.vault.adapter.remove(file); } } return true; ``` </details> <!-- suggestion_end --> <details> <summary>🤖 Prompt for AI Agents</summary> ``` In src/core/TempDirectoryManager.ts around lines 68-76, the cleanup currently calls adapter.list and adapter.remove with paths that may be absolute; change both calls to use vault-relative paths: pass a vault-relative tempDir into adapter.list, then when iterating list.files map each entry to its vault-relative path before calling adapter.remove so the adapter operates on vault-relative paths consistently (i.e., compute/normalize vault-relative paths for list and remove and use those). ``` </details> <!-- fingerprinting:phantom:medusa:chinchilla --> <!-- This is an auto-generated comment by CodeRabbit -->
const normalizedPluginDir = normalizePath(pluginDir);
const tempImagesDir = normalizePath([normalizedPluginDir, PLUGIN_DIRS.TEMP_IMAGES].join('/'));
const tempPandocDir = normalizePath([normalizedPluginDir, PLUGIN_DIRS.TEMP_PANDOC].join('/'));
return normalizedDirPath.startsWith(tempImagesDir) ||
normalizedDirPath.startsWith(tempPandocDir);
}
}