@@ -16,7 +16,7 @@ main! = |_args|
1616 Ok (_ ) ->
1717 cleanup_test_files!(FilesNeedToExist )
1818 Err (err) ->
19- cleanup_test_files!(FilesMaybeExist )?
19+ _ = cleanup_test_files!(FilesMaybeExist )
2020 Err (Exit (1 , " Test run failed:\n\t ${Inspect.to_str(err)}" ))
2121
2222run_tests !: {} => Result {} _
@@ -247,6 +247,21 @@ test_directory_operations! = |{}|
247247
248248 Ok({})
249249
250+ get_hard_link_count! : Str => Result Str _
251+ get_hard_link_count! = |path_str|
252+ ls_l =
253+ Cmd.new(" ls" )
254+ |> Cmd.args([" - l" , path_str])
255+ |> Cmd.exec_output!()?
256+
257+ hard_link_count_str =
258+ (ls_l.stdout_utf8
259+ |> Str.split_on(" " )
260+ |> List.keep_if(|str| !Str.is_empty(str))
261+ |> List.get(1)) ? |_| IExpectedALineWithASpaceHere(ls_l)
262+
263+ Ok(hard_link_count_str)
264+
250265test_hard_link! : {} => Result {} _
251266test_hard_link! = |{}|
252267 Stdout.line!(" \nTesting Path . hard_link !:")?
@@ -255,24 +270,23 @@ test_hard_link! = |{}|
255270 original_path = Path . from_str ("test_path_original .txt ")
256271 Path . write_utf8 !("Original content for Path hard link test" , original_path)?
257272
258- # Get original file stats
259- stat_before = Cmd.new(" stat" ) |> Cmd.args([" - c" , " %h" , " test_path_original. txt " ]) |> Cmd.exec_output!()?
273+ hard_link_count_before = get_hard_link_count!(" test_path_original. txt " )?
260274
261275 # Create hard link
262276 link_path = Path.from_str(" test_path_hardlink. txt " )
263277 when Path.hard_link!(original_path, link_path) is
264278 Ok({}) ->
265279 # Get link count after
266- stat_after = Cmd.new( " stat " ) |> Cmd.args([ " - c " , " %h " , " test_path_original. txt " ]) |> Cmd.exec_output!( )?
280+ hard_link_count_after = get_hard_link_count!( " test_path_original. txt " )?
267281
268282 # Verify both files exist and have same content
269283 original_content = Path.read_utf8!(original_path)?
270284 link_content = Path.read_utf8!(link_path)?
271285
272286 Stdout.line!(
273287 " " "
274- Hard link count before: ${Str . trim ( stat_before . stdout_utf8 ) }
275- Hard link count after: ${Str . trim ( stat_after . stdout_utf8 ) }
288+ Hard link count before: ${hard_link_count_before }
289+ Hard link count after: ${hard_link_count_after }
276290 Original content: ${original_content}
277291 Link content: ${link_content}
278292 Content matches: ${Inspect . to_str (original_content == link_content)}
0 commit comments