Skip to content

Commit bd1a2da

Browse files
ericktgraydon
authored andcommitted
---
yaml --- r: 36397 b: refs/heads/try2 c: a27f523 h: refs/heads/master i: 36395: 9006419 v: v3
1 parent 8305737 commit bd1a2da

File tree

3 files changed

+290
-2
lines changed

3 files changed

+290
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 20c11ca7577480baadd2fb905bdeff3c1c17604a
8+
refs/heads/try2: a27f5239bdeb48055b40ccf3c3cd176e1971b2ac
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libcore/path.rs

Lines changed: 265 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,270 @@ pub pure fn Path(s: &str) -> Path {
6868
PosixPath(s)
6969
}
7070

71+
#[cfg(target_os = "linux")]
72+
mod stat {
73+
#[cfg(target_arch = "x86")]
74+
pub mod arch {
75+
pub fn default_stat() -> libc::stat {
76+
libc::stat {
77+
st_dev: 0,
78+
__pad1: 0,
79+
st_ino: 0,
80+
st_mode: 0,
81+
st_nlink: 0,
82+
st_uid: 0,
83+
st_gid: 0,
84+
st_rdev: 0,
85+
__pad2: 0,
86+
st_size: 0,
87+
st_blksize: 0,
88+
st_blocks: 0,
89+
st_atime: 0,
90+
st_atime_nsec: 0,
91+
st_mtime: 0,
92+
st_mtime_nsec: 0,
93+
st_ctime: 0,
94+
st_ctime_nsec: 0,
95+
__unused4: 0,
96+
__unused5: 0,
97+
}
98+
}
99+
}
100+
101+
#[cfg(target_arch = "x86_64")]
102+
pub mod arch {
103+
pub fn default_stat() -> libc::stat {
104+
libc::stat {
105+
st_dev: 0,
106+
st_ino: 0,
107+
st_nlink: 0,
108+
st_mode: 0,
109+
st_uid: 0,
110+
st_gid: 0,
111+
__pad0: 0,
112+
st_rdev: 0,
113+
st_size: 0,
114+
st_blksize: 0,
115+
st_blocks: 0,
116+
st_atime: 0,
117+
st_atime_nsec: 0,
118+
st_mtime: 0,
119+
st_mtime_nsec: 0,
120+
st_ctime: 0,
121+
st_ctime_nsec: 0,
122+
__unused: [0, 0, 0],
123+
}
124+
}
125+
}
126+
}
127+
128+
#[cfg(target_os = "freebsd")]
129+
mod stat {
130+
#[cfg(target_arch = "x86_64")]
131+
pub mod arch {
132+
pub fn default_stat() -> libc::stat {
133+
libc::stat {
134+
st_dev: 0,
135+
st_ino: 0,
136+
st_mode: 0,
137+
st_nlink: 0,
138+
st_uid: 0,
139+
st_gid: 0,
140+
st_rdev: 0,
141+
st_atime: 0,
142+
st_atime_nsec: 0,
143+
st_mtime: 0,
144+
st_mtime_nsec: 0,
145+
st_ctime: 0,
146+
st_ctime_nsec: 0,
147+
st_size: 0,
148+
st_blocks: 0,
149+
st_blksize: 0,
150+
st_flags: 0,
151+
st_gen: 0,
152+
st_lspare: 0,
153+
st_birthtime: 0,
154+
st_birthtime_nsec: 0,
155+
__unused: [0, 0],
156+
}
157+
}
158+
}
159+
}
160+
161+
#[cfg(target_os = "macos")]
162+
mod stat {
163+
pub mod arch {
164+
pub fn default_stat() -> libc::stat {
165+
libc::stat {
166+
st_dev: 0,
167+
st_mode: 0,
168+
st_nlink: 0,
169+
st_ino: 0,
170+
st_uid: 0,
171+
st_gid: 0,
172+
st_rdev: 0,
173+
st_atime: 0,
174+
st_atime_nsec: 0,
175+
st_mtime: 0,
176+
st_mtime_nsec: 0,
177+
st_ctime: 0,
178+
st_ctime_nsec: 0,
179+
st_birthtime: 0,
180+
st_birthtime_nsec: 0,
181+
st_size: 0,
182+
st_blocks: 0,
183+
st_blksize: 0,
184+
st_flags: 0,
185+
st_gen: 0,
186+
st_lspare: 0,
187+
st_qspare: [0, 0],
188+
}
189+
}
190+
}
191+
}
192+
193+
#[cfg(target_os = "windows")]
194+
mod stat {
195+
pub mod arch {
196+
pub fn default_stat() -> libc::stat {
197+
libc::stat {
198+
st_dev: 0,
199+
st_ino: 0,
200+
st_mode: 0,
201+
st_nlink: 0,
202+
st_uid: 0,
203+
st_gid: 0,
204+
st_rdev: 0,
205+
st_size: 0,
206+
st_atime: 0,
207+
st_mtime: 0,
208+
st_ctime: 0,
209+
}
210+
}
211+
}
212+
}
213+
214+
215+
impl Path {
216+
fn stat(&self) -> Option<libc::stat> {
217+
do str::as_c_str(self.to_str()) |buf| {
218+
let mut st = stat::arch::default_stat();
219+
let r = libc::stat(buf, ptr::mut_addr_of(&st));
220+
221+
if r == 0 { Some(move st) } else { None }
222+
}
223+
}
224+
225+
fn lstat(&self) -> Option<libc::stat> {
226+
do str::as_c_str(self.to_str()) |buf| {
227+
let mut st = stat::arch::default_stat();
228+
let r = libc::lstat(buf, ptr::mut_addr_of(&st));
229+
230+
if r == 0 { Some(move st) } else { None }
231+
}
232+
}
233+
234+
fn exists(&self) -> bool {
235+
match self.stat() {
236+
None => false,
237+
Some(_) => true,
238+
}
239+
}
240+
241+
fn get_size(&self) -> Option<i64> {
242+
match self.stat() {
243+
None => None,
244+
Some(ref st) => Some(st.st_size as i64),
245+
}
246+
}
247+
248+
fn get_mode(&self) -> Option<uint> {
249+
match self.stat() {
250+
None => None,
251+
Some(ref st) => Some(st.st_mode as uint),
252+
}
253+
}
254+
}
255+
256+
#[cfg(target_os = "freebsd")]
257+
#[cfg(target_os = "linux")]
258+
#[cfg(target_os = "macos")]
259+
impl Path {
260+
fn get_atime(&self) -> Option<(i64, int)> {
261+
match self.stat() {
262+
None => None,
263+
Some(ref st) => {
264+
Some((st.st_atime as i64,
265+
st.st_atime_nsec as int))
266+
}
267+
}
268+
}
269+
270+
fn get_mtime(&self) -> Option<(i64, int)> {
271+
match self.stat() {
272+
None => None,
273+
Some(ref st) => {
274+
Some((st.st_mtime as i64,
275+
st.st_mtime_nsec as int))
276+
}
277+
}
278+
}
279+
280+
fn get_ctime(&self) -> Option<(i64, int)> {
281+
match self.stat() {
282+
None => None,
283+
Some(ref st) => {
284+
Some((st.st_ctime as i64,
285+
st.st_ctime_nsec as int))
286+
}
287+
}
288+
}
289+
}
290+
291+
#[cfg(target_os = "freebsd")]
292+
#[cfg(target_os = "macos")]
293+
impl Path {
294+
fn get_birthtime(&self) -> Option<(i64, int)> {
295+
match self.stat() {
296+
None => None,
297+
Some(ref st) => {
298+
Some((st.st_birthtime as i64,
299+
st.st_birthtime_nsec as int))
300+
}
301+
}
302+
}
303+
}
304+
305+
#[cfg(target_os = "win32")]
306+
impl Path {
307+
fn get_atime(&self) -> Option<(i64, int)> {
308+
match self.stat() {
309+
None => None,
310+
Some(ref st) => {
311+
Some((st.st_atime as i64, 0))
312+
}
313+
}
314+
}
315+
316+
fn get_mtime(&self) -> Option<(i64, int)> {
317+
match self.stat() {
318+
None => None,
319+
Some(ref st) => {
320+
Some((st.st_mtime as i64, 0))
321+
}
322+
}
323+
}
324+
325+
fn get_ctime(&self) -> Option<(i64, int)> {
326+
match self.stat() {
327+
None => None,
328+
Some(ref st) => {
329+
Some((st.st_ctime as i64, 0))
330+
}
331+
}
332+
}
333+
}
334+
71335
impl PosixPath : ToStr {
72336
pure fn to_str() -> ~str {
73337
let mut s = ~"";
@@ -539,7 +803,7 @@ mod windows {
539803
}
540804
}
541805

542-
#[cfg(tests)]
806+
#[cfg(test)]
543807
mod tests {
544808
#[test]
545809
fn test_double_slash_collapsing() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extern mod std;
2+
use io::WriterUtil;
3+
use std::tempfile;
4+
5+
fn main() {
6+
let dir = option::unwrap(tempfile::mkdtemp(&Path("."), ""));
7+
let path = dir.with_filename("file");
8+
9+
{
10+
match io::file_writer(&path, [io::Create, io::Truncate]) {
11+
Err(e) => fail e,
12+
Ok(f) => {
13+
for uint::range(0, 1000) |_i| {
14+
f.write_u8(0);
15+
}
16+
}
17+
}
18+
}
19+
20+
assert path.exists();
21+
assert path.get_size() == Some(1000);
22+
23+
os::remove_dir(&dir);
24+
}

0 commit comments

Comments
 (0)