@@ -22,6 +22,7 @@ groups() ->
2222 fork_server_save , seed_fork , basic_sync ,
2323 delete_sync , too_many_clients ,
2424 overwrite_sync_clash , conflict_sync ,
25+ delete_sync_conflict ,
2526 prevent_server_clash ,
2627 multipart , double_conflict ]}].
2728
@@ -714,6 +715,70 @@ conflict_sync(Config) ->
714715 ? assertEqual ({ok , <<" sh2" >>}, file :read_file (filename :join ([ClientPath2 , " shared.1C56416E" ]))),
715716 ok .
716717
718+ delete_sync_conflict () ->
719+ [{doc , " A deletion conflict can be sync'd to a third party" },
720+ {timetrap , timer :seconds (5 )}].
721+ delete_sync_conflict (Config ) ->
722+ Client = ? config (name , Config ),
723+ Server = ? config (server , Config ),
724+ Remote = (? config (peer , Config ))(Server ),
725+ ClientPath = ? config (path , Config ),
726+ ServerPath = ? config (server_path , Config ),
727+ {ok , _ServId1 } = revault_fsm :id (Server ),
728+ {ok , _ } = revault_fsm_sup :start_fsm (
729+ ? config (db_dir , Config ),
730+ Client ,
731+ ClientPath ,
732+ ? config (ignore , Config ),
733+ ? config (interval , Config ),
734+ (? config (callback , Config ))(Client )
735+ ),
736+ ok = revault_fsm :client (Client ),
737+ {ok , _ClientId } = revault_fsm :id (Client , Remote ),
738+ % % Set up a second client; because of how config works in the test, it needs
739+ Client2 = Client ++ " _2" ,
740+ Priv = ? config (priv_dir , Config ),
741+ DbDir2 = filename :join ([Priv , " db_2" ]),
742+ ClientPath2 = filename :join ([Priv , " data" , " client_2" ]),
743+ filelib :ensure_dir (filename :join ([DbDir2 , " fakefile" ])),
744+ filelib :ensure_dir (filename :join ([ClientPath2 , " fakefile" ])),
745+ {ok , _ } = revault_fsm_sup :start_fsm (DbDir2 , Client2 , ClientPath2 ,
746+ ? config (ignore , Config ), ? config (interval , Config ),
747+ (? config (callback , Config ))(Client2 )),
748+ ok = revault_fsm :client (Client2 ),
749+ ? assertMatch ({ok , _ }, revault_fsm :id (Client2 , Remote )),
750+ % % now in initialized mode
751+ % % Write files
752+ ok = file :write_file (filename :join ([ServerPath , " shared" ]), " sh1" ),
753+ ok = file :write_file (filename :join ([ClientPath , " shared" ]), " sh2" ),
754+ % % Track em
755+ ok = revault_dirmon_event :force_scan (Client , 5000 ),
756+ ok = revault_dirmon_event :force_scan (Server , 5000 ),
757+ % % Delete em
758+ ok = file :delete (filename :join ([ServerPath , " shared" ])),
759+ ok = file :delete (filename :join ([ClientPath , " shared" ])),
760+ % % Track the deletion
761+ ok = revault_dirmon_event :force_scan (Client , 5000 ),
762+ ok = revault_dirmon_event :force_scan (Server , 5000 ),
763+ % % Sync em
764+ ct :pal (" SYNC" , []),
765+ ok = revault_fsm :sync (Client , Remote ),
766+ % % See the result
767+ % % conflicting files are marked, with empty conflict files since nothing exists aside
768+ % % from clashing deletions.
769+ ? assertEqual ({error , enoent }, file :read_file (filename :join ([ServerPath , " shared" ]))),
770+ ? assertEqual ({error , enoent }, file :read_file (filename :join ([ClientPath , " shared" ]))),
771+ ? assertEqual ({ok , <<" " >>}, file :read_file (filename :join ([ServerPath , " shared.conflict" ])) ),
772+ ? assertEqual ({ok , <<" " >>}, file :read_file (filename :join ([ClientPath , " shared.conflict" ])) ),
773+
774+ % % Now when client 2 syncs, it gets the files and conflict files as well
775+ ct :pal (" SECOND SYNC" , []),
776+ ok = revault_fsm :sync (Client2 , Remote ),
777+ % % conflicting files are marked, but working files aren't sync'd since they didn't exist here
778+ ? assertEqual ({error , enoent }, file :read_file (filename :join ([ClientPath2 , " shared" ]))),
779+ ? assertEqual ({ok , <<" " >>}, file :read_file (filename :join ([ClientPath2 , " shared.conflict" ])) ),
780+ ok .
781+
717782prevent_server_clash () ->
718783 [{doc , " A client from a different server cannot connect to the wrong one "
719784 " as it is protected by a UUID." },
0 commit comments