Skip to content

Conversation

Copy link

Copilot AI commented Jan 7, 2026

Addresses feedback from PR #44 regarding duplicated device parsing patterns in the grow-ssd service script.

Changes

  • Unified parsing logic: Device path parsing (disk/partition extraction) now happens once upfront instead of in separate branches
  • Simplified control flow: When PKNAME exists, only the disk variable is overridden rather than re-parsing the entire device path
  • Reduced duplication: Eliminated ~15 lines of redundant pattern matching for NVMe and non-NVMe partition schemes

Before/After

Before: Two parallel case statements with duplicate regex patterns

if [ -n "$PKNAME" ]; then
    DISK="/dev/$PKNAME"
    case "$SSD_DEV" in
        /dev/nvme*p[0-9]*) PART=$(sed -E 's/.*p([0-9]+)$/\1/');;
        /dev/*[0-9]) PART=$(sed -E 's/.*[^0-9]([0-9]+)$/\1/');;
    esac
else
    case "$SSD_DEV" in
        /dev/nvme*p[0-9]*) 
            DISK=$(sed -E 's/p[0-9]+$//')
            PART=$(sed -E 's/.*p([0-9]+)$/\1/');;
        /dev/*[0-9])
            DISK=$(sed -E 's/[0-9]+$//')
            PART=$(sed -E 's/.*[^0-9]([0-9]+)$/\1/');;
    esac
fi

After: Single parsing pass with optional override

# Parse disk and partition from device path
case "$SSD_DEV" in
    /dev/nvme*p[0-9]*) 
        DISK=$(sed -E 's/p[0-9]+$//')
        PART=$(sed -E 's/.*p([0-9]+)$/\1/');;
    /dev/*[0-9])
        DISK=$(sed -E 's/[0-9]+$//')
        PART=$(sed -E 's/.*[^0-9]([0-9]+)$/\1/');;
esac

# Override disk if parent device exists
PKNAME=$(lsblk -no pkname "$SSD_DEV" 2>/dev/null || echo "")
if [ -n "$PKNAME" ]; then
    DISK="/dev/$PKNAME"
fi

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Copilot AI changed the title [WIP] Update SSD partition and filesystem growth logic Consolidate duplicated device parsing logic in grow-ssd script Jan 7, 2026
Copilot AI requested a review from kristapsk January 7, 2026 23:13
;;
esac

# If the device has a parent (e.g., LVM, LUKS), use the parent as the disk
Copy link
Member

Choose a reason for hiding this comment

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

Comment is not correct, this will work not only with LVM or whatever, in most cases lsblk output will always succeed (e.g. lsblk -no pkname /dev/sda1 2>/dev/null || echo "" -> sda).

@kristapsk kristapsk closed this Jan 7, 2026
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