Skip to content

Commit

Permalink
fix(core): fix check temp path permission on mac os, fix #6256 (#9588)
Browse files Browse the repository at this point in the history
* fix: check temp path permission on mac os

* chore: format code
  • Loading branch information
0x-jerry authored Jun 4, 2024
1 parent 78fc841 commit 8ee8f09
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/check-permission-on-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "patch:bug"
---

Fix check temporary path permission on macos.
2 changes: 1 addition & 1 deletion core/tauri/src/api/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/endpoints/operating_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down
25 changes: 25 additions & 0 deletions core/tauri/src/scope/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

0 comments on commit 8ee8f09

Please sign in to comment.