Skip to content

Fix: OSError in mintty terminal on Windows#598

Open
pzhlkj6612 wants to merge 1 commit intoacidanthera:masterfrom
pzhlkj6612:fix/mintty-crash
Open

Fix: OSError in mintty terminal on Windows#598
pzhlkj6612 wants to merge 1 commit intoacidanthera:masterfrom
pzhlkj6612:fix/mintty-crash

Conversation

@pzhlkj6612
Copy link
Copy Markdown

Hi! Thank you for maintaining tools in this repository.

I'm using Git Bash on Windows. Git Bash is a mintty terminal 1. The script "macrecovery.py" raised OSError. I have tried replacing os.get_terminal_size() with shutil.get_terminal_size() and it works! My tests are as follows:

After applying this PR:

$ ./Utilities/macrecovery/macrecovery.py download
Downloading 696-28424...
Saving .../RecoveryImage/BaseSystem.chunklist to com.apple.recovery.boot\BaseSystem.chunklist...
0.0/0.0 MB |==========================| 100.0% downloaded
Download complete!
Saving .../RecoveryImage/BaseSystem.dmg to com.apple.recovery.boot\BaseSystem.dmg...
56.0/843.4 MB |=                         | 6.6% downloaded

Before:

$ ./Utilities/macrecovery/macrecovery.py download
Downloading 696-28424...
Saving .../RecoveryImage/BaseSystem.chunklist to com.apple.recovery.boot\BaseSystem.chunklist...
Traceback (most recent call last):
  File "...\OpenCorePkg\Utilities\macrecovery\macrecovery.py", line 516, in <module>
    sys.exit(main())
             ~~~~^^
  File "...\OpenCorePkg\Utilities\macrecovery\macrecovery.py", line 504, in main
    return action_download(args)
  File "...\OpenCorePkg\Utilities\macrecovery\macrecovery.py", line 300, in action_download
    cnkpath = save_image(info[INFO_SIGN_LINK], info[INFO_SIGN_SESS], cnkname, args.outdir)
  File "...\OpenCorePkg\Utilities\macrecovery\macrecovery.py", line 228, in save_image
    terminalsize = max(os.get_terminal_size().columns - TERMINAL_MARGIN, 0)
                       ~~~~~~~~~~~~~~~~~~~~^^
OSError: [WinError 6] The handle is invalid

Both $COLUMNS and $LINES are defined. The docs of shutil.get_terminal_size say that it uses these two environment variables 2:

$ echo "$COLUMNS, $LINES"
118, 30

The environment:

  • Windows 11 23H2 (10.0.22631.4317)
  • mintty 3.7.0 (x86_64-pc-msys) [Windows 22631]
  • git version 2.44.0.windows.1

That script works fine in other terminals on my computer. Hope this PR won't break anything.

Footnotes

  1. ... In Git-for-Windows, mintty is installed by default and invoked as "Git Bash"... | https://mintty.github.io/

  2. https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size

Replaced "os.get_terminal_size()" with "shutil.get_terminal_size()" and
  it works fine. Both $COLUMNS and $LINES are defined.

I use Git-Bash:

> In Git-for-Windows, mintty is installed by default and invoked as "Git Bash".
>
> https://mintty.github.io/
Copy link
Copy Markdown
Member

@mikebeaton mikebeaton left a comment

Choose a reason for hiding this comment

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

A quick Google on the availability of the two versions and the difference between them makes me think this PR looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants