Repository: tauri-apps/tauri
File: core/tauri-utils/src/platform.rs (Rust)

Code before:
/// Computes the resource directory of the current environment.
///
/// On Windows, it's the path to the executable.
///
/// On Linux, when running in an AppImage the `APPDIR` variable will be set to
/// the mounted location of the app, and the resource dir will be
/// `${APPDIR}/usr/lib/${exe_name}`. If not running in an AppImage, the path is
/// `/usr/lib/${exe_name}`.  When running the app from
/// `src-tauri/target/(debug|release)/`, the path is
/// `${exe_dir}/../lib/${exe_name}`.
///
/// On MacOS, it's `${exe_dir}../Resources` (inside .app).
#[allow(unused_variables)]
pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<PathBuf> {
  let exe = current_exe()?;
  let exe_dir = exe.parent().expect("failed to get exe directory");
  let curr_dir = exe_dir.display().to_string();

  let parts: Vec<&str> = curr_dir.split(MAIN_SEPARATOR).collect();

  if (cfg!(target_os = "windows") || parts.contains(&"target"))
    && (parts[parts.len() - 1] == "debug" || parts[parts.len() - 1] == "release")
    && (parts[parts.len() - 2] == "target"
      || parts
        .get(parts.len() - 3)
        .map_or(false, |&dir| dir == "target"))
  {
    // running from the out dir or windows
    return Ok(exe_dir.to_path_buf());
  }

  #[allow(unused_mut, unused_assignments)]
  let mut res = Err(crate::Error::UnsupportedPlatform);

  #[cfg(target_os = "linux")]
  {
    res = if curr_dir.ends_with("/data/usr/bin") {
      // running from the deb bundle dir
      exe_dir
        .join(format!("../lib/{}", package_info.package_name()))
        .canonicalize()
        .map_err(Into::into)
    } else if let Some(appdir) = &env.appdir {
      let appdir: &std::path::Path = appdir.as_ref();
      Ok(PathBuf::from(format!(
        "{}/usr/lib/{}",
        appdir.display(),
        package_info.package_name()
      )))
    } else {
      // running bundle

Review comment (bug):
I believe we can simplify this a bit and we also need to check if indexes are valid

```suggestion
  let parts: Vec<&str> = curr_dir.split(MAIN_SEPARATOR).collect();
  let len = parts.len();
  if cfg!(target_os = "windows")
    || ((len >= 2 && parts[len - 2] == "target") || (len >= 3 && parts[len - 3] == "target"))
      && (parts[len - 1] == "debug" || parts[len - 1] == "release")
```

Code after:
#[cfg(not(test))]
fn is_cargo_output_directory(path: &Path) -> bool {
  path.join(".cargo-lock").exists()
}

#[cfg(test)]
const CARGO_OUTPUT_DIRECTORIES: &[&str] = &["debug", "release", "custom-profile"];

#[cfg(test)]
fn is_cargo_output_directory(path: &Path) -> bool {
  let last_component = path
    .components()
    .last()
    .unwrap()
    .as_os_str()
    .to_str()
    .unwrap();
  CARGO_OUTPUT_DIRECTORIES
    .iter()
    .any(|dirname| &last_component == dirname)
}

/// Computes the resource directory of the current environment.
///
/// On Windows, it's the path to the executable.
///
/// On Linux, when running in an AppImage the `APPDIR` variable will be set to
/// the mounted location of the app, and the resource dir will be
/// `${APPDIR}/usr/lib/${exe_name}`. If not running in an AppImage, the path is
/// `/usr/lib/${exe_name}`.  When running the app from
/// `src-tauri/target/(debug|release)/`, the path is
/// `${exe_dir}/../lib/${exe_name}`.
///
/// On MacOS, it's `${exe_dir}../Resources` (inside .app).
pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<PathBuf> {
  let exe = current_exe()?;
  resource_dir_from(exe, package_info, env)
}

#[allow(unused_variables)]
fn resource_dir_from<P: AsRef<Path>>(
  exe: P,
  package_info: &PackageInfo,
  env: &Env,
) -> crate::Result<PathBuf> {
  let exe_dir = exe.as_ref().parent().expect("failed to get exe directory");
  let curr_dir = exe_dir.display().to_string();

  let parts: Vec<&str> = curr_dir.split(MAIN_SEPARATOR).collect();
  let len = parts.len();