servo: Merge #18702 - do not force resource_path on android (from paulrouget:android_res_path); r=Manishearth
authorPaul Rouget <me@paulrouget.com>
Wed, 04 Oct 2017 10:34:52 -0500
changeset 675186 8957f502fee8c769867da9aa4335116ea45ae74c
parent 675185 6d4ac28f61bffb8d50c48e9dd529bc79026a23dc
child 675187 4eb36d1710cadefb486a395af6f0de5363a91f4d
push id83058
push userbwerth@mozilla.com
push dateWed, 04 Oct 2017 23:14:13 +0000
reviewersManishearth
milestone58.0a1
servo: Merge #18702 - do not force resource_path on android (from paulrouget:android_res_path); r=Manishearth I want to be able to configure the resource path via `set_resources_path`. Source-Repo: https://github.com/servo/servo Source-Revision: b1c2d7195dd01a131c10d2bc2ad457a51c3fa118
servo/components/config/resource_files.rs
--- a/servo/components/config/resource_files.rs
+++ b/servo/components/config/resource_files.rs
@@ -22,20 +22,28 @@ lazy_static! {
 pub fn set_resources_path(path: Option<String>) {
     let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
     *dir = path;
 }
 
 #[cfg(target_os = "android")]
 #[allow(unsafe_code)]
 pub fn resources_dir_path() -> io::Result<PathBuf> {
-    let dir = unsafe {
+    let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
+
+    if let Some(ref path) = *dir {
+        return Ok(PathBuf::from(path));
+    }
+
+    let data_path = unsafe {
         CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
     };
-    Ok(PathBuf::from(dir.to_str().unwrap()))
+    let path = PathBuf::from(data_path.to_str().unwrap());
+    *dir = Some(path.to_str().unwrap().to_owned());
+    Ok(path)
 }
 
 #[cfg(not(target_os = "android"))]
 pub fn resources_dir_path() -> io::Result<PathBuf> {
     let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
 
     if let Some(ref path) = *dir {
         return Ok(PathBuf::from(path));