Skip to content
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

DEVTOOLS: dumper-companion: Support images with multiple partitions; don't warn about missing deps when not running mac mode #5412

Merged
merged 1 commit into from Nov 11, 2023

Conversation

einstein95
Copy link
Contributor

This was inspired by a LucasArts disc having an additional (empty) HFS partition on the disc. Missing dependency warning was moved so as to not annoy users who only want to use the other modes.

…don't warn about missing deps when not running mac mode

Additionally fix a copy/paste error and remove an unused variable.
Copy link
Contributor

coderabbitai bot commented Nov 11, 2023

Walkthrough

Walkthrough

The recent changes in the dumper-companion.py script have improved its functionality and efficiency. The script now supports partitioned volumes, with the addition of a new function to handle individual partitions. The import of xattr has been moved to a local scope, and its existence is now checked within the collect_forks function. Additionally, file path manipulation within the collect_forks function has been adjusted for better performance.

Changes

File Change Summary
devtools/dumper-companion.py The import of xattr has been moved from the global scope to the collect_forks function. A new function extract_partition has been added to handle individual partitions. The extract_volume function has been modified to handle partitioned volumes. The existence of xattr is now checked within the collect_forks function. File path manipulation in the collect_forks function has been adjusted.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Comment on lines +304 to +341
partitions = []
with source_volume.open(mode="rb") as f:
f.seek(0x200)
if f.read(4) == b"PM\x00\x00":
partition_num = 1
partition_type = ""
while partition_type != "Apple_HFS":
partition_num = 1

while True:
data = f.read(4)
if data == b"PM\x00\x00":
num_partitions, partition_start, partition_size = unpack(
">III", f.read(12)
)
f.seek(32, 1)
partition_type = f.read(32).decode("ascii").split("\x00")[0]
if partition_num <= num_partitions and partition_type != "Apple_HFS":
f.seek(0x20, 1)
partition_type = f.read(0x20).decode("ascii").split("\x00")[0]
if partition_type == "Apple_HFS" and partition_size > 0:
# Found an HFS partition, log it
partitions.append((partition_start * 0x200, partition_size * 0x200))
if partition_num <= num_partitions:
# Move onto the next partition
partition_num += 1
f.seek(partition_num * 0x200 + 4)
f.seek(partition_num * 0x200)
else:
# We found the one we want or there's none
# Finished parsing the partition map
break
f.seek(partition_start * 0x200)
vol.read(f.read(partition_size * 0x200))
else:
# Didn't find the Apple Partition Map, break so we can just
# load the entire image
break

if partitions:
for partition_start, partition_size in partitions:
f.seek(partition_start)
vol.read(f.read(partition_size))
extract_partition(args, vol)
else:
f.seek(0)
vol.read(f.read())
extract_partition(args, vol)

Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for handling partitioned volumes seems sound. It reads the partition map, identifies HFS partitions, and then extracts each partition using the new extract_partition function. However, error handling is missing. Consider adding try-except blocks to handle potential IO errors.

@sev-
Copy link
Member

sev- commented Nov 11, 2023

Thank you!

@sev- sev- merged commit cc8f2d6 into scummvm:master Nov 11, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants