Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

Commit d5eef09

Browse files
committed
std: Deprecate std::old_io::fs
This commit deprecates the majority of std::old_io::fs in favor of std::fs and its new functionality. Some functions remain non-deprecated but are now behind a feature gate called `old_fs`. These functions will be deprecated once suitable replacements have been implemented. The compiler has been migrated to new `std::fs` and `std::path` APIs where appropriate as part of this change.
1 parent f86103d commit d5eef09

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@
5252

5353
#![feature(box_syntax)]
5454
#![feature(collections)]
55+
#![feature(fs)]
5556
#![feature(int_uint)]
57+
#![feature(io)]
5658
#![feature(old_io)]
57-
#![feature(old_path)]
59+
#![feature(path)]
5860
#![feature(rustc_private)]
5961
#![feature(staged_api)]
60-
#![feature(unicode)]
6162
#![feature(std_misc)]
62-
#![feature(os)]
63+
#![feature(unicode)]
6364
#![cfg_attr(windows, feature(libc))]
6465

6566
#[macro_use] extern crate log;

terminfo/parser/compiled.rs

+35-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
//! ncurses-compatible compiled terminfo format parsing (term(5))
1414
1515
use std::collections::HashMap;
16-
use std::old_io;
16+
use std::io::prelude::*;
17+
use std::io;
1718
use super::super::TermInfo;
1819

1920
// These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable.
@@ -158,7 +159,7 @@ pub static stringnames: &'static[&'static str] = &[ "cbt", "_", "cr", "csr", "tb
158159
"box1"];
159160

