Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve force overwriting for existing output files #48

Merged
merged 5 commits into from
Nov 11, 2024

Conversation

q-posev
Copy link
Member

@q-posev q-posev commented Nov 10, 2024

Mainly moved the file removal logic to the high-level trexio_run.py script and fixed some inconsistencies. Now it calls rm -rf so it should work for both TEXT and HDF5 back ends unlike the previous version that was printing an error message for TEXT TREXIO files.

Move the code logics to the front-level trexio_run script + minor cleanup
@q-posev q-posev added the enhancement New feature or request label Nov 10, 2024
@q-posev q-posev requested a review from scemama November 10, 2024 09:53
@q-posev q-posev self-assigned this Nov 10, 2024
Comment on lines 33 to 44
def remove_trexio_file(filename:str, overwrite:bool) -> None:
"""Remove the TREXIO file/directory if it exists."""
if os.path.exists(filename):
if overwrite:
if '*' in filename:
raise ValueError(f'TREXIO filename {filename} contains * symbol. Are you sure?')
os.system(f'rm -rf -- {filename} ')
else:
raise Exception(f'Output file {filename} already exists but overwrite option is not provided. Consider using the `-w` CLI argument.')

return

Copy link
Member

Choose a reason for hiding this comment

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

Suppose that a user calls trexio_convert -w $HOME/$MY_TREXIO_FILE, this wil call rm -rf -- $HOME/$MY_TREXIO_FILE. If the user made a mistake in his/her script and forgot to define $MY_TREXIO_FILE, it wil make rm -rf $HOME/. :-(
It would be safer to try to open the trexio file first and check something inside it like the trexio metadata, so that we are sure that the thing we remove is indeed a trexio file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, please have a look.

Copy link
Member

@scemama scemama left a comment

Choose a reason for hiding this comment

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

Great! But there is a little danger with rm -rf. See my comment on the source file.

@q-posev
Copy link
Member Author

q-posev commented Nov 10, 2024

Great idea! Will do that.

@scemama scemama merged commit 7e73d06 into master Nov 11, 2024
1 check passed
@q-posev q-posev deleted the improve-overwriting branch November 11, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force overwrite CLI option
2 participants