generate_secrets: Fix handling of missing trailing newlines.

When we added support for automatically adding new secrets in
generate_secrets.py, we failed to account for the possibility that a
human editor might have let the secrets file without a trailing
newline.

We address this by adding a leading newline before our new secret.

Fixes #5209.
This commit is contained in:
Tim Abbott
2017-06-03 23:13:59 -07:00
parent 8d6af030c0
commit b70986469c

View File

@@ -108,7 +108,9 @@ def generate_secrets(development=False):
return
out = open(OUTPUT_SETTINGS_FILENAME, 'a')
out.write(force_str("".join(lines)))
# Write a newline at the start, in case there was no newline at
# the end of the file due to human editing.
out.write("\n" + force_str("".join(lines)))
out.close()
print("Generated new secrets in %s." % (OUTPUT_SETTINGS_FILENAME,))