Skip to content

Commit 7f36a18

Browse files
Added platform notes to std::fs public functions.
1 parent d4b67cd commit 7f36a18

File tree

1 file changed

+165
-35
lines changed

1 file changed

+165
-35
lines changed

src/libstd/fs.rs

Lines changed: 165 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,19 @@ impl AsInner<fs_imp::DirEntry> for DirEntry {
758758
/// guarantee that the file is immediately deleted (e.g. depending on
759759
/// platform, other open file descriptors may prevent immediate removal).
760760
///
761+
/// # Platform behavior
762+
///
763+
/// This function currently corresponds to the `unlink` function on Unix
764+
/// and the `DeleteFile` function on Windows. Note that, this
765+
/// [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
766+
///
761767
/// # Errors
762768
///
763-
/// This function will return an error if `path` points to a directory, if the
764-
/// user lacks permissions to remove the file, or if some other filesystem-level
765-
/// error occurs.
769+
/// This function will return an error in the following situations, but is not
770+
/// limited to just these cases:
771+
///
772+
/// * `path` points to a directory
773+
/// * The user lacks permissions to remove the file
766774
///
767775
/// # Examples
768776
///
@@ -785,6 +793,20 @@ pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
785793
/// This function will traverse symbolic links to query information about the
786794
/// destination file.
787795
///
796+
/// # Platform behavior
797+
///
798+
/// This function currently corresponds to the `stat` function on Unix
799+
/// and the `GetFileAttributesEx` function on Windows. Note that, this
800+
/// [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
801+
///
802+
/// # Errors
803+
///
804+
/// This function will return an error in the following situations, but is not
805+
/// limited to just these cases:
806+
///
807+
/// * The user lacks permissions to perform `metadata` call on `path`
808+
/// * `path` does not exist
809+
///
788810
/// # Examples
789811
///
790812
/// ```rust
@@ -796,19 +818,27 @@ pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
796818
/// # Ok(())
797819
/// # }
798820
/// ```
799-
///
800-
/// # Errors
801-
///
802-
/// This function will return an error if the user lacks the requisite
803-
/// permissions to perform a `metadata` call on the given `path` or if there
804-
/// is no entry in the filesystem at the provided path.
805821
#[stable(feature = "rust1", since = "1.0.0")]
806822
pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
807823
fs_imp::stat(path.as_ref()).map(Metadata)
808824
}
809825

