Эх сурвалжийг харах

fix(core): fix check temp path permission on mac os, fix #6256 (#9588)

* fix: check temp path permission on mac os

* chore: format code
Jerry 1 жил өмнө
parent
commit
8ee8f09390

+ 5 - 0
.changes/check-permission-on-macos.md

@@ -0,0 +1,5 @@
+---
+"tauri": "patch:bug"
+---
+
+Fix check temporary path permission on macos.

+ 1 - 1
core/tauri/src/api/path.rs

@@ -293,7 +293,7 @@ pub fn resolve_path<P: AsRef<Path>>(
       BaseDirectory::App => app_config_dir(config),
       #[allow(deprecated)]
       BaseDirectory::Log => app_log_dir(config),
-      BaseDirectory::Temp => Some(temp_dir()),
+      BaseDirectory::Temp => temp_dir().canonicalize().ok(),
       BaseDirectory::AppConfig => app_config_dir(config),
       BaseDirectory::AppData => app_data_dir(config),
       BaseDirectory::AppLocalData => app_local_data_dir(config),

+ 1 - 1
core/tauri/src/endpoints/operating_system.rs

@@ -42,7 +42,7 @@ impl Cmd {
   }
 
   fn tempdir<R: Runtime>(_context: InvokeContext<R>) -> super::Result<PathBuf> {
-    Ok(std::env::temp_dir())
+    Ok(std::env::temp_dir().canonicalize()?)
   }
 
   fn locale<R: Runtime>(_context: InvokeContext<R>) -> super::Result<Option<String>> {

+ 25 - 0
core/tauri/src/scope/fs.rs

@@ -391,4 +391,29 @@ mod tests {
       assert!(scope.is_allowed("C:\\home\\tauri\\anyfile"));
     }
   }
+
+  #[cfg(unix)]
+  #[test]
+  fn check_temp_dir() {
+    use std::{
+      env::temp_dir,
+      fs::{remove_file, write},
+    };
+
+    let scope = new_scope();
+    scope
+      .allow_directory(temp_dir().canonicalize().unwrap(), true)
+      .unwrap();
+
+    let test_temp_file = temp_dir().canonicalize().unwrap().join("tauri_test_file");
+    if test_temp_file.exists() {
+      remove_file(test_temp_file.clone()).unwrap();
+    }
+
+    assert!(scope.is_allowed(test_temp_file.clone()));
+
+    write(test_temp_file.clone(), ".").unwrap();
+
+    assert!(scope.is_allowed(test_temp_file.clone()));
+  }
 }