From f6ecbe88ca67769ccb9def337ada9ae25235e00e Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 9 Jan 2012 16:11:25 -0800 Subject: Fix rpath bug. --- src/libstd/fs.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 2a65559db5a..4e97603e177 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -81,17 +81,20 @@ Function: connect Connects to path segments -Given paths `pre` and `post` this function will return a path -that is equal to `post` appended to `pre`, inserting a path separator -between the two as needed. +Given paths `pre` and `post, removes any trailing path separator on `pre` and +any leading path separator on `post`, and returns the concatenation of the two +with a single path separator between them. */ -fn connect(pre: path, post: path) -> path { - let len = str::byte_len(pre); - ret if pre[len - 1u] == os_fs::path_sep as u8 { - // Trailing '/'? - pre + post - } else { pre + path_sep() + post }; +fn connect(pre: path, post: path) -> path { + let pre_ = pre; + let post_ = post; + let sep = os_fs::path_sep as u8; + let pre_len = str::byte_len(pre); + let post_len = str::byte_len(post); + if pre_len > 1u && pre[pre_len-1u] == sep { str::pop_byte(pre_); } + if post_len > 1u && post[0] == sep { str::shift_byte(post_); } + ret pre_ + path_sep() + post_; } /* -- cgit 1.4.1-3-g733a5