KLR5FRIBS6UOH3S3XAOE22TJACVSVOY7TOLW22DIWNGY27S6WZRAC max_width = 80hard_tabs = falsetab_spaces = 4newline_style = "Auto"indent_style = "Block"use_small_heuristics = "Default"fn_call_width = 60attr_fn_like_width = 70struct_lit_width = 18struct_variant_width = 35array_width = 60chain_width = 60single_line_if_else_max_width = 50single_line_let_else_max_width = 50wrap_comments = trueformat_code_in_doc_comments = truedoc_comment_code_block_width = 80comment_width = 80normalize_comments = truenormalize_doc_attributes = falseformat_strings = falseformat_macro_matchers = falseformat_macro_bodies = trueskip_macro_invocations = []hex_literal_case = "Preserve"empty_item_single_line = truestruct_lit_single_line = truefn_single_line = falsewhere_single_line = falseimports_indent = "Block"imports_layout = "Mixed"imports_granularity = "Module"group_imports = "Preserve"reorder_imports = truereorder_modules = truereorder_impl_items = falsetype_punctuation_density = "Wide"space_before_colon = falsespace_after_colon = truespaces_around_ranges = falsebinop_separator = "Front"remove_nested_parens = truecombine_control_expr = trueshort_array_element_width_threshold = 10overflow_delimited_expr = falsestruct_field_align_threshold = 0enum_discrim_align_threshold = 0match_arm_blocks = truematch_arm_leading_pipes = "Never"force_multiline_blocks = falsefn_params_layout = "Tall"brace_style = "SameLineWhere"control_brace_style = "AlwaysSameLine"trailing_semicolon = truetrailing_comma = "Vertical"match_block_trailing_comma = falseblank_lines_upper_bound = 1blank_lines_lower_bound = 0edition = "2021"style_edition = "2021"inline_attribute_width = 0format_generated_files = truegenerated_marker_line_search_limit = 5merge_derives = trueuse_try_shorthand = falseuse_field_init_shorthand = falseforce_explicit_abi = truecondense_wildcard_suffixes = falsecolor = "Auto"required_version = "1.8.0"unstable_features = falsedisable_all_formatting = falseskip_children = falseshow_parse_errors = trueerror_on_line_overflow = falseerror_on_unformatted = falseignore = []emit_mode = "Files"make_backup = false
[toolchain]channel = "1.83.0"
#[doc(inline)]pub use serde::{Deserialize, Serialize};#[doc(inline)]pub use terrors::OneOf;#[doc(inline)]pub use thiserror::Error;
use crate::prelude::*;use super::dir;use async_fd_lock::{LockError, LockRead, LockWrite};use std::collections::BTreeMap;use std::path::{Path, PathBuf};use tokio::fs::File;use tokio::io::{AsyncReadExt, AsyncWriteExt};pub type Repos = BTreeMap<String, Repo>;#[derive(Debug, Serialize, Deserialize)]pub struct Repo {path: PathBuf,}#[derive(Debug, Error)]#[error("Another file-lock is blocking")]pub struct BlockingLockError;/// Acquire a read-lock to try to read [`Repos`]. If there's an active/// write-lock the call will fail with a [`BlockingLockError`].pub async fn read_repos() -> Result<Repos, ReadErr> {let file = match File::options().create_new(false).open(repos_path()).await{Err(err) if matches!(err.kind(), std::io::ErrorKind::NotFound) => {// Create a default `Repos` if file not foundreturn Ok(Repos::default());}result => result.map_err(OneOf::new)?,};let mut read_guard = match file.lock_read().await {Err(err)if matches!(err.error.kind(), std::io::ErrorKind::WouldBlock) =>{return Err(OneOf::new(BlockingLockError));}result => result.map_err(OneOf::new)?,};let mut buffer = Vec::new();read_guard.read_to_end(&mut buffer).await.map_err(OneOf::new)?;toml_edit::de::from_slice(&buffer).map_err(OneOf::new)}/// Acquire a write-lock to try to read [`Repos`]. If there's another active/// write-lock the call will fail with a [`BlockingLockError`].pub async fn write_repos(repos: &Repos) -> Result<(), WriteErr> {let file = File::options().create_new(true).open(repos_path()).await.map_err(OneOf::new)?;// Optimistically encode first to reduce the scope of the locklet repos_bytes =toml_edit::ser::to_string_pretty(repos).map_err(OneOf::new)?;let mut write_guard = match file.lock_write().await {Err(err)if matches!(err.error.kind(), std::io::ErrorKind::WouldBlock) =>{return Err(OneOf::new(BlockingLockError));}result => result.map_err(OneOf::new)?,};write_guard.write_all(repos_bytes.as_bytes()).await.map_err(OneOf::new)}pub type ReadErr = OneOf<(BlockingLockError,std::io::Error,LockError<tokio::fs::File>,toml_edit::de::Error,)>;pub type WriteErr = OneOf<(BlockingLockError,std::io::Error,LockError<tokio::fs::File>,toml_edit::ser::Error,)>;fn repos_path() -> PathBuf {PathBuf::from_iter([dir::data().as_path(), Path::new(REPOS_FILE)])}const REPOS_FILE: &str = "repos.toml";
pub mod dir;pub mod state;
[dependencies.serde]workspace = true[dependencies.terrors]workspace = true[dependencies.thiserror]workspace = true[dependencies.tokio]workspace = true[dependencies.toml_edit]workspace = trueoptional = true
path = "../pijul/libpijul"
path = "../pijul/libpijul"[workspace.dependencies.serde]version = "1.0"[workspace.dependencies.terrors]version = "0.3"[workspace.dependencies.thiserror]version = "2.0"[workspace.dependencies.tokio]version = "1.36"features = ["fs"][workspace.dependencies.toml_edit]version = "0.22"features = ["serde"]
name = "async-fd-lock"version = "0.2.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7569377d7062165f6f7834d9cb3051974a2d141433cc201c2f94c149e993cccf"dependencies = ["async-trait","cfg-if","pin-project","rustix","thiserror 1.0.69","tokio","windows-sys 0.52.0",][[package]]
[[package]]name = "backtrace"version = "0.3.74"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"dependencies = ["addr2line","cfg-if","libc","miniz_oxide","object","rustc-demangle","windows-targets 0.52.6",]
"thiserror-impl",
"thiserror-impl 1.0.69",][[package]]name = "thiserror"version = "2.0.11"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"dependencies = ["thiserror-impl 2.0.11",