Code review comment for ~powersj/cloud-init:fix-arch-hostname

Revision history for this message
Scott Moser (smoser) wrote :

summary: add 'omode' to the write_file call
  util.write_file(out_fn, str(conf), mode=0o644, omode="w")

Reasoning:
write_file does an 'open' by default with 'wb' (binary mode).
The, if the mode is binary, it will try to encode the contents which is why
we see the failure.

Your change works because you're passing a string now, which *does* have
.encode(), but it'd be better to avoid write_file's magic and pass a
string as well as open in string mode so no .encode() or .decode() had
to happen.

in its calls to 'encode_text' or 'decode_text', write_file is doing more magic
then it should. Ultimately it'd be better if the caller provided correct
modes and data, which is what we're doing here.

review: Needs Fixing

« Back to merge proposal