-
Notifications
You must be signed in to change notification settings - Fork 14
Cut ~59s from every offline install by not shelling out to Get-Disk #66
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """_disk_number: fast diskpart parse, with a Get-Disk fallback for localisation. | ||
|
|
||
| Pins the behaviour that made the fast path safe to adopt -- it must agree with | ||
| Get-Disk in BOTH states, because _detach() treats None as proof the disk is gone. | ||
| A fast path that returned None for an *attached* disk would make _detach report | ||
| success while the image stayed mounted. | ||
| """ | ||
| from unittest import mock | ||
|
|
||
| import ext4_symlink as es | ||
|
|
||
|
|
||
| ATTACHED = """ | ||
| DiskPart successfully selected the virtual disk file. | ||
|
|
||
| Device type ID: 3 (Unknown) | ||
| Virtual size: 128 GB | ||
| Physical size: 3530 MB | ||
| Filename: C:\\ProgramData\\BlueStacks_nxt\\Engine\\Tiramisu64\\Data.vhdx | ||
| Is Child: No | ||
| Associated disk#: 2 | ||
| """ | ||
|
|
||
| DETACHED = """ | ||
| DiskPart successfully selected the virtual disk file. | ||
|
|
||
| Device type ID: 3 (Unknown) | ||
| Virtual size: 128 GB | ||
| Filename: C:\\ProgramData\\BlueStacks_nxt\\Engine\\Tiramisu64\\Data.vhdx | ||
| Is Child: No | ||
| Associated disk#: | ||
| """ | ||
|
|
||
| # A localised install prints the same data under translated field names. | ||
| LOCALISED = """ | ||
| DiskPart hat die Datei für den virtuellen Datenträger ausgewählt. | ||
|
|
||
| Datenträger 2 | ||
| """ | ||
|
|
||
|
|
||
| def _completed(stdout): | ||
| return mock.Mock(stdout=stdout, stderr="", returncode=0) | ||
|
|
||
|
|
||
| def test_attached_returns_disk_number_without_calling_get_disk(): | ||
| with mock.patch.object(es, "_diskpart", return_value=_completed(ATTACHED)), \ | ||
| mock.patch.object(es, "_disk_number_via_get_disk") as slow: | ||
| assert es._disk_number("X.vhdx") == 2 | ||
| slow.assert_not_called() | ||
|
|
||
|
|
||
| def test_detached_returns_none_without_calling_get_disk(): | ||
| # _detach() relies on this: None must mean "gone", not "couldn't tell". | ||
| with mock.patch.object(es, "_diskpart", return_value=_completed(DETACHED)), \ | ||
| mock.patch.object(es, "_disk_number_via_get_disk") as slow: | ||
| assert es._disk_number("X.vhdx") is None | ||
| slow.assert_not_called() | ||
|
|
||
|
|
||
| def test_unrecognised_output_falls_back_to_get_disk(): | ||
| # Must NOT be mistaken for "detached" -- that would let _detach() claim | ||
| # success on a still-mounted image on any non-English Windows. | ||
| with mock.patch.object(es, "_diskpart", return_value=_completed(LOCALISED)), \ | ||
| mock.patch.object(es, "_disk_number_via_get_disk", return_value=7) as slow: | ||
| assert es._disk_number("X.vhdx") == 7 | ||
| slow.assert_called_once() | ||
|
|
||
|
|
||
| def test_parse_flag_distinguishes_detached_from_unparseable(): | ||
| with mock.patch.object(es, "_diskpart", return_value=_completed(DETACHED)): | ||
| assert es._disk_number_via_diskpart("X.vhdx") == (None, True) | ||
| with mock.patch.object(es, "_diskpart", return_value=_completed(LOCALISED)): | ||
| assert es._disk_number_via_diskpart("X.vhdx") == (None, False) | ||
|
|
||
|
|
||
| def test_case_insensitive_field_match(): | ||
| with mock.patch.object(es, "_diskpart", | ||
| return_value=_completed("associated DISK#: 11\n")): | ||
| assert es._disk_number_via_diskpart("X.vhdx") == (11, True) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On localized Windows where the BlueStacks data directory contains the literal
Associated disk#(a valid Windows folder name),detail vdiskstill prints that text as part of the VHD filename even though the actual field label is translated. This unanchored search therefore marks the output as parsed and returnsNoneinstead of falling back to Get-Disk, causing attached disks to be reported as missing and potentially making_detach()report success after a failed detach. Match a complete field line, including its delimiter, rather than any occurrence in the output.Useful? React with 👍 / 👎.