Merge pull request #1460 from matthiasbeyer/imag-contact/warn-if-no-extension

Set extension or warn if none there
This commit is contained in:
Matthias Beyer 2018-04-27 14:46:39 +02:00 committed by GitHub
commit bfd536d3fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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
}; };