-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements data root reading for Linux (#1158)
- Loading branch information
1 parent
dc2b1b0
commit ceef556
Showing
8 changed files
with
73 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::io::ErrorKind; | ||
use std::path::PathBuf; | ||
use thiserror::Error; | ||
use xdg::BaseDirectories; | ||
|
||
pub fn read_data_root() -> Result<Option<PathBuf>, DataRootError> { | ||
let file = get_config_path()?; | ||
|
||
match std::fs::read_to_string(&file) { | ||
Ok(v) => Ok(Some(v.trim().into())), | ||
Err(e) if e.kind() == ErrorKind::NotFound => Ok(None), | ||
Err(e) => Err(DataRootError::ReadFile(file, e)), | ||
} | ||
} | ||
|
||
fn get_config_path() -> Result<PathBuf, DataRootError> { | ||
BaseDirectories::new() | ||
.map(|xdg| { | ||
let mut p = xdg.get_config_home(); | ||
p.push("obliteration.conf"); | ||
p | ||
}) | ||
.map_err(DataRootError::XdgBaseDirectory) | ||
} | ||
|
||
/// Represents an error when read or write data root fails. | ||
#[derive(Debug, Error)] | ||
pub enum DataRootError { | ||
#[error("couldn't load XDG Base Directory")] | ||
XdgBaseDirectory(#[source] xdg::BaseDirectoriesError), | ||
|
||
#[error("couldn't read {0}")] | ||
ReadFile(PathBuf, #[source] std::io::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::path::PathBuf; | ||
use thiserror::Error; | ||
|
||
pub fn read_data_root() -> Result<Option<PathBuf>, DataRootError> { | ||
todo!() | ||
} | ||
|
||
/// Represents an error when read or write data root fails. | ||
#[derive(Debug, Error)] | ||
pub enum DataRootError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::path::PathBuf; | ||
use thiserror::Error; | ||
|
||
pub fn read_data_root() -> Result<Option<PathBuf>, DataRootError> { | ||
todo!() | ||
} | ||
|
||
/// Represents an error when read or write data root fails. | ||
#[derive(Debug, Error)] | ||
pub enum DataRootError {} |