caronc / apprise-api

A lightweight REST framework that wraps the Apprise Notification Library
https://hub.docker.com/r/caronc/apprise
MIT License
580 stars 50 forks source link

Fix failure to save settings on Windows #114

Closed NHellFire closed 1 year ago

NHellFire commented 1 year ago

Description:

Saving settings on Windows fails with:

Traceback (most recent call last):
  File "C:\Users\Nathan\.pyenv\pyenv-win\versions\3.11.3\Lib\shutil.py", line 825, in move
    os.rename(src, real_dst)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\Nathan\\.local\\apprise-api\\apprise_api\\var\\config\\27\\tmpi0utrc0z.tmp' -> 'C:\\Users\\Nathan\\.local\\apprise-api\\apprise_api\\var\\config\\27\\7a415748edb692e8bf8c4361e9777d92f2dfad2359bbd8c9fbcd49.text'

mkstemp() also returns an open file handle (that we don't use), which must be closed as Windows won't allow renaming an open file.

Checklist

caronc commented 1 year ago

This was educational for me. I didn't realize the handle had to be closed in this circumstance. Thank you!