Skip to content

Commit 5f4b2f6

Browse files
committed
---
yaml --- r: 80605 b: refs/heads/auto c: af65057 h: refs/heads/master i: 80603: ea71c4e v: v3
1 parent d2c7868 commit 5f4b2f6

File tree

10 files changed

+709
-207
lines changed

10 files changed

+709
-207
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 66ecff2b136dccabae98d2413632ff5177313205
16+
refs/heads/auto: af650572e0fceb94b387db50ee31f19ee000fe4b
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/mk/platform.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ else
4747
CFG_GCCISH_CFLAGS += -O2
4848
endif
4949

50-
# The soname thing is for supporting a statically linked jemalloc.
51-
# see https://blog.mozilla.org/jseward/2012/06/05/valgrind-now-supports-jemalloc-builds-directly/
5250
ifdef CFG_VALGRIND
5351
CFG_VALGRIND += --error-exitcode=100 \
54-
--soname-synonyms=somalloc=NONE \
5552
--quiet \
5653
--suppressions=$(CFG_SRC_DIR)src/etc/x86.supp \
5754
$(OS_SUPP)

branches/auto/src/libstd/rt/io/file.rs

Lines changed: 156 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
use prelude::*;
1212
use super::support::PathLike;
1313
use super::{Reader, Writer, Seek};
14-
use super::{SeekSet, SeekCur, SeekEnd, SeekStyle};
14+
use super::{SeekStyle,SeekSet, SeekCur, SeekEnd,
15+
Open, Read, Create, ReadWrite};
1516
use rt::rtio::{RtioFileStream, IoFactory, IoFactoryObject};
1617
use rt::io::{io_error, read_error, EndOfFile,
17-
FileMode, FileAccess, Open, Read, Create, ReadWrite};
18+
FileMode, FileAccess, FileStat};
1819
use rt::local::Local;
19-
use rt::test::*;
20+
use option::{Some, None};
21+
use path::Path;
22+
use super::super::test::*;
2023

2124
/// Open a file for reading/writing, as indicated by `path`.
2225
pub fn open<P: PathLike>(path: &P,
@@ -145,6 +148,123 @@ impl Seek for FileStream {
145148
}
146149
}
147150

