Skip to content

Commit daf02c8

Browse files
committed
refactor(file): Clarify we are dealing with a path, not a name
1 parent fd28355 commit daf02c8

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/file/source/file.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,56 @@ impl FileSourceFile {
2525
where
2626
F: FileStoredFormat + Format + 'static,
2727
{
28-
let filename = if self.name.is_absolute() {
28+
let path = if self.name.is_absolute() {
2929
self.name.clone()
3030
} else {
3131
env::current_dir()?.as_path().join(&self.name)
3232
};
3333

3434
// First check for an _exact_ match
35-
if filename.is_file() {
35+
if path.is_file() {
3636
if let Some(format) = format_hint {
37-
return Ok((filename, Box::new(format)));
37+
return Ok((path, Box::new(format)));
3838
} else {
39-
let ext = filename.extension().unwrap_or_default().to_string_lossy();
39+
let ext = path.extension().unwrap_or_default().to_string_lossy();
4040
for format in FileFormat::all() {
4141
if format.extensions().contains(&ext.as_ref()) {
42-
return Ok((filename, Box::new(*format)));
42+
return Ok((path, Box::new(*format)));
4343
}
4444
}
4545
return Err(Box::new(io::Error::new(
4646
io::ErrorKind::NotFound,
4747
format!(
4848
"configuration file \"{}\" is not of a registered file format",
49-
filename.to_string_lossy()
49+
path.to_string_lossy()
5050
),
5151
)));
5252
};
5353
}
5454

55-
let mut filename = filename;
55+
let mut path = path;
5656
// Preserve any extension-like text within the provided file stem by appending a fake extension
5757
// which will be replaced by `set_extension()` calls (e.g. `file.local.placeholder` => `file.local.json`)
58-
if filename.extension().is_some() {
59-
filename.as_mut_os_string().push(".placeholder");
58+
if path.extension().is_some() {
59+
path.as_mut_os_string().push(".placeholder");
6060
}
6161
match format_hint {
6262
Some(format) => {
6363
for ext in format.file_extensions() {
64-
filename.set_extension(ext);
64+
path.set_extension(ext);
6565

66-
if filename.is_file() {
67-
return Ok((filename, Box::new(format)));
66+
if path.is_file() {
67+
return Ok((path, Box::new(format)));
6868
}
6969
}
7070
}
7171
None => {
7272
for format in FileFormat::all() {
7373
for ext in format.extensions() {
74-
filename.set_extension(ext);
74+
path.set_extension(ext);
7575

76-
if filename.is_file() {
77-
return Ok((filename, Box::new(*format)));
76+
if path.is_file() {
77+
return Ok((path, Box::new(*format)));
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)