fix: Windows commands - #7
Conversation
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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
| if not_win then | ||
| os.execute("chmod +x " .. file.join_path(target_path, "bin", "*") .. " 2>/dev/null || true") | ||
| end |
There was a problem hiding this comment.
| error("Unsupported OS type: " .. os_type) | ||
| end | ||
|
|
||
| local bin_name = not_win and "sdkmanager" or "sdkmanager.bat" |
|
Superseded by #9, which adds Windows installation support and verifies it in CI on This comment was generated by an AI coding assistant. |
No description provided.