-
Notifications
You must be signed in to change notification settings - Fork 2
WIP:EIM-277 rename activation script in case there is already one present #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,24 @@ pub fn create_activation_shell_script( | |
| ensure_path(file_path).map_err(|e| e.to_string())?; | ||
| let mut filename = PathBuf::from(file_path); | ||
| filename.push(format!("activate_idf_{}.sh", idf_version)); | ||
| filename = match filename.try_exists() { | ||
| Ok(true) => { | ||
|
|
||
| let mut new_filename = filename.clone(); | ||
| new_filename.set_file_name(format!("activate_idf_{}_{}.sh", idf_version, uuid::Uuid::new_v4())); | ||
| info!( | ||
| "Activation script already exists at {}, changing name to {}.", | ||
| filename.display(), | ||
| new_filename.display() | ||
| ); | ||
| new_filename | ||
| } | ||
| Ok(false) => { filename} | ||
| Err(e) => { | ||
| error!("Failed to check if file exists: {}", e); | ||
| filename | ||
| } | ||
| }; | ||
| let template = include_str!("../../bash_scripts/activate_idf_template.sh"); | ||
| let mut tera = Tera::default(); | ||
| if let Err(e) = tera.add_raw_template("activate_idf_template", template) { | ||
|
|
@@ -335,6 +353,24 @@ fn create_powershell_profile( | |
| } | ||
| let mut filename = PathBuf::from(profile_path); | ||
| filename.push(format!("Microsoft.{}.PowerShell_profile.ps1", idf_version)); | ||
| filename = match filename.try_exists() { | ||
| Ok(true) => { | ||
|
|
||
| let mut new_filename = filename.clone(); | ||
| new_filename.set_file_name(format!("Microsoft.{}.PowerShell_profile_{}.ps1", idf_version, uuid::Uuid::new_v4())); | ||
| info!( | ||
| "Profile already exists at {}, changing name to {}.", | ||
| filename.display(), | ||
| new_filename.display() | ||
| ); | ||
| new_filename | ||
| } | ||
| Ok(false) => { filename} | ||
| Err(e) => { | ||
| error!("Failed to check if file exists: {}", e); | ||
| filename | ||
| } | ||
| }; | ||
|
Comment on lines
+356
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block has the same issues as the one in As suggested in the other comment, this logic should be extracted to a shared helper function. You can then replace this block with a call to the suggested
|
||
| fs::write(&filename, rendered).expect("Unable to write file"); | ||
| Ok(filename.display().to_string()) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block has two issues:
create_powershell_profileon lines 356-373. This should be extracted into a helper function to improve maintainability.filename. This could lead to overwriting an existing file, which contradicts the goal of the PR ("we will now not rewrite it"). It would be safer to propagate the error.I suggest creating a helper function that addresses both points. You could add this function within
src-tauri/src/lib/mod.rs:With this helper function, you can replace this entire
matchblock with:filename = ensure_unique_filename(filename, "Activation script").map_err(|e| e.to_string())?;