Add copy_safe action to FileHandler - #76
Merged
DavidHuber-NOAA merged 6 commits intoJul 16, 2026
Merged
Conversation
- Add cpfs() function to fsutils that copies files via temporary file with fsync and atomic rename - Implement copy_safe action in FileHandler to leverage cpfs for durable file operations - Update FileHandler._copy_files() to accept optional copy_fn parameter for customizable copy behavior - Export cpfs from wxflow package __init__ - Add comprehensive test coverage for copy_safe operation including overwrite and temp file cleanup scenarios - Mirror prod_util cpfs behavior for safe staging of files from DATA to COM directories
- Remove cpfs function from fsutils module and update __all__ export - Move atomic copy logic to FileHandler._safe_cp static method in file_utils - Update FileHandler.copy_safe to use new _safe_cp method instead of cpfs - Remove cpfs from module imports in __init__.py - Add tempfile import to file_utils and rm_p import for cleanup - Consolidate file copy utilities within FileHandler class for better encapsulation - Maintains identical atomic copy behavior with fsync and atomic rename semantics
- Remove test_copy_safe function that tested safe atomic file copy operations - Test coverage for copy_safe functionality is now handled by FileHandler._safe_cp tests - Simplify test suite by consolidating copy operation tests
- Add check to raise IsADirectoryError when source is a directory - Update docstring to clarify that directory sources are not supported - Prevents silent failures when attempting to copy directories with _safe_cp
- Add test_copy_safe function covering nominal file copy with overwrite - Validate that copied content matches source file contents - Verify no temporary .tmp files remain after successful copy - Test directory target handling to ensure source basename is retained - Verify FileNotFoundError raised when source file does not exist - Verify OSError raised when destination directory does not exist - Verify IsADirectoryError raised when attempting to copy directory source - Ensures copy_safe operation behaves as specified in atomic file copy contract
AntonMFernando-NOAA
marked this pull request as draft
July 9, 2026 19:32
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #76 +/- ##
===========================================
+ Coverage 60.72% 60.90% +0.17%
===========================================
Files 24 24
Lines 1986 2018 +32
Branches 374 377 +3
===========================================
+ Hits 1206 1229 +23
- Misses 723 735 +12
+ Partials 57 54 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
DavidHuber-NOAA
approved these changes
Jul 10, 2026
DavidHuber-NOAA
left a comment
Member
There was a problem hiding this comment.
Looks good. Thanks for this utility @AntonMFernando-NOAA!
AntonMFernando-NOAA
marked this pull request as ready for review
July 10, 2026 15:57
Member
|
@AntonMFernando-NOAA can you bump the version to 0.4.2 here, please. After that, I will merge. Line 29 in 293d5f4 |
Contributor
Author
@DavidHuber-NOAA Done. |
Member
|
Thanks! Merging. |
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.
Description
copy_safeaction toFileHandler, a third copy operation alongsidecopy_reqandcopy_opt. It mirrorsprod_util cpfsfor staging files from DATA to COM: copy to a temp file in the destination folder, fsync it, then atomically rename it onto the final name (overwriting if needed), with error checking at each step and temp-file cleanup on failure.Type of change
New feature (non-breaking change which adds functionality)
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to not work as expected)
This change requires a documentation update
How Has This Been Tested?
Ran pynorms (pycodestyle + isort) and pytest locally on Linux (Python 3.12); all pass. Added
test_copy_safecovering the nominal copy, overwrite, directory target, and the missing-source / missing-dir / directory-source error paths.pynorms
pytests
Checklist