|
1 |
| -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
| 1 | +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT |
2 | 2 | // file at the top-level directory of this distribution and at
|
3 | 3 | // http://rust-lang.org/COPYRIGHT.
|
4 | 4 | //
|
@@ -244,10 +244,6 @@ pub fn unlink(path: &Path) -> IoResult<()> {
|
244 | 244 | /// directory, etc. This function will traverse symlinks to query
|
245 | 245 | /// information about the destination file.
|
246 | 246 | ///
|
247 |
| -/// Returns a fully-filled out stat structure on success, and on failure it |
248 |
| -/// will return a dummy stat structure (it is expected that the condition |
249 |
| -/// raised is handled as well). |
250 |
| -/// |
251 | 247 | /// # Example
|
252 | 248 | ///
|
253 | 249 | /// ```rust
|
@@ -652,45 +648,41 @@ impl Seek for File {
|
652 | 648 | impl path::Path {
|
653 | 649 | /// Get information on the file, directory, etc at this path.
|
654 | 650 | ///
|
655 |
| - /// Consult the `file::stat` documentation for more info. |
| 651 | + /// Consult the `fs::stat` documentation for more info. |
656 | 652 | ///
|
657 | 653 | /// This call preserves identical runtime/error semantics with `file::stat`.
|
658 | 654 | pub fn stat(&self) -> IoResult<FileStat> { stat(self) }
|
659 | 655 |
|
660 |
| - /// Boolean value indicator whether the underlying file exists on the local |
661 |
| - /// filesystem. This will return true if the path points to either a |
662 |
| - /// directory or a file. |
| 656 | + /// Get information on the file, directory, etc at this path, not following |
| 657 | + /// symlinks. |
663 | 658 | ///
|
664 |
| - /// # Error |
| 659 | + /// Consult the `fs::lstat` documentation for more info. |
665 | 660 | ///
|
666 |
| - /// Will not raise a condition |
| 661 | + /// This call preserves identical runtime/error semantics with `file::lstat`. |
| 662 | + pub fn lstat(&self) -> IoResult<FileStat> { lstat(self) } |
| 663 | + |
| 664 | + /// Boolean value indicator whether the underlying file exists on the local |
| 665 | + /// filesystem. Returns false in exactly the cases where `fs::stat` fails. |
667 | 666 | pub fn exists(&self) -> bool {
|
668 | 667 | self.stat().is_ok()
|
669 | 668 | }
|
670 | 669 |
|
671 | 670 | /// Whether the underlying implementation (be it a file path, or something
|
672 | 671 | /// else) points at a "regular file" on the FS. Will return false for paths
|
673 | 672 | /// to non-existent locations or directories or other non-regular files
|
674 |
| - /// (named pipes, etc). |
675 |
| - /// |
676 |
| - /// # Error |
677 |
| - /// |
678 |
| - /// Will not raise a condition |
| 673 | + /// (named pipes, etc). Follows links when making this determination. |
679 | 674 | pub fn is_file(&self) -> bool {
|
680 | 675 | match self.stat() {
|
681 | 676 | Ok(s) => s.kind == io::TypeFile,
|
682 | 677 | Err(..) => false
|
683 | 678 | }
|
684 | 679 | }
|
685 | 680 |
|
686 |
| - /// Whether the underlying implementation (be it a file path, |
687 |
| - /// or something else) is pointing at a directory in the underlying FS. |
688 |
| - /// Will return false for paths to non-existent locations or if the item is |
689 |
| - /// not a directory (eg files, named pipes, links, etc) |
690 |
| - /// |
691 |
| - /// # Error |
692 |
| - /// |
693 |
| - /// Will not raise a condition |
| 681 | + /// Whether the underlying implementation (be it a file path, or something |
| 682 | + /// else) is pointing at a directory in the underlying FS. Will return |
| 683 | + /// false for paths to non-existent locations or if the item is not a |
| 684 | + /// directory (eg files, named pipes, etc). Follows links when making this |
| 685 | + /// determination. |
694 | 686 | pub fn is_dir(&self) -> bool {
|
695 | 687 | match self.stat() {
|
696 | 688 | Ok(s) => s.kind == io::TypeDirectory,
|
@@ -898,17 +890,21 @@ mod test {
|
898 | 890 | let msg = "hw";
|
899 | 891 | fs.write(msg.as_bytes()).unwrap();
|
900 | 892 | }
|
901 |
| - let stat_res = check!(stat(filename)); |
902 |
| - assert_eq!(stat_res.kind, io::TypeFile); |
| 893 | + let stat_res_fn = check!(stat(filename)); |
| 894 | + assert_eq!(stat_res_fn.kind, io::TypeFile); |
| 895 | + let stat_res_meth = check!(filename.stat()); |
| 896 | + assert_eq!(stat_res_meth.kind, io::TypeFile); |
903 | 897 | check!(unlink(filename));
|
904 | 898 | })
|
905 | 899 |
|
906 | 900 | iotest!(fn file_test_stat_is_correct_on_is_dir() {
|
907 | 901 | let tmpdir = tmpdir();
|
908 | 902 | let filename = &tmpdir.join("file_stat_correct_on_is_dir");
|
909 | 903 | check!(mkdir(filename, io::UserRWX));
|
910 |
| - let stat_res = check!(filename.stat()); |
911 |
| - assert!(stat_res.kind == io::TypeDirectory); |
| 904 | + let stat_res_fn = check!(stat(filename)); |
| 905 | + assert!(stat_res_fn.kind == io::TypeDirectory); |
| 906 | + let stat_res_meth = check!(filename.stat()); |
| 907 | + assert!(stat_res_meth.kind == io::TypeDirectory); |
912 | 908 | check!(rmdir(filename));
|
913 | 909 | })
|
914 | 910 |
|
@@ -1139,6 +1135,7 @@ mod test {
|
1139 | 1135 | check!(symlink(&input, &out));
|
1140 | 1136 | if cfg!(not(windows)) {
|
1141 | 1137 | assert_eq!(check!(lstat(&out)).kind, io::TypeSymlink);
|
| 1138 | + assert_eq!(check!(out.lstat()).kind, io::TypeSymlink); |
1142 | 1139 | }
|
1143 | 1140 | assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
|
1144 | 1141 | assert_eq!(check!(File::open(&out).read_to_end()),
|
@@ -1170,9 +1167,12 @@ mod test {
|
1170 | 1167 | check!(link(&input, &out));
|
1171 | 1168 | if cfg!(not(windows)) {
|
1172 | 1169 | assert_eq!(check!(lstat(&out)).kind, io::TypeFile);
|
| 1170 | + assert_eq!(check!(out.lstat()).kind, io::TypeFile); |
1173 | 1171 | assert_eq!(check!(stat(&out)).unstable.nlink, 2);
|
| 1172 | + assert_eq!(check!(out.stat()).unstable.nlink, 2); |
1174 | 1173 | }
|
1175 | 1174 | assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
|
| 1175 | + assert_eq!(check!(stat(&out)).size, check!(input.stat()).size); |
1176 | 1176 | assert_eq!(check!(File::open(&out).read_to_end()),
|
1177 | 1177 | (Vec::from_slice(bytes!("foobar"))));
|
1178 | 1178 |
|
|
0 commit comments