Skip to content

Commit

Permalink
Fix: support encrypted drives (shorten script file names) #1150
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Sep 14, 2024
1 parent 2e9a505 commit 6e8571b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/lib/scriptengine/script_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ pub(crate) fn create_script_file(
pub(crate) fn create_persisted_script_file(
script_text: &Vec<String>,
extension: &str,
) -> Result<String, CargoMakeError> {
match create_persisted_script_file_with_options(script_text, extension, None) {
Ok(value) => Ok(value),
Err(_) => {
let limit = envmnt::get_usize("CARGO_MAKE_SCRIPT_FILE_PATH_MAX_LENGTH", 130);
create_persisted_script_file_with_options(script_text, extension, Some(limit))
}
}
}

fn create_persisted_script_file_with_options(
script_text: &Vec<String>,
extension: &str,
filename_limit: Option<usize>,
) -> Result<String, CargoMakeError> {
let text = script_text.join("\n");

let string_bytes = text.as_bytes();
let bytes = md5::compute(string_bytes);
let file_name = format!("{:x}", bytes);
let mut file_name = format!("{:x}", bytes);

let default_target_directory = envmnt::get_or("CARGO_MAKE_CRATE_TARGET_DIRECTORY", "target");
let directory = envmnt::get_or(
Expand All @@ -42,10 +56,26 @@ pub(crate) fn create_persisted_script_file(
file_path_buf.push(&directory);
file_path_buf.push("_cargo_make_temp");
file_path_buf.push("persisted_scripts");
file_path_buf.push(file_name);
file_path_buf.push(&file_name);
file_path_buf.set_extension(extension);
let mut file_path_string: String = file_path_buf.to_string_lossy().into_owned();

if let Some(limit) = filename_limit {
if file_path_string.len() > limit {
let reduce_size = file_path_string.len() - limit;
if reduce_size < file_name.len() {
file_name = file_name[0..file_name.len() - reduce_size].to_string();

let file_path_string: String = file_path_buf.to_string_lossy().into_owned();
file_path_buf = PathBuf::new();
file_path_buf.push(&directory);
file_path_buf.push("_cargo_make_temp");
file_path_buf.push("persisted_scripts");
file_path_buf.push(file_name);
file_path_buf.set_extension(extension);
file_path_string = file_path_buf.to_string_lossy().into_owned();
}
}
}

let file_path = file_path_string.as_path();
if file_path.exists() {
Expand Down

0 comments on commit 6e8571b

Please sign in to comment.