Skip to content

Commit

Permalink
chore: Fmt and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LeChatP committed Sep 25, 2024
1 parent 115b558 commit d9e4de8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
27 changes: 20 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use std::{error::Error, fs::{self, File}, io::{BufRead, BufReader, Write}, path::Path};
use std::{
error::Error,
fs::{self, File},
io::{BufRead, BufReader, Write},
path::Path,
};

use toml::Table;


fn package_version<P:AsRef<Path>>(path : P) -> Result<String, Box<dyn Error>> {
fn package_version<P: AsRef<Path>>(path: P) -> Result<String, Box<dyn Error>> {
let cargo_toml = fs::read_to_string(path)?;
let value: Table = cargo_toml.parse::<Table>()?;
Ok(value["package"]["version"].as_str().map(|s| s.to_string()).expect("Failed to get package version"))
Ok(value["package"]["version"]
.as_str()
.map(|s| s.to_string())
.expect("Failed to get package version"))
}

fn write_version<'a>(f: &'a mut File, package_version: &'a str) -> Result<&'a str, Box<dyn Error>> {
Expand Down Expand Up @@ -65,8 +72,14 @@ fn main() {
}

let package_version = package_version("Cargo.toml").expect("Failed to get package version");
let dest_path = std::path::Path::new("rar-common").join("src").join("version.rs");
if dest_path.exists() && fs::read_to_string(&dest_path).unwrap().ends_with(&format!("\"{}\";\n",package_version)) {
let dest_path = std::path::Path::new("rar-common")
.join("src")
.join("version.rs");
if dest_path.exists()
&& fs::read_to_string(&dest_path)
.unwrap()
.ends_with(&format!("\"{}\";\n", package_version))
{
return;
}
let mut f = File::create(dest_path).unwrap();
Expand All @@ -88,4 +101,4 @@ fn main() {
if let Err(err) = set_readme_version(&package_version, "README.md") {
eprintln!("cargo:warning={}", err);
}
}
}
1 change: 0 additions & 1 deletion rar-common/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use chrono::Duration;
use linked_hash_set::LinkedHashSet;
use serde::{de, Deserialize, Serialize};
use tracing::debug;
use tracing_subscriber::field::debug;

use self::{migration::Migration, options::EnvKey, structs::SConfig, versionning::Versioning};

Expand Down
6 changes: 2 additions & 4 deletions rar-common/src/database/versionning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ impl<T: Default + Debug> Default for Versioning<T> {
}
}

pub(crate) const JSON_MIGRATIONS: &[Migration<SConfig>] = &[
];
pub(crate) const JSON_MIGRATIONS: &[Migration<SConfig>] = &[];

pub(crate) const SETTINGS_MIGRATIONS: &[Migration<SettingsFile>] = &[
];
pub(crate) const SETTINGS_MIGRATIONS: &[Migration<SettingsFile>] = &[];
7 changes: 5 additions & 2 deletions xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::{
fs::{self, File},
io,
os::{fd::AsRawFd, unix::fs::MetadataExt},
path::Path, process::Command,
path::Path,
process::Command,
};

use anyhow::{anyhow, Context};
Expand Down Expand Up @@ -120,7 +121,9 @@ fn read_or_dac_override(effective: bool) -> Result<(), capctl::Error> {
}

pub fn change_dir_to_git_root() -> Result<(), anyhow::Error> {
let output = Command::new("git").args(&["rev-parse", "--show-toplevel"]).output()?;
let output = Command::new("git")
.args(&["rev-parse", "--show-toplevel"])
.output()?;
let git_root = String::from_utf8(output.stdout)?.trim().to_string();
debug!("Changing directory to git root: {}", git_root);
std::env::set_current_dir(git_root)?;
Expand Down

0 comments on commit d9e4de8

Please sign in to comment.