160161
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
161-
pub fn parse(file: &mut old_io::Reader, longnames: bool)
162+
pub fn parse(file: &mut Read, longnames: bool)
162163
-> Result<Box<TermInfo>, String> {
163164
macro_rules! try { ($e:expr) => (
164165
match $e {
@@ -182,17 +183,17 @@ pub fn parse(file: &mut old_io::Reader, longnames: bool)
182183
}
183184

184185
// Check magic number
185-
let magic = try!(file.read_le_u16());
186+
let magic = try!(read_le_u16(file));
186187
if magic != 0x011A {
187188
return Err(format!("invalid magic number: expected {:x}, found {:x}",
188189
0x011A as usize, magic as usize));
189190
}
190191

191-
let names_bytes = try!(file.read_le_i16()) as int;
192-
let bools_bytes = try!(file.read_le_i16()) as int;
193-
let numbers_count = try!(file.read_le_i16()) as int;
194-
let string_offsets_count = try!(file.read_le_i16()) as int;
195-
let string_table_bytes = try!(file.read_le_i16()) as int;
192+
let names_bytes = try!(read_le_u16(file)) as int;
193+
let bools_bytes = try!(read_le_u16(file)) as int;
194+
let numbers_count = try!(read_le_u16(file)) as int;
195+
let string_offsets_count = try!(read_le_u16(file)) as int;
196+
let string_table_bytes = try!(read_le_u16(file)) as int;
196197

197198
assert!(names_bytes > 0);
198199

@@ -212,7 +213,7 @@ pub fn parse(file: &mut old_io::Reader, longnames: bool)
212213
}
213214

214215
// don't read NUL
215-
let bytes = try!(file.read_exact(names_bytes as uint - 1));
216+
let bytes = try!(read_exact(file, names_bytes as uint - 1));
216217
let names_str = match String::from_utf8(bytes) {
217218
Ok(s) => s,
218219
Err(_) => return Err("input not utf-8".to_string()),
@@ -222,26 +223,26 @@ pub fn parse(file: &mut old_io::Reader, longnames: bool)
222223
.map(|s| s.to_string())
223224
.collect();
224225

225-
try!(file.read_byte()); // consume NUL
226+
try!(read_byte(file)); // consume NUL
226227

227228
let mut bools_map = HashMap::new();
228229
if bools_bytes != 0 {
229230
for i in 0..bools_bytes {
230-
let b = try!(file.read_byte());
231+
let b = try!(read_byte(file));
231232
if b == 1 {
232233
bools_map.insert(bnames[i as uint].to_string(), true);
233234
}
234235
}
235236
}
236237

237238
if (bools_bytes + names_bytes) % 2 == 1 {
238-
try!(file.read_byte()); // compensate for padding
239+
try!(read_byte(file)); // compensate for padding
239240
}
240241

241242
let mut numbers_map = HashMap::new();
242243
if numbers_count != 0 {
243244
for i in 0..numbers_count {
244-
let n = try!(file.read_le_u16());
245+
let n = try!(read_le_u16(file));
245246
if n != 0xFFFF {
246247
numbers_map.insert(nnames[i as uint].to_string(), n);
247248
}
@@ -253,10 +254,10 @@ pub fn parse(file: &mut old_io::Reader, longnames: bool)
253254
if string_offsets_count != 0 {
254255
let mut string_offsets = Vec::with_capacity(10);
255256
for _ in 0..string_offsets_count {
256-
string_offsets.push(try!(file.read_le_u16()));
257+
string_offsets.push(try!(read_le_u16(file)));
257258
}
258259

259-
let string_table = try!(file.read_exact(string_table_bytes as uint));
260+
let string_table = try!(read_exact(file, string_table_bytes as usize));
260261

261262
if string_table.len() != string_table_bytes as uint {
262263
return Err("error: hit EOF before end of string \
@@ -309,6 +310,25 @@ pub fn parse(file: &mut old_io::Reader, longnames: bool)
309310
})
310311
}
311312

313+
fn read_le_u16<R: Read + ?Sized>(r: &mut R) -> io::Result<u16> {
314+
let mut b = [0; 2];
315+
assert_eq!(try!(r.read(&mut b)), 2);
316+
Ok((b[0] as u16) | ((b[1] as u16) << 8))
317+
}
318+
319+
fn read_byte<R: Read + ?Sized>(r: &mut R) -> io::Result<u8> {
320+
let mut b = [0; 1];
321+
assert_eq!(try!(r.read(&mut b)), 1);
322+
Ok(b[0])
323+
}
324+
325+
fn read_exact<R: Read + ?Sized>(r: &mut R, sz: usize) -> io::Result<Vec<u8>> {
326+
let mut v = Vec::with_capacity(sz);
327+
try!(r.take(sz as u64).read_to_end(&mut v));
328+
assert_eq!(v.len(), sz);
329+
Ok(v)
330+
}
331+
312332
/// Create a dummy TermInfo struct for msys terminals
313333
pub fn msys_terminfo() -> Box<TermInfo> {
314334
let mut strings = HashMap::new();

terminfo/searcher.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,47 @@
1212
//!
1313
//! Does not support hashed database, only filesystem!
1414
15-
use std::old_io::File;
16-
use std::old_io::fs::PathExtensions;
1715
use std::env;
16+
use std::fs::File;
17+
use std::io::prelude::*;
18+
use std::path::PathBuf;
1819

1920
/// Return path to database entry for `term`
2021
#[allow(deprecated)]
21-
pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> {
22+
pub fn get_dbpath_for_term(term: &str) -> Option<Box<PathBuf>> {
2223
if term.len() == 0 {
2324
return None;
2425
}
2526

26-
let homedir = ::std::os::homedir();
27+
let homedir = env::home_dir();
2728

2829
let mut dirs_to_search = Vec::new();
2930
let first_char = term.char_at(0);
3031

3132
// Find search directory
32-
match env::var("TERMINFO") {
33-
Ok(dir) => dirs_to_search.push(Path::new(dir)),
34-
Err(..) => {
33+
match env::var_os("TERMINFO") {
34+
Some(dir) => dirs_to_search.push(PathBuf::new(&dir)),
35+
None => {
3536
if homedir.is_some() {
3637
// ncurses compatibility;
3738
dirs_to_search.push(homedir.unwrap().join(".terminfo"))
3839
}
3940
match env::var("TERMINFO_DIRS") {
4041
Ok(dirs) => for i in dirs.split(':') {
4142
if i == "" {
42-
dirs_to_search.push(Path::new("/usr/share/terminfo"));
43+
dirs_to_search.push(PathBuf::new("/usr/share/terminfo"));
4344
} else {
44-
dirs_to_search.push(Path::new(i));
45+
dirs_to_search.push(PathBuf::new(i));
4546
}
4647
},
4748
// Found nothing in TERMINFO_DIRS, use the default paths:
4849
// According to /etc/terminfo/README, after looking at
4950
// ~/.terminfo, ncurses will search /etc/terminfo, then
5051
// /lib/terminfo, and eventually /usr/share/terminfo.
5152
Err(..) => {
52-
dirs_to_search.push(Path::new("/etc/terminfo"));
53-
dirs_to_search.push(Path::new("/lib/terminfo"));
54-
dirs_to_search.push(Path::new("/usr/share/terminfo"));
53+
dirs_to_search.push(PathBuf::new("/etc/terminfo"));
54+
dirs_to_search.push(PathBuf::new("/lib/terminfo"));
55+
dirs_to_search.push(PathBuf::new("/usr/share/terminfo"));
5556
}
5657
}
5758
}
@@ -61,13 +62,13 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> {
6162
for p in &dirs_to_search {
6263
if p.exists() {
6364
let f = first_char.to_string();
64-
let newp = p.join_many(&[&f[..], term]);
65+
let newp = p.join(&f).join(term);
6566
if newp.exists() {
6667
return Some(box newp);
6768
}
6869
// on some installations the dir is named after the hex of the char (e.g. OS X)
6970
let f = format!("{:x}", first_char as uint);
70-
let newp = p.join_many(&[&f[..], term]);
71+
let newp = p.join(&f).join(term);
7172
if newp.exists() {
7273
return Some(box newp);
7374
}
@@ -100,7 +101,7 @@ fn test_get_dbpath_for_term() {
100101
// FIXME (#9639): This needs to handle non-utf8 paths
101102
fn x(t: &str) -> String {
102103
let p = get_dbpath_for_term(t).expect("no terminfo entry found");
103-
p.as_str().unwrap().to_string()
104+
p.to_str().unwrap().to_string()
104105
};
105106
assert!(x("screen") == "/usr/share/terminfo/s/screen");
106107
assert!(get_dbpath_for_term("") == None);

0 commit comments

Comments
 (0)