adding default config dirs

This commit is contained in:
Rahul Sharma 2016-04-04 17:46:35 +05:30
parent aa9f50a1d4
commit b4885fef9a
13 changed files with 171 additions and 45 deletions

View file

@ -14,14 +14,14 @@ use resource_files::set_resources_path;
use std::cmp;
use std::default::Default;
use std::env;
use std::fs;
use std::fs::File;
use std::io::{self, Read, Write};
use std::fs::{self, File};
use std::io::{self, Read, Write, stderr};
use std::path::{Path, PathBuf};
use std::process;
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use url::{self, Url};
/// Global flags for Servo, currently set on the command line.
#[derive(Clone, Deserialize, Serialize)]
pub struct Opts {
@ -197,8 +197,8 @@ pub struct Opts {
/// True if WebRender should use multisample antialiasing.
pub use_msaa: bool,
/// Directory path for persistent session
pub profile_dir: Option<String>,
/// Directory for a default config directory
pub config_dir: Option<String>,
// Which rendering API to use.
pub render_api: RenderApi,
@ -471,6 +471,7 @@ const DEFAULT_USER_AGENT: UserAgent = UserAgent::Gonk;
const DEFAULT_USER_AGENT: UserAgent = UserAgent::Desktop;
pub fn default_opts() -> Opts {
Opts {
is_running_problem_test: false,
url: Some(Url::parse("about:blank").unwrap()),
@ -524,7 +525,7 @@ pub fn default_opts() -> Opts {
webrender_stats: false,
use_msaa: false,
render_api: DEFAULT_RENDER_API,
profile_dir: None,
config_dir: None,
full_backtraces: false,
}
}
@ -581,8 +582,9 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
opts.optflag("b", "no-native-titlebar", "Do not use native titlebar");
opts.optflag("w", "webrender", "Use webrender backend");
opts.optopt("G", "graphics", "Select graphics backend (gl or es2)", "gl");
opts.optopt("", "profile-dir",
"optional directory path for user sessions", "");
opts.optopt("", "config-dir",
"config directory following xdg spec on linux platform", "");
let opt_match = match opts.parse(args) {
Ok(m) => m,
@ -596,12 +598,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
process::exit(0);
};
if let Some(ref profile_dir) = opt_match.opt_str("profile-dir") {
if let Err(why) = fs::create_dir_all(profile_dir) {
error!("Couldn't create/open {:?}: {:?}", Path::new(profile_dir).to_string_lossy(), why);
}
}
// If this is the content process, we'll receive the real options over IPC. So just fill in
// some dummy options for now.
if let Some(content_process) = opt_match.opt_str("content-process") {
@ -833,7 +829,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
use_webrender: use_webrender,
webrender_stats: debug_options.webrender_stats,
use_msaa: debug_options.use_msaa,
profile_dir: opt_match.opt_str("profile-dir"),
config_dir: opt_match.opt_str("config-dir"),
full_backtraces: debug_options.full_backtraces,
};
@ -842,9 +838,9 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
// These must happen after setting the default options, since the prefs rely on
// on the resource path.
// Note that command line preferences have the highest precedence
if get().profile_dir.is_some() {
prefs::add_user_prefs();
}
prefs::add_user_prefs();
for pref in opt_match.opt_strs("pref").iter() {
let split: Vec<&str> = pref.splitn(2, '=').collect();
let pref_name = split[0];