From: Graydon Hoare Date: Tue, 10 Jan 2012 00:11:25 +0000 (-0800) Subject: Fix rpath bug. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f6ecbe88ca67769ccb9def337ada9ae25235e00e;p=rust.git Fix rpath bug. --- diff --git a/src/comp/back/rpath.rs b/src/comp/back/rpath.rs index 06c866fc926..91f025308e0 100644 --- a/src/comp/back/rpath.rs +++ b/src/comp/back/rpath.rs @@ -218,8 +218,8 @@ fn test_get_absolute2() { #[test] fn test_prefix_rpath() { let res = get_install_prefix_rpath("/usr/lib", "triple"); - assert str::ends_with(res, #env("CFG_PREFIX") - + "/lib/rustc/triple/lib"); + let d = fs::connect(#env("CFG_PREFIX"), "/lib/rustc/triple/lib"); + assert str::ends_with(res, d); } #[test] 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 @@ fn basename(p: path) -> path { 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_; } /*