Skip to content

Commit 0d4d242

Browse files
committed
Runtime removal: refactor fs
This moves the filesystem implementation from libnative into the new `sys` modules, refactoring along the way and hooking into `std::io::fs`. Because this eliminates APIs in `libnative` and `librustrt`, it is a: [breaking-change] This functionality is likely to be available publicly, in some form, from `std` in the future.
1 parent 49630b3 commit 0d4d242

File tree

9 files changed

+662
-1166
lines changed

9 files changed

+662
-1166
lines changed

src/libnative/io/file_unix.rs

Lines changed: 0 additions & 554 deletions
This file was deleted.

src/libnative/io/mod.rs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use std::rt::rtio::{mod, IoResult, IoError};
3030
use std::num;
3131

3232
// Local re-exports
33-
pub use self::file::FileDesc;
3433
pub use self::process::Process;
3534

3635
mod helper_thread;
@@ -41,13 +40,6 @@ pub mod net;
4140
pub mod process;
4241
mod util;
4342

44-
#[cfg(unix)]
45-
#[path = "file_unix.rs"]
46-
pub mod file;
47-
#[cfg(windows)]
48-
#[path = "file_windows.rs"]
49-
pub mod file;
50-
5143
#[cfg(any(target_os = "macos",
5244
target_os = "ios",
5345
target_os = "freebsd",
@@ -92,25 +84,6 @@ fn last_error() -> IoError {
9284
}
9385
}
9486

95-
// unix has nonzero values as errors
96-
fn mkerr_libc <Int: num::Zero>(ret: Int) -> IoResult<()> {
97-
if !ret.is_zero() {
98-
Err(last_error())
99-
} else {
100-
Ok(())
101-
}
102-
}
103-
104-
// windows has zero values as errors
105-
#[cfg(windows)]
106-
fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> {
107-
if ret == 0 {
108-
Err(last_error())
109-
} else {
110-
Ok(())
111-
}
112-
}
113-
11487
#[cfg(windows)]
11588
#[inline]
11689
fn retry<I> (f: || -> I) -> I { f() } // PR rust-lang/rust/#17020
@@ -199,62 +172,6 @@ impl rtio::IoFactory for IoFactory {
199172
addrinfo::GetAddrInfoRequest::run(host, servname, hint)
200173
}
201174

