fix(capture_webrender): try fallback capture dir

This commit is contained in:
OJ Kwon 2018-05-04 15:53:25 -07:00
parent 8e978dab17
commit 1ec078a1e3
No known key found for this signature in database
GPG key ID: FFCFEF3460FD1901

View file

@ -1404,17 +1404,24 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
pub fn capture_webrender(&mut self) {
match env::current_dir() {
Ok(current_dir) => {
let capture_id = now().to_timespec().sec.to_string();
let capture_path = current_dir.join("capture_webrender").join(capture_id);
let available_path = [env::current_dir(), Ok(env::temp_dir())].iter()
.filter_map(|val| val.as_ref().map(|dir| dir.join("capture_webrender").join(&capture_id)).ok())
.find(|val| {
match create_dir_all(&val) {
Ok(_) => true,
Err(err) => {
eprintln!("Unable to create path '{:?}' for capture: {:?}", &val, err);
false
}
}
});
match available_path {
Some(capture_path) => {
let revision_file_path = capture_path.join("wr.txt");
if let Err(err) = create_dir_all(&capture_path) {
eprintln!("Unable to create path '{:?}' for capture: {:?}", capture_path, err);
return
}
debug!("Trying to save webrender capture under {:?}", &revision_file_path);
self.webrender_api.save_capture(capture_path, webrender_api::CaptureBits::all());
match File::create(revision_file_path) {
@ -1427,7 +1434,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
Err(err) => eprintln!("Capture triggered, creating webrender revision info skipped: {:?}", err)
}
},
Err(err) => eprintln!("Unable to locate path to save captures: {:?}", err)
None => eprintln!("Unable to locate path to save captures")
}
}
}