151+
pub struct FileInfo(Path);
152+
153+
/// FIXME: DOCS
154+
impl<'self> FileInfo {
155+
pub fn new<P: PathLike>(path: &P) -> FileInfo {
156+
do path.path_as_str |p| {
157+
FileInfo(Path(p))
158+
}
159+
}
160+
// FIXME #8873 can't put this in FileSystemInfo
161+
pub fn get_path(&'self self) -> &'self Path {
162+
&(**self)
163+
}
164+
pub fn stat(&self) -> Option<FileStat> {
165+
do io_error::cond.trap(|_| {
166+
// FIXME: can we do something more useful here?
167+
}).inside {
168+
stat(self.get_path())
169+
}
170+
}
171+
pub fn exists(&self) -> bool {
172+
match self.stat() {
173+
Some(s) => {
174+
match s.is_file {
175+
true => {
176+
true
177+
},
178+
false => {
179+
// FIXME: raise condition?
180+
false
181+
}
182+
}
183+
},
184+
None => false
185+
}
186+
}
187+
pub fn is_file(&self) -> bool {
188+
match self.stat() {
189+
Some(s) => s.is_file,
190+
None => {
191+
// FIXME: raise condition
192+
false
193+
}
194+
}
195+
}
196+
pub fn open(&self, mode: FileMode, access: FileAccess) -> Option<FileStream> {
197+
match self.is_file() {
198+
true => {
199+
open(self.get_path(), mode, access)
200+
},
201+
false => {
202+
// FIXME: raise condition
203+
None
204+
}
205+
}
206+
}
207+
//fn open_read(&self) -> FileStream;
208+
//fn open_write(&self) -> FileStream;
209+
//fn create(&self) -> FileStream;
210+
//fn truncate(&self) -> FileStream;
211+
//fn open_or_create(&self) -> FileStream;
212+
//fn create_or_truncate(&self) -> FileStream;
213+
//fn unlink(&self);
214+
}
215+
216+
/*
217+
/// FIXME: DOCS
218+
impl DirectoryInfo<'self> {
219+
fn new<P: PathLike>(path: &P) -> FileInfo {
220+
FileInfo(Path(path.path_as_str()))
221+
}
222+
// FIXME #8873 can't put this in FileSystemInfo
223+
fn get_path(&'self self) -> &'self Path {
224+
&*self
225+
}
226+
fn stat(&self) -> Option<FileStat> {
227+
file::stat(self.get_path())
228+
}
229+
fn exists(&self) -> bool {
230+
do io_error::cond.trap(|_| {
231+
}).inside {
232+
match self.stat() {
233+
Some(_) => true,
234+
None => false
235+
}
236+
}
237+
}
238+
fn is_dir(&self) -> bool {
239+
240+
}
241+
fn create(&self);
242+
fn get_subdirs(&self, filter: &str) -> ~[Path];
243+
fn get_files(&self, filter: &str) -> ~[Path];
244+
}
245+
*/
246+
247+
/// Given a `rt::io::support::PathLike`, query the file system to get
248+
/// information about a file, directory, etc.
249+
///
250+
/// Returns a `Some(PathInfo)` on success, and raises a `rt::io::IoError` condition
251+
/// on failure and returns `None`.
252+
pub fn stat<P: PathLike>(path: &P) -> Option<FileStat> {
253+
let open_result = unsafe {
254+
let io: *mut IoFactoryObject = Local::unsafe_borrow();
255+
(*io).fs_stat(path)
256+
};
257+
match open_result {
258+
Ok(p) => {
259+
Some(p)
260+
},
261+
Err(ioerr) => {
262+
read_error::cond.raise(ioerr);
263+
None
264+
}
265+
}
266+
}
267+
148268
fn file_test_smoke_test_impl() {
149269
do run_in_mt_newsched_task {
150270
let message = "it's alright. have a good time";
@@ -273,7 +393,6 @@ fn file_test_io_seek_and_tell_smoke_test() {
273393
}
274394

275395
fn file_test_io_seek_and_write_impl() {
276-
use io;
277396
do run_in_mt_newsched_task {
278397
use str;
279398
let initial_msg = "food-is-yummy";
@@ -293,8 +412,7 @@ fn file_test_io_seek_and_write_impl() {
293412
read_stream.read(read_mem);
294413
}
295414
unlink(filename);
296-
let read_str = str::from_utf8(read_mem);
297-
io::println(fmt!("read_str: '%?' final_msg: '%?'", read_str, final_msg));
415+
let read_str = str::from_bytes(read_mem);
298416
assert!(read_str == final_msg.to_owned());
299417
}
300418
}
@@ -343,3 +461,35 @@ fn file_test_io_seek_shakedown_impl() {
343461
fn file_test_io_seek_shakedown() {
344462
file_test_io_seek_shakedown_impl();
345463
}
464+
465+
#[test]
466+
fn file_test_stat_is_correct_on_is_file() {
467+
do run_in_newsched_task {
468+
let filename = &Path("./tmp/file_stat_correct_on_is_file.txt");
469+
{
470+
let mut fs = open(filename, Create, ReadWrite).unwrap();
471+
let msg = "hw";
472+
fs.write(msg.as_bytes());
473+
}
474+
let stat_res = match stat(filename) {
475+
Some(s) => s,
476+
None => fail!("shouldn't happen")
477+
};
478+
assert!(stat_res.is_file);
479+
}
480+
}
481+
482+
#[test]
483+
fn file_test_stat_is_correct_on_is_dir() {
484+
//assert!(false);
485+
}
486+
487+
#[test]
488+
fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() {
489+
//assert!(false);
490+
}
491+
492+
#[test]
493+
fn file_test_fileinfo_check_exists_before_and_after_file_creation() {
494+
//assert!(false);
495+
}

branches/auto/src/libstd/rt/io/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ Out of scope
245245
use prelude::*;
246246
use to_str::ToStr;
247247
use str::{StrSlice, OwnedStr};
248+
use path::Path;
248249

249250
// Reexports
250251
pub use self::stdio::stdin;
@@ -596,3 +597,26 @@ pub enum FileAccess {
596597
Write,
597598
ReadWrite
598599
}
600+
601+
pub struct FileStat {
602+
/// A `Path` object containing information about the `PathInfo`'s location
603+
path: Path,
604+
/// `true` if the file pointed at by the `PathInfo` is a regular file
605+
is_file: bool,
606+
/// `true` if the file pointed at by the `PathInfo` is a directory
607+
is_dir: bool
608+
// `true` if the file pointed at by the `PathInfo` is a link (what this means
609+
// is platform dependant)
610+
/*
611+
/// The file pointed at by the `PathInfo`'s size in bytes
612+
size: u64,
613+
/// The file pointed at by the `PathInfo`'s time date in platform-dependent msecs
614+
created: u64,
615+
/// The file pointed at by the `PathInfo`'s last-modification time in
616+
/// platform-dependent msecs
617+
modified: u64,
618+
/// The file pointed at by the `PathInfo`'s last-accessd time (e.g. read) in
619+
/// platform-dependent msecs
620+
accessed: u64,
621+
*/
622+
}

branches/auto/src/libstd/rt/rtio.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rt::uv::uvio;
1818
use path::Path;
1919
use super::io::support::PathLike;
2020
use super::io::{SeekStyle};
21-
use super::io::{FileMode, FileAccess};
21+
use super::io::{FileMode, FileAccess, FileStat};
2222

2323
// XXX: ~object doesn't work currently so these are some placeholder
2424
// types to use instead
@@ -74,6 +74,13 @@ pub trait IoFactory {
7474
-> Result<~RtioFileStream, IoError>;
7575
fn fs_unlink<P: PathLike>(&mut self, path: &P) -> Result<(), IoError>;
7676
fn get_host_addresses(&mut self, host: &str) -> Result<~[IpAddr], IoError>;
77+
fn fs_stat<P: PathLike>(&mut self, path: &P) -> Result<FileStat, IoError>;
78+
//fn fs_fstat(&mut self, fd: c_int) -> Result<FileStat, IoError>;
79+
}
80+
81+
pub trait RtioStream {
82+
fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError>;
83+
fn write(&mut self, buf: &[u8]) -> Result<(), IoError>;
7784
}
7885

7986
pub trait RtioTcpListener : RtioSocket {

0 commit comments

Comments
 (0)