Ver código fonte

fix: allow return value of fs::canonicalize on fs scope, closes #4130 (#4188)

Lucas Fernandes Nogueira 3 anos atrás
pai
commit
78f2565e14
2 arquivos alterados com 10 adições e 1 exclusões
  1. 5 0
      .changes/fix-fs-scope-windows.md
  2. 5 1
      core/tauri/src/scope/fs.rs

+ 5 - 0
.changes/fix-fs-scope-windows.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Allow the canonical, absolute form of a path for the filesystem scope on Windows if `std::fs::canonicalize` returns a path, fallback to `\\?\$PATH`.

+ 5 - 1
core/tauri/src/scope/fs.rs

@@ -69,7 +69,11 @@ fn push_pattern<P: AsRef<Path>>(list: &mut HashSet<Pattern>, pattern: P) -> crat
   list.insert(Pattern::new(&path.to_string_lossy())?);
   #[cfg(windows)]
   {
-    list.insert(Pattern::new(&format!("\\\\?\\{}", path.display()))?);
+    if let Ok(p) = std::fs::canonicalize(&path) {
+      list.insert(Pattern::new(&p.to_string_lossy())?);
+    } else {
+      list.insert(Pattern::new(&format!("\\\\?\\{}", path.display()))?);
+    }
   }
   Ok(())
 }