Skip to content

Comments

part: Check whether partition exists before setting GPT attributes#1169

Open
vojtechtrefny wants to merge 1 commit intostoraged-project:masterfrom
vojtechtrefny:master_part-check-part-exists-attributes
Open

part: Check whether partition exists before setting GPT attributes#1169
vojtechtrefny wants to merge 1 commit intostoraged-project:masterfrom
vojtechtrefny:master_part-check-part-exists-attributes

Conversation

@vojtechtrefny
Copy link
Member

@vojtechtrefny vojtechtrefny commented Feb 19, 2026

Other "set" functions already has this check.

Summary by CodeRabbit

  • Bug Fixes
    • Partition attribute operations now include enhanced validation checks and improved error handling mechanisms. These changes ensure that system resources are properly managed and released in all scenarios, significantly improving the reliability and stability of partition attribute modifications, particularly when errors or edge cases occur during operations.

Other "set" functions already have this check.
@vojtechtrefny vojtechtrefny force-pushed the master_part-check-part-exists-attributes branch from 752f021 to bcb74a9 Compare February 19, 2026 15:25
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

📝 Walkthrough

Walkthrough

Modified the bd_part_set_part_attributes function in src/plugins/part.c to add partition retrieval validation using fdisk_get_partition, with improved error handling that ensures fdisk_context closure on failures.

Changes

Cohort / File(s) Summary
Partition attribute validation
src/plugins/part.c
Added partition handle variable and retrieval step in bd_part_set_part_attributes. Function now fetches the target partition with fdisk_get_partition, returns error on fetch failure, and unreferences partition on success. Error handling tightened to ensure fdisk_context closure via close_context before returning on failures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a check to verify partition existence before setting GPT attributes, which aligns with the code modifications and PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/plugins/part.c (1)

2226-2233: Minor: error message is less informative than the equivalent check in peer functions.

The fdisk_get_partition failure message uses the 0-based part_num integer and omits the libfdisk error reason, while bd_part_set_part_name and bd_part_set_part_uuid use the human-readable part path and include strerror_l (-status, c_locale). For consistency:

✏️ Suggested improvement
-        g_set_error (error, BD_PART_ERROR, BD_PART_ERROR_FAIL,
-                     "Failed to get partition '%d' on device '%s'.", part_num, disk);
+        g_set_error (error, BD_PART_ERROR, BD_PART_ERROR_FAIL,
+                     "Failed to get partition '%s' on device '%s': %s",
+                     part, disk, strerror_l (-ret, c_locale));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugins/part.c` around lines 2226 - 2233, The error path after calling
fdisk_get_partition currently logs the 0-based part_num and omits the libfdisk
error text; update the g_set_error call in the fdisk_get_partition failure
branch to reference the human-readable part path (the variable used elsewhere as
"part") instead of part_num and append the libfdisk error string (use
strerror_l(-ret, c_locale) or strerror_l(-status, c_locale) consistent with
other functions). Ensure you still call close_context(cxt) and return FALSE; but
replace the message text to match the style of bd_part_set_part_name /
bd_part_set_part_uuid by including disk, part and the strerror_l(...) detail.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/plugins/part.c`:
- Around line 2226-2233: The error path after calling fdisk_get_partition
currently logs the 0-based part_num and omits the libfdisk error text; update
the g_set_error call in the fdisk_get_partition failure branch to reference the
human-readable part path (the variable used elsewhere as "part") instead of
part_num and append the libfdisk error string (use strerror_l(-ret, c_locale) or
strerror_l(-status, c_locale) consistent with other functions). Ensure you still
call close_context(cxt) and return FALSE; but replace the message text to match
the style of bd_part_set_part_name / bd_part_set_part_uuid by including disk,
part and the strerror_l(...) detail.

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