refactor sidecar code #73
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
rust
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/zim-studio!73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "sidecar-dry"
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?
✅ Fixed the bug: When saving a full file (without selection), the player now properly creates a sidecar .md file
✅ Major refactoring to eliminate code duplication:
Changes Made:
- get_sidecar_path(audio_path) - Constructs sidecar path from audio file path
- clone_sidecar(source, dest, mode, tags) - Handles all sidecar cloning logic
- SidecarCloneMode enum with FullCopy and Selection variants
- Deleted ~230 lines of duplicated code (clone_sidecar_for_selection method)
- Simplified save_audio() to use clone_sidecar for full file copies (fixes the bug!)
- Simplified save_selection() to use clone_sidecar for selections
- Simplified open_sidecar_in_editor() to use get_sidecar_path
- Removed local get_sidecar_path function
- Now imports from utils::sidecar
Results:
The fix ensures that when you save a file without making a selection (no i/o marks), it will:
This matches the behavior you already had for selections, so everything is now consistent!
Code Review - PR #73: Refactor Sidecar Code
Summary
This PR successfully refactors sidecar file handling by extracting duplicated code into a new
src/utils/sidecar.rsmodule. The refactoring eliminates ~150 lines of code duplication and fixes a bug where full file saves weren't creating sidecar files.✅ Strengths
1. Excellent Code Organization
src/utils/sidecar.rsmodule provides a clean, single source of truthSidecarCloneMode)2. Strong Documentation
3. Robust Error Handling
src/utils/sidecar.rs:72-74)4. Good Test Coverage
5. Bug Fix Confirmed
src/player/app.rs:488-496⚠️ Issues and Recommendations
1. Security: Command Injection Pattern (Medium)
src/utils/sidecar.rs:282-299(get_timestamp)datecommandchrono::Utcinstead for portability and security2. Large Function (Low)
src/utils/sidecar.rs:145-263(clone_selection)allow(clippy::too_many_arguments)3. Unused Parameter (Low)
src/utils/sidecar.rs:154(_duration)4. Magic Numbers (Very Low)
src/utils/sidecar.rs:119,182+ 5offsets5. Missing Test Coverage (Low)
clone_sidecarfunction untested📊 Impact Assessment
Files Changed:
src/utils/sidecar.rs(+336 lines) - New modulesrc/utils/mod.rs(+1 line)src/player/app.rs(-245, +43 lines)src/cli/update.rs(-9, +1 lines)Metrics:
🎯 Recommendations
Must Fix: None - safe to merge
Should Fix:
datecommand withchrono::UtcNice to Have:
2. Refactor large functions
3. Add integration tests
4. Extract magic numbers
✅ Final Verdict
APPROVED - Clean refactoring that improves maintainability and fixes a real bug. High code quality with excellent documentation.
Merge Recommendation: ✅ Approve and Merge
Great work! The codebase is significantly cleaner.