@@ -43,7 +43,11 @@ pub(crate) enum BackupState {
4343 Inconsistent ,
4444}
4545
46- pub ( crate ) fn ensure_hosts_backup ( paths : & AppPaths , source_path : & Path ) -> Result < ( ) > {
46+ pub ( crate ) fn ensure_hosts_backup (
47+ paths : & AppPaths ,
48+ source_path : & Path ,
49+ backup_content : & str ,
50+ ) -> Result < ( ) > {
4751 match backup_state ( paths) {
4852 BackupState :: Ready => {
4953 validate_hosts_backup ( paths, source_path) ?;
@@ -59,8 +63,6 @@ pub(crate) fn ensure_hosts_backup(paths: &AppPaths, source_path: &Path) -> Resul
5963 BackupState :: Missing => { }
6064 }
6165
62- let original = fs:: read_to_string ( source_path)
63- . with_context ( || format ! ( "failed to read hosts file {}" , source_path. display( ) ) ) ?;
6466 let attributes = snapshot_file_attributes ( source_path) ?;
6567 let meta = HostsBackupMeta {
6668 source_path : source_path. display ( ) . to_string ( ) ,
@@ -75,7 +77,7 @@ pub(crate) fn ensure_hosts_backup(paths: &AppPaths, source_path: &Path) -> Resul
7577
7678 cleanup_temp_file ( & backup_temp_path) ?;
7779 cleanup_temp_file ( & meta_temp_path) ?;
78- write_temp_file ( & backup_temp_path, & original ) ?;
80+ write_temp_file ( & backup_temp_path, backup_content ) ?;
7981 write_temp_file (
8082 & meta_temp_path,
8183 std:: str:: from_utf8 ( & serialized) . context ( "failed to encode hosts backup metadata" ) ?,
@@ -531,10 +533,10 @@ mod tests {
531533 let source_path = test_dir. join ( "hosts" ) ;
532534
533535 std:: fs:: write ( & source_path, "first" ) . unwrap ( ) ;
534- ensure_hosts_backup ( & paths, & source_path) . unwrap ( ) ;
536+ ensure_hosts_backup ( & paths, & source_path, "first" ) . unwrap ( ) ;
535537
536538 std:: fs:: write ( & source_path, "second" ) . unwrap ( ) ;
537- ensure_hosts_backup ( & paths, & source_path) . unwrap ( ) ;
539+ ensure_hosts_backup ( & paths, & source_path, "second" ) . unwrap ( ) ;
538540
539541 assert_eq ! (
540542 std:: fs:: read_to_string( & paths. hosts_backup_path) . unwrap( ) ,
@@ -571,7 +573,7 @@ mod tests {
571573 std:: fs:: create_dir_all ( & paths. runtime_dir ) . unwrap ( ) ;
572574 let source_path = test_dir. join ( "hosts" ) ;
573575 std:: fs:: write ( & source_path, "original" ) . unwrap ( ) ;
574- ensure_hosts_backup ( & paths, & source_path) . unwrap ( ) ;
576+ ensure_hosts_backup ( & paths, & source_path, "original" ) . unwrap ( ) ;
575577
576578 let mut meta = load_backup_meta ( & paths) . unwrap ( ) ;
577579 meta. source_path = r"C:\different\hosts" . to_string ( ) ;
0 commit comments