Skip to content

Fix backup numbering when .tar.gz files are decompressed to .tar#404

Merged
shyuep merged 3 commits into
materialsproject:masterfrom
NicoPhase:fix-backup-tar-handling
Sep 17, 2025
Merged

Fix backup numbering when .tar.gz files are decompressed to .tar#404
shyuep merged 3 commits into
materialsproject:masterfrom
NicoPhase:fix-backup-tar-handling

Conversation

@NicoPhase
Copy link
Copy Markdown
Contributor

Summary

This is a fix to issue #403. It makes sure that backup files aren't overwritten when a series of custodian jobs are executed in the same folder. The fix is achieved by taking both .tar.gz and .tar files into account when determining the file number.

Copy link
Copy Markdown
Member

@shyuep shyuep left a comment

Choose a reason for hiding this comment

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

I suggested a few changes that simplify the code considerably.

Comment thread src/custodian/utils.py Outdated
directory (str): directory where the files exist
"""
num = max([0] + [int(file.split(".")[-3]) for file in glob(os.path.join(directory, f"{prefix}.*.tar.gz"))])
backup_files = glob(os.path.join(directory, f"{prefix}.*.tar.gz")) + glob(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can be done as a single glob. glob(os.path.join(directory, f"{prefix}.*.tar*")). There is no need to add two globs.

Comment thread src/custodian/utils.py Outdated
backup_files = glob(os.path.join(directory, f"{prefix}.*.tar.gz")) + glob(
os.path.join(directory, f"{prefix}.*.tar")
)
nums = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nums = [0]

Comment thread src/custodian/utils.py Outdated
nums.append(int(file.split(".")[-2]))
except (ValueError, IndexError):
continue
num = max([0, *nums])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This just needs to be num = max(nums)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions. I have introduced the changes.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.02%. Comparing base (831a80a) to head (e6af24a).
⚠️ Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
src/custodian/utils.py 63.63% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #404       +/-   ##
===========================================
- Coverage   69.74%   53.02%   -16.73%     
===========================================
  Files          39       39               
  Lines        3504     3508        +4     
===========================================
- Hits         2444     1860      -584     
- Misses       1060     1648      +588     

☔ 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.

@shyuep shyuep merged commit 32858c3 into materialsproject:master Sep 17, 2025
7 of 8 checks passed
@shyuep
Copy link
Copy Markdown
Member

shyuep commented Sep 17, 2025

Thanks.

@NicoPhase NicoPhase deleted the fix-backup-tar-handling branch September 18, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants