-
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.
Replace --verbose with --log-ndjson and fix clippy
- Loading branch information
1 parent
bc57932
commit 737dac4
Showing
8 changed files
with
84 additions
and
28 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
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,45 @@ | ||
use camino::{Utf8Path, Utf8PathBuf}; | ||
use serde::Serialize; | ||
use std::os::unix::fs::MetadataExt; | ||
|
||
/// Produce a JSON string which describes the outcome of `rx-repack`. | ||
pub(crate) fn json_message( | ||
src: &Utf8Path, | ||
result: anyhow::Result<Utf8PathBuf>, | ||
) -> anyhow::Result<String> { | ||
let msg = Message::new(src, result); | ||
serde_json::to_string(&msg).map_err(anyhow::Error::from) | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
struct Message<'a> { | ||
src: &'a Utf8Path, | ||
dst: Option<Utf8PathBuf>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
size: Option<u64>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
err: Option<String>, | ||
} | ||
|
||
impl<'a> Message<'a> { | ||
fn new(src: &'a Utf8Path, result: anyhow::Result<Utf8PathBuf>) -> Self { | ||
result | ||
.and_then(|dst| { | ||
fs_err::metadata(&dst) | ||
.map(|m| (dst, m.size())) | ||
.map_err(anyhow::Error::from) | ||
}) | ||
.map(|(dst, size)| Self { | ||
src, | ||
dst: Some(dst), | ||
size: Some(size), | ||
err: None, | ||
}) | ||
.unwrap_or_else(|e| Self { | ||
src, | ||
dst: None, | ||
size: None, | ||
err: Some(e.to_string()), | ||
}) | ||
} | ||
} |
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