Skip to content

Fix safe_copy(..., preserve_meta=False)#4938

Open
samsrabin wants to merge 4 commits intoESMCI:masterfrom
samsrabin:safe_copy-202602
Open

Fix safe_copy(..., preserve_meta=False)#4938
samsrabin wants to merge 4 commits intoESMCI:masterfrom
samsrabin:safe_copy-202602

Conversation

@samsrabin
Copy link
Contributor

@samsrabin samsrabin commented Feb 16, 2026

Description

This changes safe_copy(..., preserve_meta=False) to use shutil.copyfile instead of shutil.copy when safe_copy is called on a file directly. This fixes the bug where preserve_meta=False incorrectly preserved permissions.

The first set of test runs will fail because I'm pushing without the bugfix. Once those tests are complete, I'll push the fix and they should pass.

I added the tests in a new file, but they could be moved to test_unit_utils.py instead.

Checklist

  • My code follows the style guidelines of this project (black formatting)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that exercise my feature/fix and existing tests continue to pass
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding additions and changes to the documentation

The failing test is test_safe_copy_preserve_meta_false: According to the docstring, we do not expect permissions to be preserved when using safe_copy() on a file, but they are.
@samsrabin samsrabin self-assigned this Feb 16, 2026
@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.51%. Comparing base (fc2de6d) to head (7e7893e).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4938      +/-   ##
==========================================
+ Coverage   31.37%   31.51%   +0.13%     
==========================================
  Files         264      264              
  Lines       38899    38869      -30     
  Branches     8260     8254       -6     
==========================================
+ Hits        12204    12248      +44     
+ Misses      25457    25384      -73     
+ Partials     1238     1237       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@jedwards4b jedwards4b left a comment

Choose a reason for hiding this comment

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

Thank you!

@samsrabin
Copy link
Contributor Author

Hmm... not sure what that failing CESM system test is about.

@samsrabin
Copy link
Contributor Author

samsrabin commented Feb 16, 2026

Very strange; it works on Derecho. Resubmitting.

@samsrabin
Copy link
Contributor Author

That did it! All tests have now passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

safe_copy(..., preserve_meta=False) does preserve perms

2 participants