@@ -33,6 +33,82 @@ fn test_mv_missing_dest() {
3333 ucmd. arg ( dir) . fails ( ) ;
3434}
3535
36+ #[ test]
37+ #[ cfg( target_os = "linux" ) ]
38+ #[ cfg( not( wasi_runner) ) ]
39+ fn test_mv_no_open_same_file_system ( ) {
40+ let ( at, mut _ucmd) = at_and_ucmd ! ( ) ;
41+ let file = "source_file" ;
42+ at. touch ( file) ;
43+ if std:: process:: Command :: new ( "strace" )
44+ . args ( [
45+ "-e" ,
46+ "trace=open,openat" ,
47+ "-o" ,
48+ "strace.out" ,
49+ uutests:: util:: get_tests_binary ( ) ,
50+ "mv" ,
51+ file,
52+ "target_file" ,
53+ ] )
54+ . current_dir ( at. as_string ( ) )
55+ . output ( )
56+ . is_err ( )
57+ {
58+ return ; // missing strace
59+ } ;
60+
61+ let open_count = at
62+ . read ( "strace.out" )
63+ . lines ( )
64+ . filter ( |l| {
65+ let trimmed = l. trim ( ) ;
66+ trimmed. starts_with ( "open(" )
67+ || trimmed. starts_with ( "openat(" )
68+ && ( trimmed. contains ( file) || trimmed. contains ( "target_file" ) )
69+ } )
70+ . count ( ) ;
71+ assert_eq ! ( open_count, 0 ) ;
72+ }
73+
74+ #[ test]
75+ #[ cfg( target_os = "linux" ) ]
76+ #[ cfg( not( wasi_runner) ) ]
77+ fn test_mv_open_once ( ) {
78+ let ( at, mut _ucmd) = at_and_ucmd ! ( ) ;
79+ let file = "source_file" ;
80+ at. touch ( file) ;
81+ if std:: process:: Command :: new ( "strace" )
82+ . args ( [
83+ "-e" ,
84+ "trace=open,openat" ,
85+ "-o" ,
86+ "strace.out" ,
87+ uutests:: util:: get_tests_binary ( ) ,
88+ "mv" ,
89+ file,
90+ "/dev/shm/target_file" ,
91+ ] )
92+ . current_dir ( at. as_string ( ) )
93+ . output ( )
94+ . is_err ( )
95+ {
96+ return ; // missing strace
97+ } ;
98+
99+ let open_count = at
100+ . read ( "strace.out" )
101+ . lines ( )
102+ . filter ( |l| {
103+ let trimmed = l. trim ( ) ;
104+ trimmed. starts_with ( "open(" )
105+ || trimmed. starts_with ( "openat(" )
106+ && ( trimmed. contains ( file) || trimmed. contains ( "target_file" ) )
107+ } )
108+ . count ( ) ;
109+ assert_eq ! ( open_count, 2 ) ;
110+ }
111+
36112#[ test]
37113fn test_mv_rename_dir ( ) {
38114 let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
0 commit comments