/// Atomically write `node_records` in JSON format to `destination` file.
Atomically write `node_records` in JSON format to `destination` file.
Atomically write ` node_records ` in JSON format to ` destination ` file .
fn write_file<P: AsRef<Path>>(
    node_records: &[PrometheusNodeRecord],
    destination: P,
    mode: u32,
) -> Result<(), ServiceDiscoveryError> {
    let mut temp_dump_file = NamedTempFile::new_in(
        destination
            .as_ref()
            .parent()
            .unwrap_or_else(|| Path::new("/")),
    )
    .map_err(|source| ServiceDiscoveryError::IO { source })?;
    serde_json::to_writer_pretty(&temp_dump_file, &node_records)
        .map_err(|source| ServiceDiscoveryError::JsonSerializationFailed { source })?;
    temp_dump_file
        .as_file_mut()
        .sync_data()
        .map_err(|source| ServiceDiscoveryError::IO { source })?;
    temp_dump_file.persist(&destination).map_err(|source| {
        ServiceDiscoveryError::FilePersistenceFailed {
            source,
            destination: destination.as_ref().into(),
        }
    })?;
    let mut permissions = fs::metadata(&destination)?.permissions();
    permissions.set_mode(mode);
    fs::set_permissions(&destination, permissions)?;
    Ok(())
}
fn write_file < P : AsRef < Path > > ( node_records : & [ PrometheusNodeRecord ] , destination : P , mode : u32 , ) -> Result < ( ) , ServiceDiscoveryError > { let mut temp_dump_file = NamedTempFile :: new_in ( destination . as_ref ( ) . parent ( ) . unwrap_or_else ( | | Path :: new ( " " ) ) , ) . map_err ( | source | ServiceDiscoveryError :: IO { source } ) ? ; serde_json :: to_writer_pretty ( & temp_dump_file , & node_records ) . map_err ( | source | ServiceDiscoveryError :: JsonSerializationFailed { source } ) ? ; temp_dump_file . as_file_mut ( ) . sync_data ( ) . map_err ( | source | ServiceDiscoveryError :: IO { source } ) ? ; temp_dump_file . persist ( & destination ) . map_err ( | source | { ServiceDiscoveryError :: FilePersistenceFailed { source , destination : destination . as_ref ( ) . into ( ) , } } ) ? ; let mut permissions = fs :: metadata ( & destination ) ? . permissions ( ) ; permissions . set_mode ( mode ) ; fs :: set_permissions ( & destination , permissions ) ? ; Ok ( ( ) ) }
Atomically write `node_records` in JSON format to `destination` file.
Atomically write ` node_records ` in JSON format to ` destination ` file .
node_records
&[PrometheusNodeRecord]
destination
P
mode
u32