Skip to content

Commit

Permalink
Validate environment variable on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernthedev committed Jul 16, 2024
1 parent 20e4fda commit 3294980
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/commands/restore.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{env, fs::File, io::Read, path::{Path, PathBuf}};
use std::{
env,
fs::File,
io::Read,
path::{Path, PathBuf},

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

unused import: `PathBuf`

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

unused import: `PathBuf`

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

unused import: `PathBuf`

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

unused import: `PathBuf`

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (macos-13)

unused import: `PathBuf`

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (macos-13)

unused import: `PathBuf`

Check warning on line 5 in src/commands/restore.rs

View workflow job for this annotation

GitHub Actions / build (macos-13)

unused import: `PathBuf`
};

use clap::Args;

Expand Down Expand Up @@ -116,17 +121,21 @@ pub fn validate_ndk(package: &PackageConfig) -> Result<()> {
return Ok(());
};

let mut ndk_path_str = String::new();

// early return, the file doesn't exist nothing to validate
let ndk_file_path = Path::new("./ndkpath.txt");
if !ndk_file_path.exists() {
return Ok(());
let ndk_path = Path::new("./ndkpath.txt");
if ndk_path.exists() {
let mut ndk_file = File::open(ndk_path)?;

ndk_file.read_to_string(&mut ndk_path_str)?;
// validate environment variable if possible
} else if let Some(ndk_path_env) =
std::env::var_os("ANDROID_NDK_HOME").or_else(|| std::env::var_os("ANDROID_NDK_LATEST_HOME"))
{
ndk_path_str = ndk_path_env.to_str().unwrap().to_string();
}

let mut ndk_file = File::open(ndk_file_path)?;

let mut ndk_path_str = String::new();
ndk_file.read_to_string(&mut ndk_path_str)?;

let ndk_path = Path::new(ndk_path_str.trim());
if !ndk_path.exists() {
bail!("NDK Path {} does not exist!", ndk_path.display());
Expand Down

0 comments on commit 3294980

Please sign in to comment.