]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
cephadm: convert more temporary file writes to use write_new
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 6 Jun 2023 16:37:14 +0000 (12:37 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 6 Jun 2023 18:19:53 +0000 (14:19 -0400)
commit5845a758fde8def526f89b050f2b51e6b3458ddd
treee72b34ef5f3909800989cf183d8d950ece67df32
parent642985c6894f8f62a313cd70c915d066f9c53d6e
cephadm: convert more temporary file writes to use write_new

Some functions are using the pattern:
```
with open(os.open(name + '.new, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
    f.write(...)
    os.rename(name + '.new', name)
```
While it is not entirely clear why this pattern was first used,
it accomplishes the same goal as `write_new` only directly calling
the posix open call. I analyzed the open flags for `write_new` and
these calls using `strace` and noted that the only significant
difference was the lack of O_TRUNC in these cases. Since the ".new"
files should not exist the lack of O_TRUC ought not make any difference.
With this decided we can convert these instances to `write_new`.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py