@@ -15,7 +15,8 @@ with regular files & directories on a filesystem.
15
15
16
16
At the top-level of the module are a set of freestanding functions,
17
17
associated with various filesystem operations. They all operate
18
- on a `PathLike` object.
18
+ on a `ToCStr` object. This trait is already defined for common
19
+ objects such as strings and `Path` instances.
19
20
20
21
All operations in this module, including those as part of `FileStream` et al
21
22
block the task during execution. Most will raise `std::rt::io::{io_error,read_error}`
@@ -30,7 +31,7 @@ free function counterparts.
30
31
*/
31
32
32
33
use prelude:: * ;
33
- use super :: support :: PathLike ;
34
+ use c_str :: ToCStr ;
34
35
use super :: { Reader , Writer , Seek } ;
35
36
use super :: { SeekStyle , Read , Write } ;
36
37
use rt:: rtio:: { RtioFileStream , IoFactory , IoFactoryObject } ;
@@ -48,7 +49,6 @@ use path::Path;
48
49
///
49
50
/// use std;
50
51
/// use std::path::Path;
51
- /// use std::rt::io::support::PathLike;
52
52
/// use std::rt::io::file::open;
53
53
/// use std::rt::io::{FileMode, FileAccess};
54
54
///
@@ -87,13 +87,13 @@ use path::Path;
87
87
/// * Attempting to open a file with a `FileAccess` that the user lacks permissions
88
88
/// for
89
89
/// * Filesystem-level errors (full disk, etc)
90
- pub fn open < P : PathLike > ( path : & P ,
91
- mode : FileMode ,
92
- access : FileAccess
93
- ) -> Option < FileStream > {
90
+ pub fn open < P : ToCStr > ( path : & P ,
91
+ mode : FileMode ,
92
+ access : FileAccess
93
+ ) -> Option < FileStream > {
94
94
let open_result = unsafe {
95
95
let io: * mut IoFactoryObject = Local :: unsafe_borrow ( ) ;
96
- ( * io) . fs_open ( path, mode, access)
96
+ ( * io) . fs_open ( & path. to_c_str ( ) , mode, access)
97
97
} ;
98
98
match open_result {
99
99
Ok ( fd) => Some ( FileStream {
@@ -113,7 +113,6 @@ pub fn open<P: PathLike>(path: &P,
113
113
///
114
114
/// use std;
115
115
/// use std::path::Path;
116
- /// use std::rt::io::support::PathLike;
117
116
/// use std::rt::io::file::unlink;
118
117
///
119
118
/// let p = &Path("/some/file/path.txt");
@@ -129,10 +128,10 @@ pub fn open<P: PathLike>(path: &P,
129
128
///
130
129
/// This function will raise an `io_error` condition if the user lacks permissions to
131
130
/// remove the file or if some other filesystem-level error occurs
132
- pub fn unlink < P : PathLike > ( path : & P ) {
131
+ pub fn unlink < P : ToCStr > ( path : & P ) {
133
132
let unlink_result = unsafe {
134
133
let io: * mut IoFactoryObject = Local :: unsafe_borrow ( ) ;
135
- ( * io) . fs_unlink ( path)
134
+ ( * io) . fs_unlink ( & path. to_c_str ( ) )
136
135
} ;
137
136
match unlink_result {
138
137
Ok ( _) => ( ) ,
@@ -148,7 +147,6 @@ pub fn unlink<P: PathLike>(path: &P) {
148
147
///
149
148
/// use std;
150
149
/// use std::path::Path;
151
- /// use std::rt::io::support::PathLike;
152
150
/// use std::rt::io::file::mkdir;
153
151
///
154
152
/// let p = &Path("/some/dir");
@@ -159,10 +157,10 @@ pub fn unlink<P: PathLike>(path: &P) {
159
157
///
160
158
/// This call will raise an `io_error` condition if the user lacks permissions to make a
161
159
/// new directory at the provided path, or if the directory already exists
162
- pub fn mkdir < P : PathLike > ( path : & P ) {
160
+ pub fn mkdir < P : ToCStr > ( path : & P ) {
163
161
let mkdir_result = unsafe {
164
162
let io: * mut IoFactoryObject = Local :: unsafe_borrow ( ) ;
165
- ( * io) . fs_mkdir ( path)
163
+ ( * io) . fs_mkdir ( & path. to_c_str ( ) )
166
164
} ;
167
165
match mkdir_result {
168
166
Ok ( _) => ( ) ,
@@ -178,7 +176,6 @@ pub fn mkdir<P: PathLike>(path: &P) {
178
176
///
179
177
/// use std;
180
178
/// use std::path::Path;
181
- /// use std::rt::io::support::PathLike;
182
179
/// use std::rt::io::file::rmdir;
183
180
///
184
181
/// let p = &Path("/some/dir");
@@ -189,10 +186,10 @@ pub fn mkdir<P: PathLike>(path: &P) {
189
186
///
190
187
/// This call will raise an `io_error` condition if the user lacks permissions to remove the
191
188
/// directory at the provided path, or if the directory isn't empty
192
- pub fn rmdir < P : PathLike > ( path : & P ) {
189
+ pub fn rmdir < P : ToCStr > ( path : & P ) {
193
190
let rmdir_result = unsafe {
194
191
let io: * mut IoFactoryObject = Local :: unsafe_borrow ( ) ;
195
- ( * io) . fs_rmdir ( path)
192
+ ( * io) . fs_rmdir ( & path. to_c_str ( ) )
196
193
} ;
197
194
match rmdir_result {
198
195
Ok ( _) => ( ) ,
@@ -204,16 +201,15 @@ pub fn rmdir<P: PathLike>(path: &P) {
204
201
205
202
/// Get information on the file, directory, etc at the provided path
206
203
///
207
- /// Given a `rt::io::support::PathLike` , query the file system to get
208
- /// information about a file, directory, etc.
204
+ /// Given a path , query the file system to get information about a file,
205
+ /// directory, etc.
209
206
///
210
207
/// Returns a `Some(std::rt::io::PathInfo)` on success
211
208
///
212
209
/// # Example
213
210
///
214
211
/// use std;
215
212
/// use std::path::Path;
216
- /// use std::rt::io::support::PathLike;
217
213
/// use std::rt::io::file::stat;
218
214
///
219
215
/// let p = &Path("/some/file/path.txt");
@@ -238,10 +234,10 @@ pub fn rmdir<P: PathLike>(path: &P) {
238
234
/// This call will raise an `io_error` condition if the user lacks the requisite
239
235
/// permissions to perform a `stat` call on the given path or if there is no
240
236
/// entry in the filesystem at the provided path.
241
- pub fn stat < P : PathLike > ( path : & P ) -> Option < FileStat > {
237
+ pub fn stat < P : ToCStr > ( path : & P ) -> Option < FileStat > {
242
238
let open_result = unsafe {
243
239
let io: * mut IoFactoryObject = Local :: unsafe_borrow ( ) ;
244
- ( * io) . fs_stat ( path)
240
+ ( * io) . fs_stat ( & path. to_c_str ( ) )
245
241
} ;
246
242
match open_result {
247
243
Ok ( p) => {
@@ -260,7 +256,6 @@ pub fn stat<P: PathLike>(path: &P) -> Option<FileStat> {
260
256
///
261
257
/// use std;
262
258
/// use std::path::Path;
263
- /// use std::rt::io::support::PathLike;
264
259
/// use std::rt::io::file::readdir;
265
260
///
266
261
/// fn visit_dirs(dir: &Path, cb: &fn(&Path)) {
@@ -279,10 +274,10 @@ pub fn stat<P: PathLike>(path: &P) -> Option<FileStat> {
279
274
/// Will raise an `io_error` condition if the provided `path` doesn't exist,
280
275
/// the process lacks permissions to view the contents or if the `path` points
281
276
/// at a non-directory file
282
- pub fn readdir < P : PathLike > ( path : & P ) -> Option < ~[ Path ] > {
277
+ pub fn readdir < P : ToCStr > ( path : & P ) -> Option < ~[ Path ] > {
283
278
let readdir_result = unsafe {
284
279
let io: * mut IoFactoryObject = Local :: unsafe_borrow ( ) ;
285
- ( * io) . fs_readdir ( path, 0 )
280
+ ( * io) . fs_readdir ( & path. to_c_str ( ) , 0 )
286
281
} ;
287
282
match readdir_result {
288
283
Ok ( p) => {
0 commit comments