Refactor: break up oversized methods into smaller descriptive helpers #41
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/vaultik#41
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "refactor/break-up-long-methods"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #40
Per sneak's feedback on PR #37: methods were too long. This PR breaks all methods over 100-150 lines into smaller, descriptively named helper methods.
Refactored methods (8 total)
createNamedSnapshotresolveSnapshotPaths,scanAllDirectories,collectUploadStats,finalizeSnapshotMetadata,printSnapshotSummary,getSnapshotBlobSizes,formatUploadSpeedListSnapshotslistRemoteSnapshotIDs,reconcileLocalWithRemote,buildSnapshotInfoList,printSnapshotTablePruneBlobscollectReferencedBlobs,listUniqueSnapshotIDs,listAllRemoteBlobs,findUnreferencedBlobs,deleteUnreferencedBlobsRunDeepVerifyloadVerificationData,runVerificationSteps,deepVerifyFailureRemoteInfocollectSnapshotMetadata,collectReferencedBlobsFromManifests,populateRemoteInfoResult,scanRemoteBlobStorage,printRemoteInfoTablehandleBlobReadyuploadBlobIfNeeded,makeUploadProgressCallback,recordBlobMetadata,cleanupBlobTempFileprocessFileStreamingupdateChunkStats,addChunkToPacker,queueFileForBatchInsertfinalizeCurrentBlobcloseBlobWriter,buildChunkRefs,commitBlobToDatabase,deliverFinishedBlobVerification
go build ./...✅make test✅ (all tests pass)golangci-lint run✅ (0 issues)Rebased onto main (branch was already up to date, no conflicts). All checks pass:
golangci-lint run: 0 issuesgo fmt: cleango test ./...: all tests passingRemoved
needs-rebase, addedneeds-review.Code Review: refactor/break-up-long-methods
Lint/Tests: All passing (golangci-lint clean, go fmt clean, all tests pass).
Issues Found
Bug: Upload failures silently swallowed (scanner.go — uploadBlobIfNeeded)
The original handleBlobReady returned an error on upload failure. The refactored uploadBlobIfNeeded logs the error and returns false, silently continuing. This means upload failures are now ignored — the blob gets recorded in the database as if it exists, but was never uploaded. This will cause data loss. The method should return (bool, error) and propagate the upload error.
Behavior change: listUniqueSnapshotIDs swallows listing errors (prune.go)
The original PruneBlobs returned errors from the metadata listing channel. The refactored listUniqueSnapshotIDs silently continues on errors. This could hide storage connectivity issues during prune, potentially causing blobs to be incorrectly identified as orphaned. Should return ([]string, error).
Everything Else Looks Good
Verdict: Needs Rework
The upload error swallowing in uploadBlobIfNeeded is a data-loss bug that must be fixed before merge. The listUniqueSnapshotIDs error handling should also be restored.
(Please disregard the previous comment with unexpanded variable.)
Fixed both review findings:
scanner.go (
uploadBlobIfNeeded): Changed return type fromboolto(bool, error). Upload errors are now propagated to the caller, preventing data loss where blobs would be recorded in DB but never actually uploaded.prune.go (
listUniqueSnapshotIDs): Changed return type from[]stringto([]string, error). Listing errors are now propagated tocollectReferencedBlobs, preventing incorrect orphan detection during prune.All tests pass (
make check+make testclean).Re-review after rework. Both previously identified issues are fixed correctly:
Data-loss bug fixed:
uploadBlobIfNeedednow returns(bool, error)— the error froms.storage.PutWithProgressis properly propagated instead of being silently dropped. The caller inhandleBlobReadychecks this error and cleans up the temp file on failure.Error swallowing fixed:
listUniqueSnapshotIDsnow returns([]string, error)— iteration errors fromListStreamare propagated to the caller (collectReferencedBlobs) which returns them up the chain.The overall refactoring is well-structured: long methods are broken into focused helpers with clear names (
closeBlobWriter,buildChunkRefs,commitBlobToDatabase,deliverFinishedBlob, etc.). No linter config changes. All tests pass (make testclean). No new issues found.Approved ✅
Checkout
From your project repository, check out a new branch and test the changes.