Fix backup numbering when .tar.gz files are decompressed to .tar#404
Conversation
shyuep
left a comment
There was a problem hiding this comment.
I suggested a few changes that simplify the code considerably.
| 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( |
There was a problem hiding this comment.
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.
| backup_files = glob(os.path.join(directory, f"{prefix}.*.tar.gz")) + glob( | ||
| os.path.join(directory, f"{prefix}.*.tar") | ||
| ) | ||
| nums = [] |
| nums.append(int(file.split(".")[-2])) | ||
| except (ValueError, IndexError): | ||
| continue | ||
| num = max([0, *nums]) |
There was a problem hiding this comment.
This just needs to be num = max(nums)
There was a problem hiding this comment.
Thanks for the suggestions. I have introduced the changes.
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
Thanks. |
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.