fix copyFilesystems raw-copy branch; cover with tests#6
Open
eriknordmark wants to merge 1 commit into
Open
Conversation
deitch
approved these changes
May 28, 2026
Contributor
|
Looks like linting errors. |
Two related changes:
The raw-data-copy branch in copyFilesystems used
`errors.Is(err, &disk.UnknownFilesystemError{})` to detect "no
recognized filesystem on source partition", but go-diskfs returns a
fresh `*UnknownFilesystemError` with a populated partition field via
`NewUnknownFilesystemError(partIndex)`. The zero-instance comparison
through errors.Is never matches, so the branch never fires and any
source partition without a known filesystem (including a real
squashfs we want to grow) falls into the rejection arm. Replace with
an errors.As-based helper.
Add four tests for paths that were previously uncovered:
- TestSwapPartitions: confirms swapPartitions round-trips
Name/Type-GUID/PartUUID/Attributes between the original slot and
the alt-labeled new slot, with geometry preserved.
- TestShrinkFilesystems: implements the previously-empty stub.
Mocks execResize2fs and covers the skip-when-no-shrink-needed
paths, the invocation when shrinking, error propagation, and
rejection of non-ext4 sources.
- TestCopyFilesystemsRawCopy: exercises the freshly-reachable
raw-copy branch via an unrecognized-filesystem source.
- Update TestCreatePartitions to expect the alternate label
(createPartitions assigns altName; the swap step is what restores
the original name on the new slot).
Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4312d66 to
7cce065
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two related changes:
Bug fix: raw-copy branch was unreachable
copyFilesystemsdetects "no recognized filesystem on source" via:But go-diskfs returns a fresh
*UnknownFilesystemErrorwith a populated partition field (disk.NewUnknownFilesystemError(partIndex)).errors.Iscompares against the zero-valued sentinel&UnknownFilesystemError{}and never matches, so any source partition without a recognized filesystem (including a real squashfs we'd want to grow) falls into the rejection arm above instead of the raw-copy arm below.Switched to an
errors.As-based helper (isUnknownFilesystem) that ignores the per-instance field. This makes the raw-copy / squashfs path actually reachable, which is the path needed for partitions whose source is squashfs (a common shape: rootfs images grown to make room for larger replacements).Test coverage for previously-uncovered paths
Four additions:
TestSwapPartitions— confirmsswapPartitionsround-tripsName/Type-GUID/PartUUID/Attributesbetween the original slot and the alt-labeled new slot, and preserves geometry. Catches inversion-on-double-call regressions.TestShrinkFilesystems— implements the previously-empty stub. MocksexecResize2fsand covers: skip when current ≤ target, invocation when shrinking, error propagation, and rejection of non-ext4 sources.TestCopyFilesystemsRawCopy— exercises the freshly-reachable raw-copy branch via an unrecognized-filesystem source. Uses equal-sized partitions to avoid an unrelated go-diskfs verification bug (sync.verifyBlockCopyrejects target-larger-than-source; filed at sync.verifyBlockCopy fails when target partition is larger than source go-diskfs#403).TestCreatePartitionsupdate — corrects the expectation:createPartitionsintentionally assigns the alternate label (<orig>_resized2) to the new slot; a laterswapPartitionsstep is what restores the original name. The previous expectation asserted the post-swap state but was running before swap. Verified passes against both unmodified upstream go-diskfs and a local patched build.Test results
(Pre-existing
TestRunfailure remains; that's blocked on an unrelated go-diskfs ext4 issue — diskfs/go-diskfs#402 — and not in scope here.)Notes for review
shrinkFilesystems,createPartitions,copyFilesystems,swapPartitions,removePartitions) remain unexported. Callers that want explicit per-phase orchestration would need them exported; that's a separate API question, not part of this PR. Discussed briefly in Add idempotency #2 (comment).Signed-off-by: eriknordmark erik@zededa.com