Skip to content

Commit 009341e

Browse files
committed
refactor: apply reviewer feedback
- Make file existence and metadata checks platform-agnostic (not Android-only) - Remove verbose debug logging that doesn't add value - Simplify error messages to reduce spam - Keep Android-specific context only where necessary
1 parent 63701d5 commit 009341e

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

crates/tauri/src/protocol/asset.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,16 @@ fn get_response(
4848
return resp.status(403).body(Vec::new().into()).map_err(Into::into);
4949
}
5050

51-
// On Android, log additional information for debugging external storage access
52-
#[cfg(target_os = "android")]
53-
{
54-
if path.starts_with("/storage/emulated/0/Android/data/") {
55-
log::debug!("Attempting to access Android external storage path: {}", path);
56-
57-
// Check if the file exists before trying to open it
58-
if !std::path::Path::new(&path).exists() {
59-
log::error!("File does not exist at path: {}", path);
60-
return resp.status(404).body(Vec::new().into()).map_err(Into::into);
61-
}
62-
63-
// Check if we have read permissions
64-
match std::fs::metadata(&path) {
65-
Ok(metadata) => {
66-
log::debug!("File metadata for {}: size={}, readonly={}", path, metadata.len(), metadata.permissions().readonly());
67-
}
68-
Err(e) => {
69-
log::error!("Failed to get metadata for {}: {}", path, e);
70-
return resp.status(500).body(format!("Failed to access file metadata: {}", e).into_bytes().into()).map_err(Into::into);
71-
}
72-
}
73-
}
51+
// Check if the file exists before trying to open it
52+
if !std::path::Path::new(&path).exists() {
53+
log::error!("File does not exist at path: {}", path);
54+
return resp.status(404).body(Vec::new().into()).map_err(Into::into);
55+
}
56+
57+
// Check if we have read permissions
58+
if let Err(e) = std::fs::metadata(&path) {
59+
log::error!("Failed to get metadata for {}: {}", path, e);
60+
return resp.status(500).body(format!("Failed to access file metadata: {}", e).into_bytes().into()).map_err(Into::into);
7461
}
7562

7663
let (mut file, len, mime_type, read_bytes) = crate::async_runtime::safe_block_on(async move {
@@ -81,7 +68,6 @@ fn get_response(
8168
{
8269
if path.starts_with("/storage/emulated/0/Android/data/") {
8370
log::error!("Failed to open Android external storage file '{}': {}. This may be due to missing storage permissions or the file being inaccessible from the webview context.", path, e);
84-
log::error!("Ensure your app has the necessary storage permissions and the file is in an accessible location.");
8571
}
8672
}
8773
return Err(e.into());

0 commit comments

Comments
 (0)