コード例 #1
0
def store_json(file_name, object_data):
    """Store persistency data to file."""
    persistence_data = JsonUtil.dump_as_json(object_data)
    fd = create_temporary_persistence_file(file_name)
    os.write(fd, bytes(persistence_data, 'utf-8'))
    replace_persistence_file(file_name, fd)
    os.close(fd)
コード例 #2
0
def store_json(file_name, object_data):
    """Store persistence data to file."""
    persistence_data = JsonUtil.dump_as_json(object_data)
    # Create a temporary file within persistence directory to write new persistence data to it.
    # Thus the old data is not modified, any error creating or writing the file will not harm the old state.
    fd, _ = tempfile.mkstemp(dir=SecureOSFunctions.tmp_base_dir_path)
    os.write(fd, bytes(persistence_data, 'utf-8'))
    create_missing_directories(file_name)
    replace_persistence_file(file_name, fd)
    os.close(fd)