810826
/// Query the metadata about a file without following symlinks.
811827
///
828+
/// # Platform behavior
829+
///
830+
/// This function currently corresponds to the `lstat` function on Unix
831+
/// and the `GetFileAttributesEx` function on Windows. Note that, this
832+
/// [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
833+
///
834+
/// # Errors
835+
///
836+
/// This function will return an error in the following situations, but is not
837+
/// limited to just these cases:
838+
///
839+
/// * The user lacks permissions to perform `metadata` call on `path`
840+
/// * `path` does not exist
841+
///
812842
/// # Examples
813843
///
814844
/// ```rust
@@ -829,12 +859,20 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
829859
///
830860
/// This will not work if the new name is on a different mount point.
831861
///
862+
/// # Platform behavior
863+
///
864+
/// This function currently corresponds to the `rename` function on Unix
865+
/// and the `MoveFileEx` function with the `MOVEFILE_REPLACE_EXISTING` flag on Windows.
866+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
867+
///
832868
/// # Errors
833869
///
834-
/// This function will return an error if the provided `from` doesn't exist, if
835-
/// the process lacks permissions to view the contents, if `from` and `to`
836-
/// reside on separate filesystems, or if some other intermittent I/O error
837-
/// occurs.
870+
/// This function will return an error in the following situations, but is not
871+
/// limited to just these cases:
872+
///
873+
/// * `from` does not exist
874+
/// * The user lacks permissions to view contents
875+
/// * `from` and `to` are on separate filesystems
838876
///
839877
/// # Examples
840878
///
@@ -861,6 +899,14 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
861899
///
862900
/// On success, the total number of bytes copied is returned.
863901
///
902+
/// # Platform behavior
903+
///
904+
/// This function currently corresponds to the `open` function in Unix
905+
/// with `O_RDONLY` for `from` and `O_WRONLY`, `O_CREAT`, and `O_TRUNC` for `to`.
906+
/// `O_CLOEXEC` is set for returned file descriptors.
907+
/// On Windows, this function currently corresponds to `CopyFileEx`.
908+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
909+
///
864910
/// # Errors
865911
///
866912
/// This function will return an error in the following situations, but is not
@@ -890,6 +936,19 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
890936
/// The `dst` path will be a link pointing to the `src` path. Note that systems
891937
/// often require these two paths to both be located on the same filesystem.
892938
///
939+
/// # Platform behavior
940+
///
941+
/// This function currently corresponds to the `link` function on Unix
942+
/// and the `CreateHardLink` function on Windows.
943+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
944+
///
945+
/// # Errors
946+
///
947+
/// This function will return an error in the following situations, but is not
948+
/// limited to just these cases:
949+
///
950+
/// * The `src` path is not a file or doesn't exist
951+
///
893952
/// # Examples
894953
///
895954
/// ```
@@ -933,11 +992,20 @@ pub fn soft_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<(
933992

934993
/// Reads a symbolic link, returning the file that the link points to.
935994
///
995+
/// # Platform behavior
996+
///
997+
/// This function currently corresponds to the `readlink` function on Unix
998+
/// and the `CreateFile` function with `FILE_FLAG_OPEN_REPARSE_POINT` and
999+
/// `FILE_FLAG_BACKUP_SEMANTICS` flags on Windows.
1000+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1001+
///
9361002
/// # Errors
9371003
///
938-
/// This function will return an error on failure. Failure conditions include
939-
/// reading a file that does not exist or reading a file that is not a symbolic
940-
/// link.
1004+
/// This function will return an error in the following situations, but is not
1005+
/// limited to just these cases:
1006+
///
1007+
/// * `path` is not a symbolic link
1008+
/// * `path` does not exist
9411009
///
9421010
/// # Examples
9431011
///
@@ -957,8 +1025,19 @@ pub fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
9571025
/// Returns the canonical form of a path with all intermediate components
9581026
/// normalized and symbolic links resolved.
9591027
///
960-
/// This function may return an error in situations like where the path does not
961-
/// exist, a component in the path is not a directory, or an I/O error happens.
1028+
/// # Platform behavior
1029+
///
1030+
/// This function currently corresponds to the `realpath` function on Unix
1031+
/// and the `CreateFile` and `GetFinalPathNameByHandle` functions on Windows.
1032+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1033+
///
1034+
/// # Errors
1035+
///
1036+
/// This function will return an error in the following situations, but is not
1037+
/// limited to just these cases:
1038+
///
1039+
/// * `path` does not exist
1040+
/// * A component in path is not a directory
9621041
///
9631042
/// # Examples
9641043
///
@@ -977,10 +1056,19 @@ pub fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
9771056

9781057
/// Creates a new, empty directory at the provided path
9791058
///
1059+
/// # Platform behavior
1060+
///
1061+
/// This function currently corresponds to the `mkdir` function on Unix
1062+
/// and the `CreateDirectory` function on Windows.
1063+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1064+
///
9801065
/// # Errors
9811066
///
982-
/// This function will return an error if the user lacks permissions to make a
983-
/// new directory at the provided `path`, or if the directory already exists.
1067+
/// This function will return an error in the following situations, but is not
1068+
/// limited to just these cases:
1069+
///
1070+
/// * User lacks permissions to create directory at `path`
1071+
/// * `path` already exists
9841072
///
9851073
/// # Examples
9861074
///
@@ -1000,9 +1088,18 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
10001088
/// Recursively create a directory and all of its parent components if they
10011089
/// are missing.
10021090
///
1091+
/// # Platform behavior
1092+
///
1093+
/// This function currently corresponds to the `mkdir` function on Unix
1094+
/// and the `CreateDirectory` function on Windows.
1095+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1096+
///
10031097
/// # Errors
10041098
///
1005-
/// This function will fail if any directory in the path specified by `path`
1099+
/// This function will return an error in the following situations, but is not
1100+
/// limited to just these cases:
1101+
///
1102+
/// * If any directory in the path specified by `path`
10061103
/// does not already exist and it could not be created otherwise. The specific
10071104
/// error conditions for when a directory is being created (after it is
10081105
/// determined to not exist) are outlined by `fs::create_dir`.
@@ -1024,10 +1121,19 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
10241121

10251122
/// Removes an existing, empty directory.
10261123
///
1124+
/// # Platform behavior
1125+
///
1126+
/// This function currently corresponds to the `rmdir` function on Unix
1127+
/// and the `RemoveDirectory` function on Windows.
1128+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1129+
///
10271130
/// # Errors
10281131
///
1029-
/// This function will return an error if the user lacks permissions to remove
1030-
/// the directory at the provided `path`, or if the directory isn't empty.
1132+
/// This function will return an error in the following situations, but is not
1133+
/// limited to just these cases:
1134+
///
1135+
/// * The user lacks permissions to remove the directory at the provided `path`
1136+
/// * The directory isn't empty
10311137
///
10321138
/// # Examples
10331139
///
@@ -1050,6 +1156,13 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
10501156
/// This function does **not** follow symbolic links and it will simply remove the
10511157
/// symbolic link itself.
10521158
///
1159+
/// # Platform behavior
1160+
///
1161+
/// This function currently corresponds to `opendir`, `lstat`, `rm` and `rmdir` functions on Unix
1162+
/// and the `FindFirstFile`, `GetFileAttributesEx`, `DeleteFile`, and `RemoveDirectory` functions
1163+
/// on Windows.
1164+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1165+
///
10531166
/// # Errors
10541167
///
10551168
/// See `file::remove_file` and `fs::remove_dir`.
@@ -1087,6 +1200,21 @@ fn _remove_dir_all(path: &Path) -> io::Result<()> {
10871200
/// The iterator will yield instances of `io::Result<DirEntry>`. New errors may
10881201
/// be encountered after an iterator is initially constructed.
10891202
///
1203+
/// # Platform behavior
1204+
///
1205+
/// This function currently corresponds to the `opendir` function on Unix
1206+
/// and the `FindFirstFile` function on Windows.
1207+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1208+
///
1209+
/// # Errors
1210+
///
1211+
/// This function will return an error in the following situations, but is not
1212+
/// limited to just these cases:
1213+
///
1214+
/// * The provided `path` doesn't exist
1215+
/// * The process lacks permissions to view the contents
1216+
/// * The `path` points at a non-directory file
1217+
///
10901218
/// # Examples
10911219
///
10921220
/// ```
@@ -1109,12 +1237,6 @@ fn _remove_dir_all(path: &Path) -> io::Result<()> {
11091237
/// Ok(())
11101238
/// }
11111239
/// ```
1112-
///
1113-
/// # Errors
1114-
///
1115-
/// This function will return an error if the provided `path` doesn't exist, if
1116-
/// the process lacks permissions to view the contents or if the `path` points
1117-
/// at a non-directory file
11181240
#[stable(feature = "rust1", since = "1.0.0")]
11191241
pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
11201242
fs_imp::readdir(path.as_ref()).map(ReadDir)
@@ -1180,6 +1302,20 @@ impl Iterator for WalkDir {
11801302

11811303
/// Changes the permissions found on a file or a directory.
11821304
///
1305+
/// # Platform behavior
1306+
///
1307+
/// This function currently corresponds to the `chmod` function on Unix
1308+
/// and the `SetFileAttributes` function on Windows.
1309+
/// Note that, this [may change in the future.][https://github.com/rust-lang/rust/pull/28613]
1310+
///
1311+
/// # Errors
1312+
///
1313+
/// This function will return an error in the following situations, but is not
1314+
/// limited to just these cases:
1315+
///
1316+
/// * `path` does not exist
1317+
/// * The user lacks the permission to change attributes of the file
1318+
///
11831319
/// # Examples
11841320
///
11851321
/// ```
@@ -1192,12 +1328,6 @@ impl Iterator for WalkDir {
11921328
/// # Ok(())
11931329
/// # }
11941330
/// ```
1195-
///
1196-
/// # Errors
1197-
///
1198-
/// This function will return an error if the provided `path` doesn't exist, if
1199-
/// the process lacks permissions to change the attributes of the file, or if
1200-
/// some other I/O error is encountered.
12011331
#[stable(feature = "set_permissions", since = "1.1.0")]
12021332
pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions)
12031333
-> io::Result<()> {

0 commit comments

Comments
 (0)