@@ -1395,3 +1395,61 @@ fn metadata_access_times() {
1395
1395
}
1396
1396
}
1397
1397
}
1398
+
1399
+ /// Test creating hard links to symlinks.
1400
+ #[ test]
1401
+ fn symlink_hard_link ( ) {
1402
+ let tmpdir = tmpdir ( ) ;
1403
+ if !got_symlink_permission ( & tmpdir) {
1404
+ return ;
1405
+ }
1406
+
1407
+ // Create "file", a file.
1408
+ check ! ( tmpdir. create( "file" ) ) ;
1409
+
1410
+ // Create "symlink", a symlink to "file".
1411
+ check ! ( symlink_file( "file" , & tmpdir, "symlink" ) ) ;
1412
+
1413
+ // Create "hard_link", a hard link to "symlink".
1414
+ check ! ( tmpdir. hard_link( "symlink" , & tmpdir, "hard_link" ) ) ;
1415
+
1416
+ // "hard_link" should appear as a symlink.
1417
+ assert ! ( check!( tmpdir. symlink_metadata( "hard_link" ) )
1418
+ . file_type( )
1419
+ . is_symlink( ) ) ;
1420
+
1421
+ // We sould be able to open "file" via any of the above names.
1422
+ let _ = check ! ( tmpdir. open( "file" ) ) ;
1423
+ assert ! ( tmpdir. open( "file.renamed" ) . is_err( ) ) ;
1424
+ let _ = check ! ( tmpdir. open( "symlink" ) ) ;
1425
+ let _ = check ! ( tmpdir. open( "hard_link" ) ) ;
1426
+
1427
+ // Rename "file" to "file.renamed".
1428
+ check ! ( tmpdir. rename( "file" , & tmpdir, "file.renamed" ) ) ;
1429
+
1430
+ // Now, the symlink and the hard link should be dangling.
1431
+ assert ! ( tmpdir. open( "file" ) . is_err( ) ) ;
1432
+ let _ = check ! ( tmpdir. open( "file.renamed" ) ) ;
1433
+ assert ! ( tmpdir. open( "symlink" ) . is_err( ) ) ;
1434
+ assert ! ( tmpdir. open( "hard_link" ) . is_err( ) ) ;
1435
+
1436
+ // The symlink and the hard link should both still point to "file".
1437
+ assert ! ( tmpdir. read_link( "file" ) . is_err( ) ) ;
1438
+ assert ! ( tmpdir. read_link( "file.renamed" ) . is_err( ) ) ;
1439
+ assert_eq ! ( check!( tmpdir. read_link( "symlink" ) ) , Path :: new( "file" ) ) ;
1440
+ assert_eq ! ( check!( tmpdir. read_link( "hard_link" ) ) , Path :: new( "file" ) ) ;
1441
+
1442
+ // Remove "file.renamed".
1443
+ check ! ( tmpdir. remove_file( "file.renamed" ) ) ;
1444
+
1445
+ // Now, we can't open the file by any name.
1446
+ assert ! ( tmpdir. open( "file" ) . is_err( ) ) ;
1447
+ assert ! ( tmpdir. open( "file.renamed" ) . is_err( ) ) ;
1448
+ assert ! ( tmpdir. open( "symlink" ) . is_err( ) ) ;
1449
+ assert ! ( tmpdir. open( "hard_link" ) . is_err( ) ) ;
1450
+
1451
+ // "hard_link" should still appear as a symlink.
1452
+ assert ! ( check!( tmpdir. symlink_metadata( "hard_link" ) )
1453
+ . file_type( )
1454
+ . is_symlink( ) ) ;
1455
+ }
0 commit comments