mirror of
https://github.com/telemt/telemt.git
synced 2026-11-03 22:31:59 +03:00
Rustfmt
This commit is contained in:
@@ -86,9 +86,9 @@ pub(in crate::api) async fn write_atomic(
|
||||
let _lock = ConfigWriteLock::acquire(&path)?;
|
||||
write_atomic_sync(&path, None, &contents, None).map(|_| ())
|
||||
})
|
||||
.await
|
||||
.map_err(|error| ApiFailure::internal(format!("failed to join writer: {error}")))?
|
||||
.map_err(|error| ApiFailure::internal(format!("failed to write config: {error}")))
|
||||
.await
|
||||
.map_err(|error| ApiFailure::internal(format!("failed to join writer: {error}")))?
|
||||
.map_err(|error| ApiFailure::internal(format!("failed to write config: {error}")))
|
||||
}
|
||||
|
||||
/// Replaces one source only if both its graph revision and owner contents are unchanged.
|
||||
@@ -294,11 +294,7 @@ fn write_atomic_sync(
|
||||
let descriptor = openat(
|
||||
anchored.parent(),
|
||||
temp_name.as_str(),
|
||||
OFlag::O_WRONLY
|
||||
| OFlag::O_CREAT
|
||||
| OFlag::O_EXCL
|
||||
| OFlag::O_NOFOLLOW
|
||||
| OFlag::O_CLOEXEC,
|
||||
OFlag::O_WRONLY | OFlag::O_CREAT | OFlag::O_EXCL | OFlag::O_NOFOLLOW | OFlag::O_CLOEXEC,
|
||||
Mode::from_bits_truncate(0o600),
|
||||
)
|
||||
.map_err(errno_to_io)?;
|
||||
@@ -408,9 +404,9 @@ fn validate_expected_contents(
|
||||
existing: Option<&ExistingTarget>,
|
||||
expected_contents: Option<&str>,
|
||||
) -> std::io::Result<()> {
|
||||
if expected_contents.is_some_and(|expected| {
|
||||
existing.is_none_or(|target| target.contents != expected)
|
||||
}) {
|
||||
if expected_contents
|
||||
.is_some_and(|expected| existing.is_none_or(|target| target.contents != expected))
|
||||
{
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::AlreadyExists,
|
||||
"config source changed before persistence",
|
||||
@@ -419,10 +415,7 @@ fn validate_expected_contents(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn target_unchanged(
|
||||
existing: Option<&ExistingTarget>,
|
||||
current: Option<&ExistingTarget>,
|
||||
) -> bool {
|
||||
fn target_unchanged(existing: Option<&ExistingTarget>, current: Option<&ExistingTarget>) -> bool {
|
||||
match (existing, current) {
|
||||
(Some(expected), Some(current)) => {
|
||||
same_target(&expected.metadata, ¤t.metadata)
|
||||
|
||||
@@ -6,15 +6,15 @@ use serde::Serialize;
|
||||
|
||||
use crate::config::{ProxyConfig, RateLimitBps};
|
||||
|
||||
#[cfg(test)]
|
||||
use super::atomic::write_atomic;
|
||||
use super::atomic::write_atomic_if_unchanged;
|
||||
#[cfg(test)]
|
||||
use super::compute_revision;
|
||||
use super::{
|
||||
AccessSection, compute_snapshot_revision, load_candidate_snapshot, load_config_snapshot,
|
||||
resolve_single_source_owner, toml_path_exists,
|
||||
};
|
||||
use super::atomic::write_atomic_if_unchanged;
|
||||
#[cfg(test)]
|
||||
use super::atomic::write_atomic;
|
||||
use crate::api::model::ApiFailure;
|
||||
|
||||
/// Re-render the given top-level tables from `cfg` and upsert each into the
|
||||
|
||||
@@ -266,8 +266,7 @@ async fn access_mutation_rejects_source_graph_change_after_snapshot() {
|
||||
let root = dir.path().join("config.toml");
|
||||
let included = dir.path().join("users.toml");
|
||||
let root_body = "include = \"users.toml\"\n[censorship]\ntls_domain = \"one.example\"\n";
|
||||
let external_root =
|
||||
"include = \"users.toml\"\n[censorship]\ntls_domain = \"two.example\"\n";
|
||||
let external_root = "include = \"users.toml\"\n[censorship]\ntls_domain = \"two.example\"\n";
|
||||
let included_body = "[access.users]\nalice = \"00000000000000000000000000000000\"\n";
|
||||
tokio::fs::write(&root, root_body).await.unwrap();
|
||||
tokio::fs::write(&included, included_body).await.unwrap();
|
||||
@@ -288,7 +287,10 @@ async fn access_mutation_rejects_source_graph_change_after_snapshot() {
|
||||
.unwrap_err();
|
||||
|
||||
assert_eq!(error.code, "revision_conflict");
|
||||
assert_eq!(tokio::fs::read_to_string(&root).await.unwrap(), external_root);
|
||||
assert_eq!(
|
||||
tokio::fs::read_to_string(&root).await.unwrap(),
|
||||
external_root
|
||||
);
|
||||
assert_eq!(
|
||||
tokio::fs::read_to_string(&included).await.unwrap(),
|
||||
included_body
|
||||
|
||||
Reference in New Issue
Block a user