comparison rust/hg-core/src/utils/files.rs @ 46742:91ab5190a3de

rhg: Add support for environment variables in config include paths Some tests rely on this. Differential Revision: https://phab.mercurial-scm.org/D10140
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Mar 2021 15:35:32 +0100
parents d2e61f00ee9d
children 3c9ddb1986a9
comparison
equal deleted inserted replaced
46741:25e3dac511f0 46742:91ab5190a3de
21 use std::fs::Metadata; 21 use std::fs::Metadata;
22 use std::iter::FusedIterator; 22 use std::iter::FusedIterator;
23 use std::ops::Deref; 23 use std::ops::Deref;
24 use std::path::{Path, PathBuf}; 24 use std::path::{Path, PathBuf};
25 25
26 pub fn get_path_from_bytes(bytes: &[u8]) -> &Path { 26 pub fn get_os_str_from_bytes(bytes: &[u8]) -> &OsStr {
27 let os_str; 27 let os_str;
28 #[cfg(unix)] 28 #[cfg(unix)]
29 { 29 {
30 use std::os::unix::ffi::OsStrExt; 30 use std::os::unix::ffi::OsStrExt;
31 os_str = std::ffi::OsStr::from_bytes(bytes); 31 os_str = std::ffi::OsStr::from_bytes(bytes);
32 } 32 }
33 // TODO Handle other platforms 33 // TODO Handle other platforms
34 // TODO: convert from WTF8 to Windows MBCS (ANSI encoding). 34 // TODO: convert from WTF8 to Windows MBCS (ANSI encoding).
35 // Perhaps, the return type would have to be Result<PathBuf>. 35 // Perhaps, the return type would have to be Result<PathBuf>.
36 36 os_str
37 Path::new(os_str) 37 }
38
39 pub fn get_path_from_bytes(bytes: &[u8]) -> &Path {
40 Path::new(get_os_str_from_bytes(bytes))
38 } 41 }
39 42
40 // TODO: need to convert from WTF8 to MBCS bytes on Windows. 43 // TODO: need to convert from WTF8 to MBCS bytes on Windows.
41 // that's why Vec<u8> is returned. 44 // that's why Vec<u8> is returned.
42 #[cfg(unix)] 45 #[cfg(unix)]