Skip to content

fix: Windows commands - #7

Closed
1fexd wants to merge 1 commit into
mise-plugins:mainfrom
1fexd:main
Closed

fix: Windows commands#7
1fexd wants to merge 1 commit into
mise-plugins:mainfrom
1fexd:main

Conversation

@1fexd

@1fexd 1fexd commented May 22, 2026

Copy link
Copy Markdown

No description provided.

@1fexd 1fexd mentioned this pull request May 22, 2026

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

Copy link
Copy Markdown

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 introduces cross-platform support for reorganizing files after installation, specifically handling differences between Unix-like systems and Windows. While the implementation adds necessary logic for Windows environments, the review identified a significant flaw in the OS detection where the Windows branch would catch all non-Unix systems, making the error handling unreachable. Furthermore, the feedback highlights the need for proper path quoting in shell commands to prevent failures when directory names contain spaces, and suggests using more descriptive boolean variables for better readability and consistency.

Comment thread hooks/post_install.lua
Comment on lines +32 to +53
local not_win = os_type == "darwin" or os_type == "linux"
if not_win then
-- Move current rootPath to temp location
os.execute("mv " .. root_path .. " " .. temp_path)
-- Recreate rootPath with proper structure
os.execute("mkdir -p " .. target_path)
-- Move contents from temp to target
os.execute("mv " .. temp_path .. "/* " .. target_path .. "/")
-- Clean up temp
os.execute("rm -rf " .. temp_path)
elseif not not_win then
-- Move current rootPath to temp location
os.execute("move " .. root_path .. " " .. temp_path)
-- Recreate rootPath with proper structure
os.execute("mkdir " .. target_path)
-- Move contents from temp to target
os.execute("robocopy " .. temp_path .. " " .. target_path .. " /E /MOVE /NFL /NDL /NP /NJH /NJS")
-- Clean up temp
os.execute("rmdir /S /Q " .. temp_path)
else
error("Unsupported OS type: " .. os_type)
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The OS detection logic is flawed: elseif not not_win then is logically equivalent to else, which makes the final else block unreachable and causes the script to attempt Windows-specific commands on any unsupported operating system. Additionally, paths passed to os.execute should be quoted to handle spaces in directory names (e.g., C:\Program Files), which is a common scenario on Windows.

    local is_windows = os_type == "windows"
    local is_unix = os_type == "darwin" or os_type == "linux"
    if is_unix then
        -- Move current rootPath to temp location
        os.execute('mv "' .. root_path .. '" "' .. temp_path .. '"')
        -- Recreate rootPath with proper structure
        os.execute('mkdir -p "' .. target_path .. '"')
        -- Move contents from temp to target
        os.execute('mv "' .. temp_path .. '"/* "' .. target_path .. '/"')
        -- Clean up temp
        os.execute('rm -rf "' .. temp_path .. '"')
    elseif is_windows then
        -- Move current rootPath to temp location
        os.execute('move "' .. root_path .. '" "' .. temp_path .. '"')
        -- Recreate rootPath with proper structure
        os.execute('if not exist "' .. target_path .. '" mkdir "' .. target_path .. '"')
        -- Move contents from temp to target
        os.execute('robocopy "' .. temp_path .. '" "' .. target_path .. '" /E /MOVE /NFL /NDL /NP /NJH /NJS')
        -- Clean up temp
        os.execute('rmdir /S /Q "' .. temp_path .. '"')
    else
        error("Unsupported OS type: " .. os_type)
    end

Comment thread hooks/post_install.lua
Comment on lines +61 to +63
if not_win then
os.execute("chmod +x " .. file.join_path(target_path, "bin", "*") .. " 2>/dev/null || true")
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Update the condition to use is_unix and ensure the path in os.execute is quoted. Note that the wildcard * must remain outside the double quotes for the shell to expand it correctly.

    if is_unix then
        os.execute('chmod +x "' .. file.join_path(target_path, "bin") .. '"/* 2>/dev/null || true')
    end

Comment thread hooks/post_install.lua
error("Unsupported OS type: " .. os_type)
end

local bin_name = not_win and "sdkmanager" or "sdkmanager.bat"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Use the is_unix variable for better readability and consistency with the corrected OS detection logic.

    local bin_name = is_unix and "sdkmanager" or "sdkmanager.bat"

@jdx

jdx commented Jul 16, 2026

Copy link
Copy Markdown
Member

Superseded by #9, which adds Windows installation support and verifies it in CI on windows-latest. Thanks for contributing the alternative implementation and review findings.

This comment was generated by an AI coding assistant.

@jdx jdx closed this Jul 16, 2026
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