Auto merge of #20175 - andreicristianpetcu:remove_optional_from_default_config_dir, r=jdm

#20174 removed the option and unwrap

I removed the useless option and the need for unwrap from default_config_dir

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #20174 (github issue number if applicable).
- [X] These changes do not require tests because they are used at build time.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20175)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-02 14:39:37 -05:00 committed by GitHub
commit 48ff3965cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 12 deletions

View file

@ -17,19 +17,18 @@ use std::path::PathBuf;
use xdg;
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
pub fn default_config_dir() -> Option<PathBuf> {
pub fn default_config_dir() -> PathBuf {
let xdg_dirs = xdg::BaseDirectories::with_profile("servo", "default").unwrap();
let config_dir = xdg_dirs.get_config_home();
Some(config_dir)
xdg_dirs.get_config_home()
}
#[cfg(target_os = "android")]
#[allow(unsafe_code)]
pub fn default_config_dir() -> Option<PathBuf> {
pub fn default_config_dir() -> PathBuf {
let dir = unsafe {
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
};
Some(PathBuf::from(dir.to_str().unwrap()))
PathBuf::from(dir.to_str().unwrap())
}
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
@ -67,16 +66,16 @@ pub fn default_cache_dir() -> Option<PathBuf> {
}
#[cfg(target_os = "macos")]
pub fn default_config_dir() -> Option<PathBuf> {
pub fn default_config_dir() -> PathBuf {
let mut config_dir = env::home_dir().unwrap();
config_dir.push("Library");
config_dir.push("Application Support");
config_dir.push("Servo");
Some(config_dir)
config_dir
}
#[cfg(target_os = "windows")]
pub fn default_config_dir() -> Option<PathBuf> {
pub fn default_config_dir() -> PathBuf {
let mut config_dir = match env::var_os("APPDATA") {
Some(appdata_path) => PathBuf::from(appdata_path),
None => {
@ -87,5 +86,5 @@ pub fn default_config_dir() -> Option<PathBuf> {
}
};
config_dir.push("Servo");
Some(config_dir)
config_dir
}

View file

@ -184,7 +184,7 @@ pub fn add_user_prefs() {
init_user_prefs(&mut path);
}
None => {
let mut path = default_config_dir().unwrap();
let mut path = default_config_dir();
if path.join("prefs.json").exists() {
init_user_prefs(&mut path);
}

View file

@ -56,7 +56,7 @@ fn test_default_config_dir_create_read_write() {
\"shell.homepage\": \"https://google.com\"\
}";
let mut expected_json = String::new();
let config_path = basedir::default_config_dir().unwrap();
let config_path = basedir::default_config_dir();
if !config_path.exists() {
fs::create_dir_all(&config_path).unwrap();