Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(fs): use scope from tauri core #825

Merged
merged 6 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/fs-scope-check-android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fs": patch
---

Fixes scope checks on Android.
29 changes: 26 additions & 3 deletions plugins/fs/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,33 @@ fn push_pattern<P: AsRef<Path>, F: Fn(&str) -> Result<Pattern, glob::PatternErro
) -> crate::Result<()> {
let path: PathBuf = pattern.as_ref().components().collect();
list.insert(f(&path.to_string_lossy())?);
#[cfg(windows)]
#[cfg(any(windows, target_os = "android"))]
{
if let Ok(p) = std::fs::canonicalize(&path) {
let mut path = path;
let mut buf = None;

// attempt to canonicalize parents in case we have a path like `/data/user/0/appid/**`
// where `**` obviously does not exist but we need to canonicalize the parent
let canonicalized = loop {
if let Ok(p) = path.canonicalize() {
break Some(if let Some(buf) = buf { p.join(buf) } else { p });
}

let last = path.iter().rev().next().map(PathBuf::from);
if let Some(mut p) = last {
path.pop();
if let Some(buf) = &buf {
p.push(buf);
}
buf.replace(p);
} else {
break None;
}
};

if let Some(p) = canonicalized {
list.insert(f(&p.to_string_lossy())?);
} else {
} else if cfg!(windows) {
list.insert(f(&format!("\\\\?\\{}", path.display()))?);
}
}
Expand Down Expand Up @@ -203,6 +225,7 @@ impl Scope {
/// Determines if the given path is allowed on this scope.
pub fn is_allowed<P: AsRef<Path>>(&self, path: P) -> bool {
let path = path.as_ref();

let path = if !path.exists() {
crate::Result::Ok(path.to_path_buf())
} else {
Expand Down
Loading