Set extension or warn if none there

In case of auto-generating the file name, we should add an extension.
If we do not auto-generate the file name, we should warn that the
extension for the file is missing.
This commit is contained in:
Matthias Beyer 2018-04-27 13:58:46 +02:00
parent 493fa0226c
commit 932ba3e7d4

View file

@ -94,9 +94,27 @@ pub fn create(rt: &Runtime) {
} else if fl.is_dir() { } else if fl.is_dir() {
let uuid = Uuid::new_v4().hyphenated().to_string(); let uuid = Uuid::new_v4().hyphenated().to_string();
fl.push(uuid.clone()); fl.push(uuid.clone());
fl.set_extension("vcf");
info!("Creating file: {:?}", fl); info!("Creating file: {:?}", fl);
Some(uuid) Some(uuid)
} else { } else {
let has_vcf_ext = fl
.extension()
.and_then(|ext| ext.to_str())
.map(|ext| ext == "vcf")
.unwrap_or(false);
if !has_vcf_ext {
let f = fl.file_name()
.and_then(|ext| ext.to_str())
.map(|f| format!(" '{}' ", f)) // ugly
.unwrap_or_else(|| String::from(" ")); // hack
warn!("File{}has no extension 'vcf'", f); // ahead
warn!("other tools might not recognize this as contact.");
warn!("Continuing...");
}
None None
}; };