Skip to content

Fixed FIleExistsError in the _save method#3

Merged
Code0x58 merged 2 commits intoCode0x58:masterfrom
JakubBlaha:master
May 6, 2020
Merged

Fixed FIleExistsError in the _save method#3
Code0x58 merged 2 commits intoCode0x58:masterfrom
JakubBlaha:master

Conversation

@JakubBlaha
Copy link
Copy Markdown
Contributor

There was an error occuring when calling the _save method.

FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\\Users\\jakub\\AppData\\Local\\Temp\\tmphz6dzu_7~' -> 'C:\\Users\\jakub\\AppData\\Local\\Temp\\tmphz6dzu_7'

@Code0x58
Copy link
Copy Markdown
Owner

Code0x58 commented May 3, 2020

Thanks for reporting this! I've just added Windows to the tests in Travis to highlight the failure, so rebasing your change will show that it fixed the issue.

I think a better solution here is to use os.replace(...) instead of os.rename(...), that way the behaviour is consistent between platforms (where the store doesn't blink out of existence). That method was added in python 3.3, so to maintain support you could use something like:

if sys.version_info >= (3, 3):
    os.replace(temp, self._path)
elif os.name == "windows":
    os.remove(self._path)
    os.rename(temp, self._path)
else:
    os.rename(temp, self._path)

@Code0x58 Code0x58 merged commit 542a3c3 into Code0x58:master May 6, 2020
@Code0x58
Copy link
Copy Markdown
Owner

Code0x58 commented May 6, 2020

Thanks! I'll make a release for this tonight

@JakubBlaha
Copy link
Copy Markdown
Contributor Author

Thank you too! I can finally use this in my windows scripts.

@Code0x58
Copy link
Copy Markdown
Owner

Code0x58 commented May 6, 2020

This/Windows support is now released as 1.2.0 is available on pypi

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.

2 participants