The function save_elevator() (line 31) creates a temporary file (line 32), then writes the serialized string of elevator table in that temporary file (line 33), then renames it to "elevator" (line 35). The problem is: when destination filename exists, os.rename fails.
TODO: after closing the temporary file (line 34), delete the file "elevator" (os.remove), of course checking if it succeeds, before renaming "elevator.tmp" to "elevator", also checking if rename succeeded.
The function
save_elevator()
(line 31) creates a temporary file (line 32), then writes the serialized string ofelevator
table in that temporary file (line 33), then renames it to "elevator" (line 35). The problem is: when destination filename exists,os.rename
fails.TODO: after closing the temporary file (line 34), delete the file "elevator" (
os.remove
), of course checking if it succeeds, before renaming "elevator.tmp" to "elevator", also checking if rename succeeded.