# neutron_lib.utils.file module

neutron_lib.utils.file.replace_file(file_name, data, file_mode=420)

  Replaces the contents of file_name with data in a safe manner.

  First write to a temp file and then rename. Since POSIX renames are atomic, the file is unlikely to be corrupted by competing writes.

  We create the tempfile on the same device to ensure that it can be renamed.

  Parameters:

    - file_name – Path to the file to replace.

    - data – The data to write to the file.

    - file_mode – The mode to use for the replaced file.

  Returns:

    None.

this page last updated: 2026-03-03 11:51:03

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug