]> git.lizzy.rs Git - rust.git/commitdiff
Fix rpath bug.
authorGraydon Hoare <graydon@mozilla.com>
Tue, 10 Jan 2012 00:11:25 +0000 (16:11 -0800)
committerGraydon Hoare <graydon@mozilla.com>
Tue, 10 Jan 2012 00:12:47 +0000 (16:12 -0800)
src/comp/back/rpath.rs
src/libstd/fs.rs

index 06c866fc926c9f3c3b8fe0b6aa09858fb5ddc4ff..91f025308e0f31afdfcf023ac3bcdc0bcf66aacf 100644 (file)
@@ -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]
index 2a65559db5aa97106b89617831826803b793a020..4e97603e1776aad3ac23ba419d788479279cdc57 100644 (file)
@@ -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_;
 }
 
 /*