Skip to content

when saving a file under an existing name fails, the file is deleted anyway #441

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

Closed
gdementen opened this issue Sep 21, 2017 · 2 comments
Closed

Comments

@gdementen
Copy link
Contributor

This is extremely annoying. I had a large (valid) file, I introduced a few bad values in it, tried to save it. It failed (without error, see larray-project/larray-editor#75) and I then closed the editor to realize my file had disappeared, hence loosing my work!

This happens at least for saving to Excel, but might happen for other backends too.

This is going to be a tad annoying to fix:

if destpath exists:
    if overwrite:
        save file as temppath
        delete destpath
        rename temppath to destpath
    else:
       raise "{despath} already exists"
else:
    save file as destpath

Or, a tad simpler (but at tad less efficient):

save file as temppath
if destpath exists:
    if overwrite:
        delete destpath
    else:
        raise "{despath} already exists"
rename temppath to destpath
@alixdamman
Copy link
Collaborator

I think that the problem comes from Workbook.__init__ in which we find the 4 following lines:

    if os.path.isfile(filepath) and overwrite_file:
        os.remove(filepath)
    if not os.path.isfile(filepath):
        self.new_workbook = True

So, I guess only Workbook must be changed.

@gdementen
Copy link
Contributor Author

The problem is also present in Session.save():

        if overwrite and engine != ext_default_engine['csv'] and os.path.isfile(fname):
            os.remove(fname)

@alixdamman alixdamman self-assigned this Sep 25, 2017
alixdamman added a commit to alixdamman/larray that referenced this issue Sep 25, 2017
…ing on a Excel file to be overwritten. Temporary file is deleted only after calling close().
alixdamman added a commit to alixdamman/larray that referenced this issue Sep 26, 2017
…ing on a file to be overwritten. Temporary file is deleted only after calling close().
alixdamman added a commit to alixdamman/larray that referenced this issue Sep 26, 2017
…ing on a file to be overwritten. Temporary file is deleted only after calling close().
gdementen pushed a commit that referenced this issue Aug 31, 2018
fix #441 : temporary file is created and used when working on a file to be overwritten. Temporary file is deleted only after calling close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants