@@ -23,7 +23,6 @@ fn tmp() -> PathBuf {
23
23
fn test_posix_realpath_alloc ( ) {
24
24
use std:: ffi:: OsString ;
25
25
use std:: ffi:: { CStr , CString } ;
26
- use std:: fs:: { remove_file, File } ;
27
26
use std:: os:: unix:: ffi:: OsStrExt ;
28
27
use std:: os:: unix:: ffi:: OsStringExt ;
29
28
@@ -51,7 +50,6 @@ fn test_posix_realpath_alloc() {
51
50
/// Test non-allocating variant of `realpath`.
52
51
fn test_posix_realpath_noalloc ( ) {
53
52
use std:: ffi:: { CStr , CString } ;
54
- use std:: fs:: { remove_file, File } ;
55
53
use std:: os:: unix:: ffi:: OsStrExt ;
56
54
57
55
let path = tmp ( ) . join ( "miri_test_libc_posix_realpath_noalloc" ) ;
@@ -78,12 +76,8 @@ fn test_posix_realpath_noalloc() {
78
76
79
77
/// Test failure cases for `realpath`.
80
78
fn test_posix_realpath_errors ( ) {
81
- use std:: convert:: TryInto ;
82
79
use std:: ffi:: CString ;
83
- use std:: fs:: { create_dir_all, remove_dir_all} ;
84
80
use std:: io:: ErrorKind ;
85
- use std:: os:: unix:: ffi:: OsStrExt ;
86
- use std:: os:: unix:: fs:: symlink;
87
81
88
82
// Test non-existent path returns an error.
89
83
let c_path = CString :: new ( "./nothing_to_see_here" ) . expect ( "CString::new failed" ) ;
@@ -92,48 +86,6 @@ fn test_posix_realpath_errors() {
92
86
let e = std:: io:: Error :: last_os_error ( ) ;
93
87
assert_eq ! ( e. raw_os_error( ) , Some ( libc:: ENOENT ) ) ;
94
88
assert_eq ! ( e. kind( ) , ErrorKind :: NotFound ) ;
95
-
96
- // Test that a long path returns an error.
97
- //
98
- // Linux first checks if the path exists and macos does not.
99
- // Using an existing path ensures all platforms return `ENAMETOOLONG` given a long path.
100
- //
101
- // Rather than creating a bunch of directories, we create two directories containing symlinks.
102
- // Sadly we can't avoid creating directories and instead use a path like "./././././" or "./../../" as linux
103
- // appears to collapse "." and ".." before checking path length.
104
- let path = tmp ( ) . join ( "posix_realpath_errors" ) ;
105
- // Cleanup before test.
106
- remove_dir_all ( & path) . ok ( ) ;
107
-
108
- // The directories we will put symlinks in.
109
- let x = path. join ( "x/" ) ;
110
- let y = path. join ( "y/" ) ;
111
-
112
- // The symlinks in each directory pointing to each other.
113
- let yx_sym = y. join ( "x" ) ;
114
- let xy_sym = x. join ( "y" ) ;
115
-
116
- // Create directories.
117
- create_dir_all ( & x) . expect ( "dir x" ) ;
118
- create_dir_all ( & y) . expect ( "dir y" ) ;
119
-
120
- // Create symlinks between directories.
121
- symlink ( & x, & yx_sym) . expect ( "symlink x" ) ;
122
- symlink ( & y, & xy_sym) . expect ( "symlink y " ) ;
123
-
124
- // This path exists due to the symlinks created above.
125
- let too_long = path. join ( "x/y/" . repeat ( libc:: PATH_MAX . try_into ( ) . unwrap ( ) ) ) ;
126
-
127
- let c_path = CString :: new ( too_long. into_os_string ( ) . as_bytes ( ) ) . expect ( "CString::new failed" ) ;
128
- let r = unsafe { libc:: realpath ( c_path. as_ptr ( ) , std:: ptr:: null_mut ( ) ) } ;
129
- let e = std:: io:: Error :: last_os_error ( ) ;
130
-
131
- assert ! ( r. is_null( ) ) ;
132
- assert_eq ! ( e. raw_os_error( ) , Some ( libc:: ENAMETOOLONG ) ) ;
133
- assert_eq ! ( e. kind( ) , ErrorKind :: InvalidFilename ) ;
134
-
135
- // Cleanup after test.
136
- remove_dir_all ( & path) . ok ( ) ;
137
89
}
138
90
139
91
#[ cfg( any( target_os = "linux" , target_os = "freebsd" ) ) ]
0 commit comments