path2: Replace the path module outright
Remove the old path. Rename path2 to path. Update all clients for the new path. Also make some miscellaneous changes to the Path APIs to help the adoption process.
This commit is contained in:
parent
6741241f40
commit
73d3d00ec4
63 changed files with 2501 additions and 2989 deletions
|
|
@ -14,10 +14,9 @@
|
|||
use std::{os, str};
|
||||
use std::os::getenv;
|
||||
use std::io::{file_reader, Reader};
|
||||
use path = std::path::Path;
|
||||
|
||||
/// Return path to database entry for `term`
|
||||
pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
|
||||
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
|
||||
if term.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -29,25 +28,26 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
|
|||
|
||||
// Find search directory
|
||||
match getenv("TERMINFO") {
|
||||
Some(dir) => dirs_to_search.push(path(dir)),
|
||||
Some(dir) => dirs_to_search.push(Path::from_str(dir)),
|
||||
None => {
|
||||
if homedir.is_some() {
|
||||
dirs_to_search.push(homedir.unwrap().push(".terminfo")); // ncurses compatability
|
||||
// ncurses compatability;
|
||||
dirs_to_search.push(homedir.unwrap().join_str(".terminfo"))
|
||||
}
|
||||
match getenv("TERMINFO_DIRS") {
|
||||
Some(dirs) => for i in dirs.split_iter(':') {
|
||||
if i == "" {
|
||||
dirs_to_search.push(path("/usr/share/terminfo"));
|
||||
dirs_to_search.push(Path::from_str("/usr/share/terminfo"));
|
||||
} else {
|
||||
dirs_to_search.push(path(i.to_owned()));
|
||||
dirs_to_search.push(Path::from_str(i.to_owned()));
|
||||
}
|
||||
},
|
||||
// Found nothing, use the default paths
|
||||
// /usr/share/terminfo is the de facto location, but it seems
|
||||
// Ubuntu puts it in /lib/terminfo
|
||||
None => {
|
||||
dirs_to_search.push(path("/usr/share/terminfo"));
|
||||
dirs_to_search.push(path("/lib/terminfo"));
|
||||
dirs_to_search.push(Path::from_str("/usr/share/terminfo"));
|
||||
dirs_to_search.push(Path::from_str("/lib/terminfo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,14 +55,18 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
|
|||
|
||||
// Look for the terminal in all of the search directories
|
||||
for p in dirs_to_search.iter() {
|
||||
let newp = ~p.push_many(&[str::from_char(first_char), term.to_owned()]);
|
||||
if os::path_exists(p) && os::path_exists(newp) {
|
||||
return Some(newp);
|
||||
}
|
||||
// on some installations the dir is named after the hex of the char (e.g. OS X)
|
||||
let newp = ~p.push_many(&[format!("{:x}", first_char as uint), term.to_owned()]);
|
||||
if os::path_exists(p) && os::path_exists(newp) {
|
||||
return Some(newp);
|
||||
if os::path_exists(p) {
|
||||
let f = str::from_char(first_char);
|
||||
let newp = p.join_many_str([f.as_slice(), term]);
|
||||
if os::path_exists(&newp) {
|
||||
return Some(~newp);
|
||||
}
|
||||
// on some installations the dir is named after the hex of the char (e.g. OS X)
|
||||
let f = format!("{:x}", first_char as uint);
|
||||
let newp = p.join_many_str([f.as_slice(), term]);
|
||||
if os::path_exists(&newp) {
|
||||
return Some(~newp);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
|
|
@ -82,7 +86,11 @@ fn test_get_dbpath_for_term() {
|
|||
// woefully inadequate test coverage
|
||||
// note: current tests won't work with non-standard terminfo hierarchies (e.g. OS X's)
|
||||
use std::os::{setenv, unsetenv};
|
||||
fn x(t: &str) -> ~str { get_dbpath_for_term(t).expect("no terminfo entry found").to_str() };
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
fn x(t: &str) -> ~str {
|
||||
let p = get_dbpath_for_term(t).expect("no terminfo entry found");
|
||||
p.as_str().unwrap().to_owned()
|
||||
};
|
||||
assert!(x("screen") == ~"/usr/share/terminfo/s/screen");
|
||||
assert!(get_dbpath_for_term("") == None);
|
||||
setenv("TERMINFO_DIRS", ":");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue