Skip to content

Commit

Permalink
fallback if snap is targetted (#200)
Browse files Browse the repository at this point in the history
* fallback if snap is targetted

* put code in subfunctions

---------

Co-authored-by: Jean-Loup Maillet <[email protected]>
  • Loading branch information
jloupdef and destitech-com authored Sep 6, 2024
1 parent ef98533 commit 6727f0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Browser {
/// (20 seconds by default).
pub async fn launch(mut config: BrowserConfig) -> Result<(Self, Handler)> {
// Canonalize paths to reduce issues with sandboxing
config.executable = utils::canonicalize(&config.executable).await?;
config.executable = utils::canonicalize_except_snap(config.executable).await?;

// Launch a new chromium instance
let mut child = config.launch()?;
Expand Down
18 changes: 18 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ pub(crate) async fn canonicalize<P: AsRef<Path> + Unpin>(path: P) -> std::io::Re
Ok(dunce::simplified(&path).to_path_buf())
}

/// Absolute path
///
pub(crate) fn absolute(path: PathBuf) -> std::io::Result<PathBuf> {
let path = if path.is_absolute() { path } else { std::env::current_dir()?.join(path) };
Ok(dunce::simplified(&path).to_path_buf())
}

/// Canonicalize path except if target binary is snap, in this case only make the path absolute
///
pub(crate) async fn canonicalize_except_snap(path: PathBuf) -> std::io::Result<PathBuf> {
// Canonalize paths to reduce issues with sandboxing
let executable_cleaned: PathBuf = canonicalize(&path).await?;

// Handle case where executable is provided by snap, ignore canonicalize result and only make path absolute
Ok(if executable_cleaned.to_str().unwrap().ends_with("/snap") { absolute(path).unwrap() } else { executable_cleaned })
}


pub(crate) mod base64 {
use base64::engine::general_purpose::STANDARD;
use base64::{DecodeError, Engine};
Expand Down

0 comments on commit 6727f0f

Please sign in to comment.