Don't open file with read permissions if there is no need to write to it (#14689)

This commit is contained in:
Nicolas Mowen 2024-10-30 08:22:20 -06:00 committed by GitHub
parent 89ca085b94
commit 03dd9b2d42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -650,7 +650,7 @@ class FrigateConfig(FrigateBaseModel):
migrate_frigate_config(config_path) migrate_frigate_config(config_path)
# Finally, load the resulting configuration file. # Finally, load the resulting configuration file.
with open(config_path, "a+") as f: with open(config_path, "a+" if new_config else "r") as f:
# Only write the default config if the opened file is non-empty. This can happen as # Only write the default config if the opened file is non-empty. This can happen as
# a race condition. It's extremely unlikely, but eh. Might as well check it. # a race condition. It's extremely unlikely, but eh. Might as well check it.
if new_config and f.tell() == 0: if new_config and f.tell() == 0: