summaryrefslogtreecommitdiffstats
path: root/src/file/source/file.rs
diff options
context:
space:
mode:
authorCfirTsabari <cfir16@gmail.com>2022-03-27 11:22:53 +0000
committerCfirTsabari <cfir16@gmail.com>2022-04-10 18:37:35 +0000
commit34ea07a8a714fd4c8d4b4bc0606e2d536dc275d5 (patch)
tree1bd52456c912a832b637a0728b9c6c8c355fc98c /src/file/source/file.rs
parent8f1ccff320aa81eed85d4d4d686b56d2dd0e5643 (diff)
fix: dot in config name
Rust std `set_extension` is either add an extension if none exists, or edit the current one if such exists. This caused a mishandling when user is using a name with a dot, part of the name was treated as an extension, and be overwritten by the different format extensions. So manually *adding* a new dummy extension will cause the current code, to behave as expected, since it will always overwrite the new dummy extension and not part of the name.
Diffstat (limited to 'src/file/source/file.rs')
-rw-r--r--src/file/source/file.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/file/source/file.rs b/src/file/source/file.rs
index 403f3f2..8ee5d31 100644
--- a/src/file/source/file.rs
+++ b/src/file/source/file.rs
@@ -27,7 +27,7 @@ impl FileSourceFile {
where
F: FileStoredFormat + Format + 'static,
{
- let mut filename = if self.name.is_absolute() {
+ let filename = if self.name.is_absolute() {
self.name.clone()
} else {
env::current_dir()?.as_path().join(&self.name)
@@ -59,6 +59,9 @@ impl FileSourceFile {
)))
};
}
+ // Adding a dummy extension will make sure we will not override secondary extensions, i.e. "file.local"
+ // This will make the following set_extension function calls to append the extension.
+ let mut filename = add_dummy_extension(filename);
match format_hint {
Some(format) => {
@@ -121,3 +124,18 @@ where
})
}
}
+
+fn add_dummy_extension(mut filename: PathBuf) -> PathBuf {
+ match filename.extension() {
+ Some(extension) => {
+ let mut ext = extension.to_os_string();
+ ext.push(".");
+ ext.push("dummy");
+ filename.set_extension(ext);
+ }
+ None => {
+ filename.set_extension("dummy");
+ }
+ }
+ filename
+}