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

* fix: check temp path permission on mac os

* chore: format code
This commit is contained in:
Jerry 2024-06-04 21:02:54 +08:00 committed by GitHub
parent 78fc841370
commit 8ee8f09390
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 2 deletions

View File

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

View File

@ -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),

View File

@ -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>> {

View File

@ -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()));
}
}