summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-27 13:58:46 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-04-27 13:58:46 +0200
commit932ba3e7d486aa0979469606dd52fd8a71c2c4e5 (patch)
treef0021c9402b79c7ed49e379b798ad5913055d8bd /bin
parent493fa0226cc3bfec392a2d5309142e45a47726b2 (diff)
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.
Diffstat (limited to 'bin')
-rw-r--r--bin/domain/imag-contact/src/create.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs
index e17cb287..d5ae4131 100644
--- a/bin/domain/imag-contact/src/create.rs
+++ b/bin/domain/imag-contact/src/create.rs
@@ -94,9 +94,27 @@ pub fn create(rt: &Runtime) {
} else if fl.is_dir() {
let uuid = Uuid::new_v4().hyphenated().to_string();
fl.push(uuid.clone());
+ fl.set_extension("vcf");
info!("Creating file: {:?}", fl);
Some(uuid)
} 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
};