From d2d9759d7b3705bd4b956c598af6de981a8fc461 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 8 Feb 2018 10:49:28 -0500 Subject: [PATCH] Bug 1433932: Avoid crashing on failing to save a capture. r=nical,kats MozReview-Commit-ID: ARj9ww2F3gx --- gfx/webrender_bindings/src/bindings.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index d8e6fad25137..d493a5a4d073 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -1164,20 +1164,26 @@ pub extern "C" fn wr_api_capture( path: *const c_char, bits_raw: u32, ) { - use std::fs::File; + use std::fs::{File, create_dir_all}; use std::io::Write; let cstr = unsafe { CStr::from_ptr(path) }; let path = PathBuf::from(&*cstr.to_string_lossy()); - let revision_path = path.join("wr.txt"); + + let _ = create_dir_all(&path); + match File::create(path.join("wr.txt")) { + Ok(mut file) => { + let revision = include_bytes!("../revision.txt"); + file.write(revision).unwrap(); + } + Err(e) => { + println!("Unable to create path '{:?}' for capture: {:?}", path, e); + return + } + } + let bits = CaptureBits::from_bits(bits_raw as _).unwrap(); dh.api.save_capture(path, bits); - - let revision = include_bytes!("../revision.txt"); - File::create(revision_path) - .unwrap() - .write(revision) - .unwrap(); } #[cfg(target_os = "windows")]