summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-07-16 13:49:07 +0200
committerLinus Färnstrand <linus@mullvad.net>2018-07-16 18:03:21 +0200
commite3ccedc99c0b957dc5d3d9336b4f72350ecbfd3d (patch)
tree415d87e96b9d24dab7f86d4dbd210c88884171b3
parentc3678de2d760d6766ee673c51c2b1cdcf206d8d8 (diff)
downloadmullvadvpn-e3ccedc99c0b957dc5d3d9336b4f72350ecbfd3d.tar.xz
mullvadvpn-e3ccedc99c0b957dc5d3d9336b4f72350ecbfd3d.zip
Use dirs crate to find user home path. Canonicalize problem report paths
-rw-r--r--Cargo.lock11
-rw-r--r--mullvad-problem-report/Cargo.toml1
-rw-r--r--mullvad-problem-report/src/main.rs13
3 files changed, 19 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1bd24888d5..a4191d42f5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -255,6 +255,15 @@ dependencies = [
]
[[package]]
+name = "dirs"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "dtoa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -852,6 +861,7 @@ name = "mullvad-problem-report"
version = "2018.2.0-beta1"
dependencies = [
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mullvad-paths 0.1.0",
@@ -1940,6 +1950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum ctrlc 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "653abc99aa905f693d89df4797fadc08085baee379db92be9f2496cefe8a6f2c"
"checksum derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c998e6ab02a828dd9735c18f154e14100e674ed08cb4e1938f0e4177543f439"
"checksum derive_builder_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "735e24ee9e5fa8e16b86da5007856e97d592e11867e45d76e0c0d0a164a0b757"
+"checksum dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "37a76dd8b997af7107d0bb69d43903cf37153a18266f8b3fdb9911f28efb5444"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum duct 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "166298c17c5b4fe5997b962c2f22e887c7c5adc44308eb9103ce5b66af45a423"
"checksum env_logger 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "00c45cec4cde3daac5f036c74098b4956151525cdf360cff5ee0092c98823e54"
diff --git a/mullvad-problem-report/Cargo.toml b/mullvad-problem-report/Cargo.toml
index b0300bb516..199bbd1390 100644
--- a/mullvad-problem-report/Cargo.toml
+++ b/mullvad-problem-report/Cargo.toml
@@ -11,6 +11,7 @@ path = "src/main.rs"
[dependencies]
clap = "2.25"
+dirs = "1.0"
error-chain = "0.12"
lazy_static = "1.0"
regex = "1.0"
diff --git a/mullvad-problem-report/src/main.rs b/mullvad-problem-report/src/main.rs
index ce36aa253a..eeab6bd346 100644
--- a/mullvad-problem-report/src/main.rs
+++ b/mullvad-problem-report/src/main.rs
@@ -8,6 +8,7 @@
#[macro_use]
extern crate clap;
+extern crate dirs;
#[macro_use]
extern crate error_chain;
#[macro_use]
@@ -24,7 +25,6 @@ use regex::Regex;
use std::borrow::Cow;
use std::cmp::min;
use std::collections::{HashMap, HashSet};
-use std::env;
use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::{self, BufWriter, Read, Seek, SeekFrom, Write};
@@ -301,14 +301,15 @@ impl ProblemReport {
/// Attach a file log to this report. This method adds the error chain instead of the log
/// contents if an error occurs while reading the log file.
pub fn add_log(&mut self, path: &Path) {
- if self.log_paths.insert(path.to_owned()) {
+ let expanded_path = path.canonicalize().unwrap_or_else(|_| path.to_owned());
+ if self.log_paths.insert(expanded_path.clone()) {
+ let redacted_path = self.redact(&expanded_path.to_string_lossy());
let content = self.redact(
&read_file_lossy(path, LOG_MAX_READ_BYTES)
- .chain_err(|| ErrorKind::ReadLogError(path.to_path_buf()))
+ .chain_err(|| ErrorKind::ReadLogError(expanded_path))
.unwrap_or_else(|e| e.display_chain().to_string()),
);
- let path = self.redact(&path.to_string_lossy());
- self.logs.push((path, content));
+ self.logs.push((redacted_path, content));
}
}
@@ -338,7 +339,7 @@ impl ProblemReport {
}
fn redact_home_dir(input: &str) -> Cow<str> {
- match env::home_dir() {
+ match dirs::home_dir() {
Some(home) => Cow::from(input.replace(home.to_string_lossy().as_ref(), "~")),
None => Cow::from(input),
}