Skip to content
Prev Previous commit
Next Next commit
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.
  • Loading branch information
aturon committed Nov 9, 2014
commit 0c1e1ff1e300868a29405a334e65eae690df971d
554 changes: 0 additions & 554 deletions src/libnative/io/file_unix.rs

This file was deleted.

83 changes: 0 additions & 83 deletions src/libnative/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use std::rt::rtio::{mod, IoResult, IoError};
use std::num;

// Local re-exports
pub use self::file::FileDesc;
pub use self::process::Process;

mod helper_thread;
Expand All @@ -41,13 +40,6 @@ pub mod net;
pub mod process;
mod util;

#[cfg(unix)]
#[path = "file_unix.rs"]
pub mod file;
#[cfg(windows)]
#[path = "file_windows.rs"]
pub mod file;

#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
Expand Down Expand Up @@ -92,25 +84,6 @@ fn last_error() -> IoError {
}
}

// unix has nonzero values as errors
fn mkerr_libc <Int: num::Zero>(ret: Int) -> IoResult<()> {
if !ret.is_zero() {
Err(last_error())
} else {
Ok(())
}
}

// windows has zero values as errors
#[cfg(windows)]
fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> {
if ret == 0 {
Err(last_error())
} else {
Ok(())
}
}

#[cfg(windows)]
#[inline]
fn retry<I> (f: || -> I) -> I { f() } // PR rust-lang/rust/#17020
Expand Down Expand Up @@ -199,62 +172,6 @@ impl rtio::IoFactory for IoFactory {
addrinfo::GetAddrInfoRequest::run(host, servname, hint)
}

// filesystem operations
fn fs_from_raw_fd(&mut self, fd: c_int, close: rtio::CloseBehavior)
-> Box<rtio::RtioFileStream + Send> {
let close = match close {
rtio::CloseSynchronously | rtio::CloseAsynchronously => true,
rtio::DontClose => false
};
box file::FileDesc::new(fd, close) as Box<rtio::RtioFileStream + Send>
}
fn fs_open(&mut self, path: &CString, fm: rtio::FileMode,
fa: rtio::FileAccess)
-> IoResult<Box<rtio::RtioFileStream + Send>>
{
file::open(path, fm, fa).map(|fd| box fd as Box<rtio::RtioFileStream + Send>)
}
fn fs_unlink(&mut self, path: &CString) -> IoResult<()> {
file::unlink(path)
}
fn fs_stat(&mut self, path: &CString) -> IoResult<rtio::FileStat> {
file::stat(path)
}
fn fs_mkdir(&mut self, path: &CString, mode: uint) -> IoResult<()> {
file::mkdir(path, mode)
}
fn fs_chmod(&mut self, path: &CString, mode: uint) -> IoResult<()> {
file::chmod(path, mode)
}
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()> {
file::rmdir(path)
}
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
file::rename(path, to)
}
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<CString>> {
file::readdir(path)
}
fn fs_lstat(&mut self, path: &CString) -> IoResult<rtio::FileStat> {
file::lstat(path)
}
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) -> IoResult<()> {
file::chown(path, uid, gid)
}
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString> {
file::readlink(path)
}
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
file::symlink(src, dst)
}
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
file::link(src, dst)
}
fn fs_utime(&mut self, src: &CString, atime: u64,
mtime: u64) -> IoResult<()> {
file::utime(src, atime, mtime)
}

// misc
fn timer_init(&mut self) -> IoResult<Box<rtio::RtioTimer + Send>> {
timer::Timer::new().map(|t| box t as Box<rtio::RtioTimer + Send>)
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/timer_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use std::sync::atomic;
use std::comm;

use io::c;
use io::file::FileDesc;
use platform_imp::fs::FileDesc;
use io::helper_thread::Helper;

helper_init!(static HELPER: Helper<Req>)
Expand Down
86 changes: 0 additions & 86 deletions src/librustrt/rtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@ pub trait RemoteCallback {
fn fire(&mut self);
}

/// Description of what to do when a file handle is closed
pub enum CloseBehavior {
/// Do not close this handle when the object is destroyed
DontClose,
/// Synchronously close the handle, meaning that the task will block when
/// the handle is destroyed until it has been fully closed.
CloseSynchronously,
/// Asynchronously closes a handle, meaning that the task will *not* block
/// when the handle is destroyed, but the handle will still get deallocated
/// and cleaned up (but this will happen asynchronously on the local event
/// loop).
CloseAsynchronously,
}

/// Data needed to spawn a process. Serializes the `std::io::process::Command`
/// builder.
pub struct ProcessConfig<'a> {
Expand Down Expand Up @@ -202,28 +188,6 @@ pub trait IoFactory {
hint: Option<AddrinfoHint>)
-> IoResult<Vec<AddrinfoInfo>>;

// filesystem operations
fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior)
-> Box<RtioFileStream + Send>;
fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess)
-> IoResult<Box<RtioFileStream + Send>>;
fn fs_unlink(&mut self, path: &CString) -> IoResult<()>;
fn fs_stat(&mut self, path: &CString) -> IoResult<FileStat>;
fn fs_mkdir(&mut self, path: &CString, mode: uint) -> IoResult<()>;
fn fs_chmod(&mut self, path: &CString, mode: uint) -> IoResult<()>;
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()>;
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()>;
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
IoResult<Vec<CString>>;
fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
IoResult<()>;
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString>;
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()>;
fn fs_utime(&mut self, src: &CString, atime: u64, mtime: u64) ->
IoResult<()>;

// misc
fn timer_init(&mut self) -> IoResult<Box<RtioTimer + Send>>;
fn spawn(&mut self, cfg: ProcessConfig)
Expand Down Expand Up @@ -296,19 +260,6 @@ pub trait RtioTimer {
fn period(&mut self, msecs: u64, cb: Box<Callback + Send>);
}

pub trait RtioFileStream {
fn read(&mut self, buf: &mut [u8]) -> IoResult<int>;
fn write(&mut self, buf: &[u8]) -> IoResult<()>;
fn pread(&mut self, buf: &mut [u8], offset: u64) -> IoResult<int>;
fn pwrite(&mut self, buf: &[u8], offset: u64) -> IoResult<()>;
fn seek(&mut self, pos: i64, whence: SeekStyle) -> IoResult<u64>;
fn tell(&self) -> IoResult<u64>;
fn fsync(&mut self) -> IoResult<()>;
fn datasync(&mut self) -> IoResult<()>;
fn truncate(&mut self, offset: i64) -> IoResult<()>;
fn fstat(&mut self) -> IoResult<FileStat>;
}

pub trait RtioProcess {
fn id(&self) -> libc::pid_t;
fn kill(&mut self, signal: int) -> IoResult<()>;
Expand Down Expand Up @@ -399,43 +350,6 @@ pub enum ProcessExit {
ExitSignal(int),
}

pub enum FileMode {
Open,
Append,
Truncate,
}

pub enum FileAccess {
Read,
Write,
ReadWrite,
}

pub struct FileStat {
pub size: u64,
pub kind: u64,
pub perm: u64,
pub created: u64,
pub modified: u64,
pub accessed: u64,
pub device: u64,
pub inode: u64,
pub rdev: u64,
pub nlink: u64,
pub uid: u64,
pub gid: u64,
pub blksize: u64,
pub blocks: u64,
pub flags: u64,
pub gen: u64,
}

pub enum SeekStyle {
SeekSet,
SeekEnd,
SeekCur,
}

pub struct AddrinfoHint {
pub family: uint,
pub socktype: uint,
Expand Down
Loading