202-
// filesystem operations
203-
fn fs_from_raw_fd(&mut self, fd: c_int, close: rtio::CloseBehavior)
204-
-> Box<rtio::RtioFileStream + Send> {
205-
let close = match close {
206-
rtio::CloseSynchronously | rtio::CloseAsynchronously => true,
207-
rtio::DontClose => false
208-
};
209-
box file::FileDesc::new(fd, close) as Box<rtio::RtioFileStream + Send>
210-
}
211-
fn fs_open(&mut self, path: &CString, fm: rtio::FileMode,
212-
fa: rtio::FileAccess)
213-
-> IoResult<Box<rtio::RtioFileStream + Send>>
214-
{
215-
file::open(path, fm, fa).map(|fd| box fd as Box<rtio::RtioFileStream + Send>)
216-
}
217-
fn fs_unlink(&mut self, path: &CString) -> IoResult<()> {
218-
file::unlink(path)
219-
}
220-
fn fs_stat(&mut self, path: &CString) -> IoResult<rtio::FileStat> {
221-
file::stat(path)
222-
}
223-
fn fs_mkdir(&mut self, path: &CString, mode: uint) -> IoResult<()> {
224-
file::mkdir(path, mode)
225-
}
226-
fn fs_chmod(&mut self, path: &CString, mode: uint) -> IoResult<()> {
227-
file::chmod(path, mode)
228-
}
229-
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()> {
230-
file::rmdir(path)
231-
}
232-
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
233-
file::rename(path, to)
234-
}
235-
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<CString>> {
236-
file::readdir(path)
237-
}
238-
fn fs_lstat(&mut self, path: &CString) -> IoResult<rtio::FileStat> {
239-
file::lstat(path)
240-
}
241-
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) -> IoResult<()> {
242-
file::chown(path, uid, gid)
243-
}
244-
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString> {
245-
file::readlink(path)
246-
}
247-
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
248-
file::symlink(src, dst)
249-
}
250-
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
251-
file::link(src, dst)
252-
}
253-
fn fs_utime(&mut self, src: &CString, atime: u64,
254-
mtime: u64) -> IoResult<()> {
255-
file::utime(src, atime, mtime)
256-
}
257-
258175
// misc
259176
fn timer_init(&mut self) -> IoResult<Box<rtio::RtioTimer + Send>> {
260177
timer::Timer::new().map(|t| box t as Box<rtio::RtioTimer + Send>)

src/libnative/io/timer_unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use std::sync::atomic;
5656
use std::comm;
5757

5858
use io::c;
59-
use io::file::FileDesc;
59+
use platform_imp::fs::FileDesc;
6060
use io::helper_thread::Helper;
6161

6262
helper_init!(static HELPER: Helper<Req>)

src/librustrt/rtio.rs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,6 @@ pub trait RemoteCallback {
5050
fn fire(&mut self);
5151
}
5252

53-
/// Description of what to do when a file handle is closed
54-
pub enum CloseBehavior {
55-
/// Do not close this handle when the object is destroyed
56-
DontClose,
57-
/// Synchronously close the handle, meaning that the task will block when
58-
/// the handle is destroyed until it has been fully closed.
59-
CloseSynchronously,
60-
/// Asynchronously closes a handle, meaning that the task will *not* block
61-
/// when the handle is destroyed, but the handle will still get deallocated
62-
/// and cleaned up (but this will happen asynchronously on the local event
63-
/// loop).
64-
CloseAsynchronously,
65-
}
66-
6753
/// Data needed to spawn a process. Serializes the `std::io::process::Command`
6854
/// builder.
6955
pub struct ProcessConfig<'a> {
@@ -202,28 +188,6 @@ pub trait IoFactory {
202188
hint: Option<AddrinfoHint>)
203189
-> IoResult<Vec<AddrinfoInfo>>;
204190

205-
// filesystem operations
206-
fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior)
207-
-> Box<RtioFileStream + Send>;
208-
fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess)
209-
-> IoResult<Box<RtioFileStream + Send>>;
210-
fn fs_unlink(&mut self, path: &CString) -> IoResult<()>;
211-
fn fs_stat(&mut self, path: &CString) -> IoResult<FileStat>;
212-
fn fs_mkdir(&mut self, path: &CString, mode: uint) -> IoResult<()>;
213-
fn fs_chmod(&mut self, path: &CString, mode: uint) -> IoResult<()>;
214-
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()>;
215-
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()>;
216-
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
217-
IoResult<Vec<CString>>;
218-
fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
219-
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
220-
IoResult<()>;
221-
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString>;
222-
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
223-
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
224-
fn fs_utime(&mut self, src: &CString, atime: u64, mtime: u64) ->
225-
IoResult<()>;
226-
227191
// misc
228192
fn timer_init(&mut self) -> IoResult<Box<RtioTimer + Send>>;
229193
fn spawn(&mut self, cfg: ProcessConfig)
@@ -296,19 +260,6 @@ pub trait RtioTimer {
296260
fn period(&mut self, msecs: u64, cb: Box<Callback + Send>);
297261
}
298262

299-
pub trait RtioFileStream {
300-
fn read(&mut self, buf: &mut [u8]) -> IoResult<int>;
301-
fn write(&mut self, buf: &[u8]) -> IoResult<()>;
302-
fn pread(&mut self, buf: &mut [u8], offset: u64) -> IoResult<int>;
303-
fn pwrite(&mut self, buf: &[u8], offset: u64) -> IoResult<()>;
304-
fn seek(&mut self, pos: i64, whence: SeekStyle) -> IoResult<u64>;
305-
fn tell(&self) -> IoResult<u64>;
306-
fn fsync(&mut self) -> IoResult<()>;
307-
fn datasync(&mut self) -> IoResult<()>;
308-
fn truncate(&mut self, offset: i64) -> IoResult<()>;
309-
fn fstat(&mut self) -> IoResult<FileStat>;
310-
}
311-
312263
pub trait RtioProcess {
313264
fn id(&self) -> libc::pid_t;
314265
fn kill(&mut self, signal: int) -> IoResult<()>;
@@ -399,43 +350,6 @@ pub enum ProcessExit {
399350
ExitSignal(int),
400351
}
401352

402-
pub enum FileMode {
403-
Open,
404-
Append,
405-
Truncate,
406-
}
407-
408-
pub enum FileAccess {
409-
Read,
410-
Write,
411-
ReadWrite,
412-
}
413-
414-
pub struct FileStat {
415-
pub size: u64,
416-
pub kind: u64,
417-
pub perm: u64,
418-
pub created: u64,
419-
pub modified: u64,
420-
pub accessed: u64,
421-
pub device: u64,
422-
pub inode: u64,
423-
pub rdev: u64,
424-
pub nlink: u64,
425-
pub uid: u64,
426-
pub gid: u64,
427-
pub blksize: u64,
428-
pub blocks: u64,
429-
pub flags: u64,
430-
pub gen: u64,
431-
}
432-
433-
pub enum SeekStyle {
434-
SeekSet,
435-
SeekEnd,
436-
SeekCur,
437-
}
438-
439353
pub struct AddrinfoHint {
440354
pub family: uint,
441355
pub socktype: uint,

0 commit comments

Comments
 (0)