@@ -430,3 +430,48 @@ def test_backup(tmp_path: Path, capsys: pytest.CaptureFixture) -> None:
430430 assert not (dest_folder / "latest" / "file2.txt" ).exists ()
431431 assert (dest_folder / "latest" / "file3.txt" ).exists ()
432432 assert_n_backups (dest_folder , 2 )
433+
434+
435+ def test_backup_with_non_utf8_filename (tmp_path : Path ) -> None :
436+ """Test the backup function with a non-UTF8 filename.
437+
438+ Reproduces https://github.com/basnijholt/rsync-time-machine.py/issues/1
439+ """
440+ src_folder = tmp_path / "src"
441+ dest_folder = tmp_path / "dest"
442+ src_folder .mkdir ()
443+ dest_folder .mkdir ()
444+
445+ # Create a folder and file with a non-UTF8 filename
446+ folder = "TEST-UTF8"
447+ (src_folder / folder ).mkdir ()
448+ non_utf8_filename = "Mîso.rtf"
449+ (src_folder / folder / non_utf8_filename ).write_text ("Hello, World!" )
450+
451+ kw = {
452+ "src_folder" : str (src_folder ),
453+ "dest_folder" : str (dest_folder ),
454+ "exclusion_file" : "" ,
455+ "log_dir" : str (tmp_path / "logs" ),
456+ "auto_delete_log" : True ,
457+ "expiration_strategy" : "1:1" ,
458+ "auto_expire" : True ,
459+ "port" : "22" ,
460+ "id_rsa" : "" ,
461+ "rsync_set_flags" : "" ,
462+ "rsync_append_flags" : "" ,
463+ "rsync_get_flags" : False ,
464+ "allow_host_only" : False ,
465+ }
466+
467+ # Create a backup.marker file
468+ Path (backup_marker_path (str (dest_folder ))).touch ()
469+
470+ # Run the backup
471+ backup (** kw ) # type: ignore[arg-type]
472+
473+ # Check that the backup was created
474+ assert (dest_folder / "latest" / folder / non_utf8_filename ).exists ()
475+ assert (
476+ dest_folder / "latest" / folder / non_utf8_filename
477+ ).read_text () == "Hello, World!"
0 commit comments