kfogel / OneTime

An open source encryption program that uses the "one-time pad" method.
http://red-bean.com/onetime
32 stars 14 forks source link

WindowsError: [Error 183] Cannot create a file when that file already exists #13

Closed phred2 closed 7 years ago

phred2 commented 9 years ago

When running OneTime (onetime-2.0-beta3.zip) Windows 7 Python 2.7.9 environment:

C:\Python27>python onetime.py -e -p hotbits.pad -o test.e test.txt Traceback (most recent call last): File "onetime.py", line 1279, in main() File "onetime.py", line 1273, in main config.save() File "onetime.py", line 847, in save os.rename(tempfile, self.pad_records_file) WindowsError: [Error 183] Cannot create a file when that file already exists

I've made sure the pad-records path (.onetime) contains nothing before running. After running it appears OneTime created two files:

pad-records 0 bytes pad-records.tmp 205 bytes

Perhaps a Windows specific issue?

Cheers, Phred

phred2 commented 9 years ago

Indeed a Windows specific issue. Python docs (https://docs.python.org/2/library/os.html) state that if the destination file exists os.rename will throw an error in a Windows environment but in most cases will overwrite the destination under Unix.

A working quick fix for Windows users is the addition of: if os.name == 'nt': os.remove(self.pad_records_file) just prior to the rename os.rename(tempfile, self.pad_records_file)

Cheers, Phred

kfogel commented 8 years ago

Please try version 2.0-beta9 (from http://red-bean.com/onetime/), which includes the above commit, and let me know if it fixes the problem on Windows.

Best regards, -Karl

kfogel commented 7 years ago

Closing under the assumption that this is now fixed. Please re-open if I'm wrong.