fix copy_bom error message if rsync is not installed
This commit is contained in:
parent
12b2f3b18d
commit
62b8b5889d
@ -1,4 +1,4 @@
|
||||
/// This file defines error number to indicate different errors
|
||||
//! This file defines error number to indicate different errors
|
||||
pub static FILE_NOT_EXISTS_ERROR: i32 = -1;
|
||||
pub static COPY_FILE_ERROR: i32 = -2;
|
||||
pub static INVALID_BOM_FILE_ERROR: i32 = -3;
|
||||
@ -7,3 +7,4 @@ pub static CREATE_SYMLINK_ERROR: i32 = -5;
|
||||
pub static COPY_DIR_ERROR: i32 = -6;
|
||||
pub static INCORRECT_HASH_ERROR: i32 = -7;
|
||||
pub static MISSING_LIBRARY_ERROR: i32 = -8;
|
||||
pub static RSYNC_NOT_FOUND_ERROR: i32 = -9;
|
||||
|
@ -10,6 +10,7 @@ extern crate walkdir;
|
||||
use bom::Bom;
|
||||
use env_logger::Env;
|
||||
use structopt::StructOpt;
|
||||
use util::check_rsync;
|
||||
|
||||
mod bom;
|
||||
mod error;
|
||||
@ -49,6 +50,7 @@ fn main() {
|
||||
// the copy_bom log environmental variable
|
||||
let env = Env::new().filter("OCCLUM_LOG_LEVEL");
|
||||
env_logger::init_from_env(env);
|
||||
check_rsync();
|
||||
|
||||
let copy_bom_option = CopyBomOption::from_args();
|
||||
copy_bom_option.copy_files();
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::error::{
|
||||
COPY_DIR_ERROR, COPY_FILE_ERROR, CREATE_DIR_ERROR, CREATE_SYMLINK_ERROR, FILE_NOT_EXISTS_ERROR,
|
||||
INCORRECT_HASH_ERROR, MISSING_LIBRARY_ERROR,
|
||||
INCORRECT_HASH_ERROR, MISSING_LIBRARY_ERROR, RSYNC_NOT_FOUND_ERROR,
|
||||
};
|
||||
use data_encoding::HEXUPPER;
|
||||
use elf::types::{Type, ET_DYN, ET_EXEC};
|
||||
@ -8,7 +8,7 @@ use regex::Regex;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Output};
|
||||
use std::process::{Command, Output, Stdio};
|
||||
use std::sync::Mutex;
|
||||
use std::vec;
|
||||
|
||||
@ -598,3 +598,21 @@ pub fn warn_on_nonempty_image_dir(image_dir: &str) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check rsync is installed by running command `rsync --version`.
|
||||
/// The exit code should be zero if rsync is installed.
|
||||
/// If rsync is not installed, copy_bom will abort.
|
||||
pub fn check_rsync() {
|
||||
let mut command = Command::new("rsync");
|
||||
command.arg("--version");
|
||||
command.stdout(Stdio::null());
|
||||
if let Ok(status) = command.status() {
|
||||
if let Some(exit_code) = status.code() {
|
||||
if exit_code == 0 {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("rsync is not installed.");
|
||||
std::process::exit(RSYNC_NOT_FOUND_ERROR);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user