Skip to content

Conversation

@Hahihula
Copy link
Collaborator

@Hahihula Hahihula commented Oct 6, 2025

In case there is already activation script in place (user installs same IDF version to different location) we will now not rewrite it.
Do not merge. This needs to be reworked as this way it will broke the named workflow.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Hahihula, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a potential issue where installing the same IDF version multiple times could lead to the overwriting of previously generated activation scripts and PowerShell profiles. It implements a safeguard that checks for the existence of these files and, if found, renames them by appending a Universally Unique Identifier (UUID) to their names. This ensures that all generated scripts are preserved, providing a more stable and predictable installation experience without data loss.

Highlights

  • Activation Script Renaming: The pull request introduces a mechanism to rename activation scripts if a file with the same name already exists. Instead of overwriting, a UUID is appended to the filename.
  • PowerShell Profile Handling: Similar to activation scripts, PowerShell profile files will now also be renamed with a UUID suffix if a file with the intended name already exists, preventing accidental overwrites.
  • Improved Installation Robustness: This change enhances the robustness of installations, particularly when installing the same IDF version to different locations, by ensuring existing activation and profile scripts are preserved.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the creation of activation scripts for both shell and PowerShell to avoid overwriting existing files. It introduces a check to see if a script already exists, and if so, generates a new unique filename using a UUID. My review focuses on improving code maintainability by addressing code duplication and enhancing the error handling to prevent potential file overwrites in edge cases. I've suggested extracting the filename generation logic into a shared helper function and propagating errors instead of falling back to a default that could lead to data loss.

Comment on lines +142 to +159
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
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block has two issues:

  1. Code Duplication: The logic for handling existing files is duplicated in create_powershell_profile on lines 356-373. This should be extracted into a helper function to improve maintainability.
  2. Incorrect Error Handling: In case of an error when checking if the file exists, the code falls back to using the original 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:

fn ensure_unique_filename(path: PathBuf, file_type: &str) -> Result<PathBuf, std::io::Error> {
    match path.try_exists() {
        Ok(true) => {
            let stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or_default();
            let extension = path.extension().and_then(|s| s.to_str()).unwrap_or_default();

            let mut new_path = path.clone();
            let new_name = if extension.is_empty() {
                format!("{}_{}", stem, uuid::Uuid::new_v4())
            } else {
                format!("{}_{}.{}", stem, uuid::Uuid::new_v4(), extension)
            };
            new_path.set_file_name(new_name);

            info!(
                "{} already exists at {}, changing name to {}.",
                file_type,
                path.display(),
                new_path.display()
            );
            Ok(new_path)
        }
        Ok(false) => Ok(path),
        Err(e) => {
            error!("Failed to check if file exists: {}. Aborting.", e);
            Err(e)
        }
    }
}

With this helper function, you can replace this entire match block with:
filename = ensure_unique_filename(filename, "Activation script").map_err(|e| e.to_string())?;

Comment on lines +356 to +373
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
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block has the same issues as the one in create_activation_shell_script (lines 142-159): code duplication and incorrect error handling.

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 ensure_unique_filename function:

filename = ensure_unique_filename(filename, "Profile")?;

@Hahihula Hahihula changed the title EIM-277 rename activation script in case there is already one present WIP:EIM-277 rename activation script in case there is already one present Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants