]> git.lizzy.rs Git - rust.git/commitdiff
Account for possibly empty license_template_path
authorDavid Lukes <dafydd.lukes@gmail.com>
Mon, 26 Feb 2018 11:31:09 +0000 (12:31 +0100)
committerDavid Lukes <dafydd.lukes@gmail.com>
Mon, 5 Mar 2018 12:13:55 +0000 (13:13 +0100)
Don't attempt to load license_template if the path wasn't specified.

src/config/config_type.rs

index ad2ae6f74227b96f21e93b70e8a1ec964e6eb80e..e6e5c5ef540d74e5693ff50feb0ae93338f46265 100644 (file)
@@ -392,35 +392,37 @@ fn set_heuristics(&mut self) {
             }
 
             fn set_license_template(&mut self) {
-                let license_template_path = self.license_template_path();
-                let mut license_template_file = match File::open(&license_template_path) {
-                    Ok(file) => file,
-                    Err(e) => {
-                        eprintln!("Warning: unable to open license template file {:?}: {}",
-                                  license_template_path, e);
-                        return;
-                    }
-                };
-                let mut license_template_str = String::new();
-                if let Err(e) = license_template_file.read_to_string(&mut license_template_str) {
-                    eprintln!("Warning: unable to read from license template file {:?}: {}",
-                              license_template_path, e);
-                    return;
-                };
-                let license_template_parsed = match parse_license_template(&license_template_str) {
-                    Ok(string) => string,
-                    Err(e) => {
-                        eprintln!("Warning: unable to parse license template file {:?}: {}",
-                                  license_template_path, e);
-                        return;
-                    }
-                };
-                self.license_template = match Regex::new(&license_template_parsed) {
-                    Ok(re) => Some(re),
-                    Err(e) => {
-                        eprintln!("Warning: regex syntax error in placeholder, unable to compile \
-                                   license template from file {:?}: {}", license_template_path, e);
+                if self.was_set().license_template_path() {
+                    let license_template_path = self.license_template_path();
+                    let mut license_template_file = match File::open(&license_template_path) {
+                        Ok(file) => file,
+                        Err(e) => {
+                            eprintln!("Warning: unable to open license template file {:?}: {}",
+                                    license_template_path, e);
+                            return;
+                        }
+                    };
+                    let mut license_template_str = String::new();
+                    if let Err(e) = license_template_file.read_to_string(&mut license_template_str) {
+                        eprintln!("Warning: unable to read from license template file {:?}: {}",
+                                license_template_path, e);
                         return;
+                    };
+                    let license_template_parsed = match parse_license_template(&license_template_str) {
+                        Ok(string) => string,
+                        Err(e) => {
+                            eprintln!("Warning: unable to parse license template file {:?}: {}",
+                                    license_template_path, e);
+                            return;
+                        }
+                    };
+                    self.license_template = match Regex::new(&license_template_parsed) {
+                        Ok(re) => Some(re),
+                        Err(e) => {
+                            eprintln!("Warning: regex syntax error in placeholder, unable to compile \
+                                    license template from file {:?}: {}", license_template_path, e);
+                            return;
+                        }
                     }
                 }
             }