-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from tinythings/isbm-machine-id-relocated
machine id relocated
- Loading branch information
Showing
8 changed files
with
73 additions
and
8 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 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 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 |
---|---|---|
@@ -1,2 +1,27 @@ | ||
pub mod dataconv; | ||
pub mod iofs; | ||
|
||
use crate::SysinspectError; | ||
use std::{fs, io, path::PathBuf}; | ||
use uuid::Uuid; | ||
|
||
/// The `/etc/machine-id` is not always present, especially | ||
/// on the custom embedded systems. However, this file is used | ||
/// to identify a minion. | ||
/// | ||
/// Write the `/etc/machine-id` (or other location), if not any yet. | ||
pub fn write_machine_id(p: Option<PathBuf>) -> Result<(), SysinspectError> { | ||
let p = p.unwrap_or(PathBuf::from("/etc/machine-id")); | ||
if !p.exists() { | ||
if let Err(err) = fs::write(p, Uuid::new_v4().to_string().replace("-", "")) { | ||
return Err(SysinspectError::IoErr(err)); | ||
} | ||
} else { | ||
return Err(SysinspectError::IoErr(io::Error::new( | ||
io::ErrorKind::AlreadyExists, | ||
format!("File \"{}\" already exists", p.to_str().unwrap_or_default()), | ||
))); | ||
} | ||
|
||
Ok(()) | ||
} |
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