about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorMark Simulacrum <mark.simulacrum@gmail.com>2018-05-12 07:32:29 -0600
committerGitHub <noreply@github.com>2018-05-12 07:32:29 -0600
commitbf832c2a89b67449da276377dbe23cd08d397930 (patch)
tree9b794eb4b63f2b8007c0ccec136021624ef7f7d9 /src/libstd/path.rs
parentb9c9fac1a4d0994cc9a3e28b167dee30d90fd67c (diff)
parent8720314c025cd222fd04d07119e2cf180f53770a (diff)
downloadrust-bf832c2a89b67449da276377dbe23cd08d397930.tar.gz
rust-bf832c2a89b67449da276377dbe23cd08d397930.zip
Rollup merge of #50602 - Screwtapello:update-canonicalize-docs, r=cramertj
Update canonicalize docs

I was recently working with file-paths in Rust, and I felt let down by the `std::fs::canonicalize` docs, so I figured I should submit a PR with some suggestions.

I was looking for a method to turn a relative path into an absolute path. The `canonicalize` docs didn't mention the words "relative" or "absolute", but they did mention resolving symlinks (which is a kind of canonicalisation and does not imply converting to absolute), so I assumed that's all it did. To remedy this, I've added the word "absolute" to the description of both `std::fs::canonicalize` and `std::path::Path::canonicalize`.

After calling `canonicalize` on Windows, I ran into a bunch of other problems I would not have expected from the function's behaviour on Linux. Specifically, if you call `canonicalize` on a path:

  - it's allowed to be much longer than it otherwise would
  - `.join("a/slash/delimited/path")` gives you a broken path that Windows can't use, where the same operation would have worked perfectly without `canonicalize` (if the path were short enough)
  - the resulting path may confuse other Windows programs if you pass it to them on the command-line, or write it to a config file that they read, etc.

...so I tried to summarize those behaviours too.

If I understand correctly, those behaviours are a side-effect of calling `GetFinalPathNameByHandle`, and the documentation says `canonicalize` might not call that function in future, so maybe those side-effects shouldn't be part of the function's documentation. However, I bet there's a lot of applications deliberately calling `canonicalize` just for the path-length-extension alone, so that particular side-effect is de-facto part of the `canonicalize` interface.
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 5d35a786173..86478f0a523 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -2284,8 +2284,8 @@ impl Path {
         fs::symlink_metadata(self)
     }
 
-    /// Returns the canonical form of the path with all intermediate components
-    /// normalized and symbolic links resolved.
+    /// Returns the canonical, absolute form of the path with all intermediate
+    /// components normalized and symbolic links resolved.
     ///
     /// This is an alias to [`fs::canonicalize`].
     ///