Auto merge of #20750 - kwonoj:fix-wr-path, r=paulrouget

fix(capture_webrender): try fallback capture dir

<!-- Please describe your changes on the following line: -->

This PR try to update behavior of webrender capture to have fallback dir - first it try to create under current working dir, if fails go back to $TMPDIR. I was debating between TMP vs $home, bit hesitate to create some folder under user's home dir directly so choose TMP instead. Can be easily changed, or add few more if needed.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20746 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
- locally verified on mac os

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/20750)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-05-16 16:41:59 -04:00 committed by GitHub
commit d1f4fcfc51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 capture_id = now().to_timespec().sec.to_string();
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")
}
}
}