From 98703f7a414bb7ff8776b2946f82b7296c8791cb Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 30 Apr 2025 11:30:50 +0300 Subject: [PATCH] chore(snix): configure rustfmt for edition 2024 crates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a rustfmt.toml to all the crates that are already migrated to edition 2024. Initially proposed in cl/30341. Fixes #115. Change-Id: I9f58cd45e38fec3acbb077492d5402e30560996b Reviewed-on: https://cl.snix.dev/c/snix/+/30343 Tested-by: besadii Autosubmit: Florian Klink Reviewed-by: Domen Kožar --- snix/castore/rustfmt.toml | 2 ++ snix/castore/src/bin/snix-castore.rs | 10 +++--- .../castore/src/blobservice/chunked_reader.rs | 4 +-- snix/castore/src/blobservice/from_addr.rs | 2 +- snix/castore/src/blobservice/grpc.rs | 12 +++---- snix/castore/src/blobservice/mod.rs | 2 +- snix/castore/src/blobservice/object_store.rs | 10 +++--- snix/castore/src/blobservice/tests/mod.rs | 34 +++++++++++-------- snix/castore/src/blobservice/tests/utils.rs | 2 +- snix/castore/src/composition.rs | 4 +-- snix/castore/src/directoryservice/bigtable.rs | 8 ++--- .../src/directoryservice/combinators.rs | 6 ++-- .../src/directoryservice/directory_graph.rs | 4 +-- .../castore/src/directoryservice/from_addr.rs | 2 +- snix/castore/src/directoryservice/grpc.rs | 20 ++++++----- .../src/directoryservice/object_store.rs | 14 ++++---- .../src/directoryservice/order_validator.rs | 2 +- snix/castore/src/directoryservice/redb.rs | 7 ++-- .../src/directoryservice/tests/utils.rs | 2 +- snix/castore/src/directoryservice/traverse.rs | 5 ++- snix/castore/src/errors.rs | 2 +- snix/castore/src/fs/fuse/tests.rs | 7 ++-- snix/castore/src/fs/inodes.rs | 2 +- snix/castore/src/fs/mod.rs | 8 ++--- snix/castore/src/fs/root_nodes.rs | 2 +- snix/castore/src/import/archive.rs | 10 +++--- snix/castore/src/import/blobs.rs | 4 +-- snix/castore/src/import/fs.rs | 8 ++--- snix/castore/src/import/mod.rs | 4 +-- snix/castore/src/nodes/directory.rs | 2 +- snix/castore/src/path/component.rs | 2 +- .../src/proto/grpc_blobservice_wrapper.rs | 8 ++--- .../proto/grpc_directoryservice_wrapper.rs | 6 ++-- snix/castore/src/proto/mod.rs | 2 +- snix/castore/src/proto/tests/directory.rs | 2 +- snix/castore/src/proto/tests/mod.rs | 2 +- snix/castore/src/refscan.rs | 4 +-- snix/castore/src/tests/import.rs | 26 ++++++++------ snix/castore/src/utils.rs | 2 +- snix/store/rustfmt.toml | 2 ++ snix/store/src/bin/snix-store.rs | 8 ++--- snix/store/src/fixtures.rs | 2 +- snix/store/src/import.rs | 2 +- snix/store/src/nar/hashing_reader.rs | 4 +-- snix/store/src/nar/import.rs | 7 ++-- snix/store/src/nar/mod.rs | 10 +++--- snix/store/src/nar/renderer.rs | 2 +- snix/store/src/nar/seekable.rs | 6 ++-- snix/store/src/pathinfoservice/bigtable.rs | 8 ++--- snix/store/src/pathinfoservice/cache.rs | 13 +++---- snix/store/src/pathinfoservice/from_addr.rs | 6 ++-- snix/store/src/pathinfoservice/fs/mod.rs | 4 +-- snix/store/src/pathinfoservice/grpc.rs | 8 ++--- snix/store/src/pathinfoservice/lru.rs | 24 +++++++------ snix/store/src/pathinfoservice/memory.rs | 2 +- snix/store/src/pathinfoservice/mod.rs | 2 +- snix/store/src/pathinfoservice/nix_http.rs | 4 +-- snix/store/src/pathinfoservice/redb.rs | 4 +-- .../src/pathinfoservice/signing_wrapper.rs | 13 +++---- snix/store/src/pathinfoservice/tests/mod.rs | 13 +++---- snix/store/src/pathinfoservice/tests/utils.rs | 10 +++--- .../src/proto/grpc_pathinfoservice_wrapper.rs | 4 +-- snix/store/src/tests/nar_renderer.rs | 2 +- snix/store/src/tests/nar_renderer_seekable.rs | 2 +- snix/store/src/utils.rs | 2 +- 65 files changed, 222 insertions(+), 197 deletions(-) create mode 100644 snix/castore/rustfmt.toml create mode 100644 snix/store/rustfmt.toml diff --git a/snix/castore/rustfmt.toml b/snix/castore/rustfmt.toml new file mode 100644 index 000000000..4dfc1d2b7 --- /dev/null +++ b/snix/castore/rustfmt.toml @@ -0,0 +1,2 @@ +# FUTUREWORK: move to .. once all crates are migrated (#114) +edition = "2024" diff --git a/snix/castore/src/bin/snix-castore.rs b/snix/castore/src/bin/snix-castore.rs index 978fafa7b..c583ac721 100644 --- a/snix/castore/src/bin/snix-castore.rs +++ b/snix/castore/src/bin/snix-castore.rs @@ -1,14 +1,14 @@ use clap::{Parser, Subcommand}; +#[cfg(any(feature = "fuse", feature = "virtiofs"))] +use snix_castore::B3Digest; +use snix_castore::Node; +#[cfg(feature = "fs")] +use snix_castore::fs::SnixStoreFs; #[cfg(feature = "fuse")] use snix_castore::fs::fuse::FuseDaemon; #[cfg(feature = "virtiofs")] use snix_castore::fs::virtiofs::start_virtiofs_daemon; -#[cfg(feature = "fs")] -use snix_castore::fs::SnixStoreFs; use snix_castore::import::{archive::ingest_archive, fs::ingest_path}; -#[cfg(any(feature = "fuse", feature = "virtiofs"))] -use snix_castore::B3Digest; -use snix_castore::Node; use std::error::Error; use std::io::Write; use std::path::PathBuf; diff --git a/snix/castore/src/blobservice/chunked_reader.rs b/snix/castore/src/blobservice/chunked_reader.rs index 3ff20ffde..caee3209d 100644 --- a/snix/castore/src/blobservice/chunked_reader.rs +++ b/snix/castore/src/blobservice/chunked_reader.rs @@ -1,4 +1,4 @@ -use futures::{ready, TryStreamExt}; +use futures::{TryStreamExt, ready}; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncSeekExt}; use tokio_stream::StreamExt; @@ -259,8 +259,8 @@ mod test { }; use crate::{ - blobservice::{chunked_reader::ChunkedReader, BlobService, MemoryBlobService}, B3Digest, + blobservice::{BlobService, MemoryBlobService, chunked_reader::ChunkedReader}, }; use hex_literal::hex; use tokio::io::{AsyncReadExt, AsyncSeekExt}; diff --git a/snix/castore/src/blobservice/from_addr.rs b/snix/castore/src/blobservice/from_addr.rs index 7eb0031ca..aad50d3df 100644 --- a/snix/castore/src/blobservice/from_addr.rs +++ b/snix/castore/src/blobservice/from_addr.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use url::Url; use crate::composition::{ - with_registry, CompositionContext, DeserializeWithRegistry, ServiceBuilder, REG, + CompositionContext, DeserializeWithRegistry, REG, ServiceBuilder, with_registry, }; use super::BlobService; diff --git a/snix/castore/src/blobservice/grpc.rs b/snix/castore/src/blobservice/grpc.rs index c0f294b57..283bda6b5 100644 --- a/snix/castore/src/blobservice/grpc.rs +++ b/snix/castore/src/blobservice/grpc.rs @@ -1,8 +1,8 @@ use super::{BlobReader, BlobService, BlobWriter, ChunkedReader}; use crate::composition::{CompositionContext, ServiceBuilder}; use crate::{ - proto::{self, stat_blob_response::ChunkMeta}, B3Digest, + proto::{self, stat_blob_response::ChunkMeta}, }; use futures::sink::SinkExt; use std::{ @@ -13,13 +13,13 @@ use std::{ }; use tokio::io::AsyncWriteExt; use tokio::task::JoinHandle; -use tokio_stream::{wrappers::ReceiverStream, StreamExt}; +use tokio_stream::{StreamExt, wrappers::ReceiverStream}; use tokio_util::{ io::{CopyToBytes, SinkWriter}, sync::PollSender, }; -use tonic::{async_trait, Code, Status}; -use tracing::{instrument, Instrument as _}; +use tonic::{Code, Status, async_trait}; +use tracing::{Instrument as _, instrument}; /// Connects to a (remote) snix-store BlobService over gRPC. #[derive(Clone)] @@ -323,14 +323,14 @@ mod tests { use tempfile::TempDir; use tokio::net::UnixListener; - use tokio_retry::strategy::ExponentialBackoff; use tokio_retry::Retry; + use tokio_retry::strategy::ExponentialBackoff; use tokio_stream::wrappers::UnixListenerStream; use crate::blobservice::MemoryBlobService; use crate::fixtures; - use crate::proto::blob_service_client::BlobServiceClient; use crate::proto::GRPCBlobServiceWrapper; + use crate::proto::blob_service_client::BlobServiceClient; use super::BlobService; use super::GRPCBlobService; diff --git a/snix/castore/src/blobservice/mod.rs b/snix/castore/src/blobservice/mod.rs index efba927b5..da55524c7 100644 --- a/snix/castore/src/blobservice/mod.rs +++ b/snix/castore/src/blobservice/mod.rs @@ -3,9 +3,9 @@ use std::io; use auto_impl::auto_impl; use tonic::async_trait; +use crate::B3Digest; use crate::composition::{Registry, ServiceBuilder}; use crate::proto::stat_blob_response::ChunkMeta; -use crate::B3Digest; mod chunked_reader; mod combinator; diff --git a/snix/castore/src/blobservice/object_store.rs b/snix/castore/src/blobservice/object_store.rs index 37ece02a2..437307ceb 100644 --- a/snix/castore/src/blobservice/object_store.rs +++ b/snix/castore/src/blobservice/object_store.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map, HashMap}, + collections::{HashMap, hash_map}, io::{self, Cursor}, pin::pin, sync::Arc, @@ -9,19 +9,19 @@ use std::{ use data_encoding::HEXLOWER; use fastcdc::v2020::AsyncStreamCDC; use futures::Future; -use object_store::{path::Path, ObjectStore}; +use object_store::{ObjectStore, path::Path}; use pin_project_lite::pin_project; use prost::Message; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt}; use tokio_stream::StreamExt; use tonic::async_trait; -use tracing::{debug, instrument, trace, Level}; +use tracing::{Level, debug, instrument, trace}; use url::Url; use crate::{ - composition::{CompositionContext, ServiceBuilder}, - proto::{stat_blob_response::ChunkMeta, StatBlobResponse}, B3Digest, B3HashingReader, Error, + composition::{CompositionContext, ServiceBuilder}, + proto::{StatBlobResponse, stat_blob_response::ChunkMeta}, }; use super::{BlobReader, BlobService, BlobWriter, ChunkedReader}; diff --git a/snix/castore/src/blobservice/tests/mod.rs b/snix/castore/src/blobservice/tests/mod.rs index 0280faebb..d6222a703 100644 --- a/snix/castore/src/blobservice/tests/mod.rs +++ b/snix/castore/src/blobservice/tests/mod.rs @@ -31,21 +31,25 @@ pub fn blob_services(#[case] blob_service: impl BlobService) {} #[apply(blob_services)] #[tokio::test] async fn has_nonexistent_false(blob_service: impl BlobService) { - assert!(!blob_service - .has(&BLOB_A_DIGEST) - .await - .expect("must not fail")); + assert!( + !blob_service + .has(&BLOB_A_DIGEST) + .await + .expect("must not fail") + ); } /// Using [BlobService::chunks] on a non-existing blob should return Ok(None) #[apply(blob_services)] #[tokio::test] async fn chunks_nonexistent_false(blob_service: impl BlobService) { - assert!(blob_service - .chunks(&BLOB_A_DIGEST) - .await - .expect("must be ok") - .is_none()); + assert!( + blob_service + .chunks(&BLOB_A_DIGEST) + .await + .expect("must be ok") + .is_none() + ); } // TODO: do tests with `chunks` @@ -54,11 +58,13 @@ async fn chunks_nonexistent_false(blob_service: impl BlobService) { #[apply(blob_services)] #[tokio::test] async fn not_found_read(blob_service: impl BlobService) { - assert!(blob_service - .open_read(&BLOB_A_DIGEST) - .await - .expect("must not fail") - .is_none()) + assert!( + blob_service + .open_read(&BLOB_A_DIGEST) + .await + .expect("must not fail") + .is_none() + ) } /// Put a blob in the store, check has, get it back. diff --git a/snix/castore/src/blobservice/tests/utils.rs b/snix/castore/src/blobservice/tests/utils.rs index c7e41d965..5c65ef873 100644 --- a/snix/castore/src/blobservice/tests/utils.rs +++ b/snix/castore/src/blobservice/tests/utils.rs @@ -1,6 +1,6 @@ use crate::blobservice::{BlobService, MemoryBlobService}; -use crate::proto::blob_service_client::BlobServiceClient; use crate::proto::GRPCBlobServiceWrapper; +use crate::proto::blob_service_client::BlobServiceClient; use crate::{blobservice::GRPCBlobService, proto::blob_service_server::BlobServiceServer}; use hyper_util::rt::TokioIo; use tonic::transport::{Endpoint, Server, Uri}; diff --git a/snix/castore/src/composition.rs b/snix/castore/src/composition.rs index 263ff5c23..1ce62ed15 100644 --- a/snix/castore/src/composition.rs +++ b/snix/castore/src/composition.rs @@ -97,8 +97,8 @@ //! This behavior might change in the future. use erased_serde::deserialize; -use futures::future::BoxFuture; use futures::FutureExt; +use futures::future::BoxFuture; use serde::de::DeserializeOwned; use serde_tagged::de::{BoxFnSeed, SeedFactory}; use serde_tagged::util::TagString; @@ -152,7 +152,7 @@ impl<'r, 'de: 'r, T: 'static> SeedFactory<'de, TagString<'de>> for RegistryWithF // using find() and not get() because of https://github.com/rust-lang/rust/issues/80389 let seed: &Box = self .0 - .0 + .0 .iter() .find(|(k, _)| *k == &(TypeId::of::(), tag.as_ref())) .ok_or_else(|| serde::de::Error::custom(format!("Unknown type: {}", tag)))? diff --git a/snix/castore/src/directoryservice/bigtable.rs b/snix/castore/src/directoryservice/bigtable.rs index b8f7be478..1faf9349e 100644 --- a/snix/castore/src/directoryservice/bigtable.rs +++ b/snix/castore/src/directoryservice/bigtable.rs @@ -4,16 +4,16 @@ use data_encoding::HEXLOWER; use futures::stream::BoxStream; use prost::Message; use serde::{Deserialize, Serialize}; -use serde_with::{serde_as, DurationSeconds}; +use serde_with::{DurationSeconds, serde_as}; use std::sync::Arc; use tonic::async_trait; use tracing::{instrument, trace, warn}; use super::{ - utils::traverse_directory, Directory, DirectoryPutter, DirectoryService, SimplePutter, + Directory, DirectoryPutter, DirectoryService, SimplePutter, utils::traverse_directory, }; use crate::composition::{CompositionContext, ServiceBuilder}; -use crate::{proto, B3Digest, Error}; +use crate::{B3Digest, Error, proto}; /// There should not be more than 10 MiB in a single cell. /// @@ -79,7 +79,7 @@ impl BigtableDirectoryService { use async_process::{Command, Stdio}; use tempfile::TempDir; - use tokio_retry::{strategy::ExponentialBackoff, Retry}; + use tokio_retry::{Retry, strategy::ExponentialBackoff}; let tmpdir = TempDir::new().unwrap(); diff --git a/snix/castore/src/directoryservice/combinators.rs b/snix/castore/src/directoryservice/combinators.rs index 72e972963..b3fb61671 100644 --- a/snix/castore/src/directoryservice/combinators.rs +++ b/snix/castore/src/directoryservice/combinators.rs @@ -1,17 +1,17 @@ use std::sync::Arc; -use futures::stream::BoxStream; use futures::StreamExt; use futures::TryFutureExt; use futures::TryStreamExt; +use futures::stream::BoxStream; use tonic::async_trait; use tracing::{instrument, trace}; use super::{Directory, DirectoryGraph, DirectoryService, RootToLeavesValidator, SimplePutter}; -use crate::composition::{CompositionContext, ServiceBuilder}; -use crate::directoryservice::DirectoryPutter; use crate::B3Digest; use crate::Error; +use crate::composition::{CompositionContext, ServiceBuilder}; +use crate::directoryservice::DirectoryPutter; /// Asks near first, if not found, asks far. /// If found in there, returns it, and *inserts* it into diff --git a/snix/castore/src/directoryservice/directory_graph.rs b/snix/castore/src/directoryservice/directory_graph.rs index 54f3cb3e9..38a4c5162 100644 --- a/snix/castore/src/directoryservice/directory_graph.rs +++ b/snix/castore/src/directoryservice/directory_graph.rs @@ -1,14 +1,14 @@ use std::collections::HashMap; use petgraph::{ + Direction, Incoming, graph::{DiGraph, NodeIndex}, visit::{Bfs, DfsPostOrder, EdgeRef, IntoNodeIdentifiers, Walker}, - Direction, Incoming, }; use tracing::instrument; use super::order_validator::{LeavesToRootValidator, OrderValidator, RootToLeavesValidator}; -use crate::{path::PathComponent, B3Digest, Directory, Node}; +use crate::{B3Digest, Directory, Node, path::PathComponent}; #[derive(thiserror::Error, Debug)] pub enum Error { diff --git a/snix/castore/src/directoryservice/from_addr.rs b/snix/castore/src/directoryservice/from_addr.rs index d236f66bc..441da56af 100644 --- a/snix/castore/src/directoryservice/from_addr.rs +++ b/snix/castore/src/directoryservice/from_addr.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use url::Url; use crate::composition::{ - with_registry, CompositionContext, DeserializeWithRegistry, ServiceBuilder, REG, + CompositionContext, DeserializeWithRegistry, REG, ServiceBuilder, with_registry, }; use super::DirectoryService; diff --git a/snix/castore/src/directoryservice/grpc.rs b/snix/castore/src/directoryservice/grpc.rs index f42cceffd..700aea6fc 100644 --- a/snix/castore/src/directoryservice/grpc.rs +++ b/snix/castore/src/directoryservice/grpc.rs @@ -11,8 +11,8 @@ use tokio::spawn; use tokio::sync::mpsc::UnboundedSender; use tokio::task::JoinHandle; use tokio_stream::wrappers::UnboundedReceiverStream; -use tonic::{async_trait, Code, Status}; -use tracing::{instrument, warn, Instrument as _}; +use tonic::{Code, Status, async_trait}; +use tracing::{Instrument as _, instrument, warn}; /// Connects to a (remote) snix-store DirectoryService over gRPC. #[derive(Clone)] @@ -320,13 +320,13 @@ mod tests { use std::time::Duration; use tempfile::TempDir; use tokio::net::UnixListener; - use tokio_retry::{strategy::ExponentialBackoff, Retry}; + use tokio_retry::{Retry, strategy::ExponentialBackoff}; use tokio_stream::wrappers::UnixListenerStream; use crate::{ directoryservice::{DirectoryService, GRPCDirectoryService, MemoryDirectoryService}, fixtures, - proto::{directory_service_client::DirectoryServiceClient, GRPCDirectoryServiceWrapper}, + proto::{GRPCDirectoryServiceWrapper, directory_service_client::DirectoryServiceClient}, }; /// This ensures connecting via gRPC works as expected. @@ -383,10 +383,12 @@ mod tests { GRPCDirectoryService::from_client("test-instance".into(), client) }; - assert!(grpc_client - .get(&fixtures::DIRECTORY_A.digest()) - .await - .expect("must not fail") - .is_none()) + assert!( + grpc_client + .get(&fixtures::DIRECTORY_A.digest()) + .await + .expect("must not fail") + .is_none() + ) } } diff --git a/snix/castore/src/directoryservice/object_store.rs b/snix/castore/src/directoryservice/object_store.rs index 979b85eca..da59eea49 100644 --- a/snix/castore/src/directoryservice/object_store.rs +++ b/snix/castore/src/directoryservice/object_store.rs @@ -1,20 +1,20 @@ -use std::collections::hash_map; use std::collections::HashMap; +use std::collections::hash_map; use std::sync::Arc; use data_encoding::HEXLOWER; -use futures::future::Either; -use futures::stream::BoxStream; use futures::SinkExt; use futures::StreamExt; use futures::TryFutureExt; use futures::TryStreamExt; -use object_store::{path::Path, ObjectStore}; +use futures::future::Either; +use futures::stream::BoxStream; +use object_store::{ObjectStore, path::Path}; use prost::Message; use tokio::io::AsyncWriteExt; use tokio_util::codec::LengthDelimitedCodec; use tonic::async_trait; -use tracing::{instrument, trace, warn, Level}; +use tracing::{Level, instrument, trace, warn}; use url::Url; use super::{ @@ -22,7 +22,7 @@ use super::{ RootToLeavesValidator, }; use crate::composition::{CompositionContext, ServiceBuilder}; -use crate::{proto, B3Digest, Error, Node}; +use crate::{B3Digest, Error, Node, proto}; /// Stores directory closures in an object store. /// Notably, this makes use of the option to disallow accessing child directories except when @@ -49,7 +49,7 @@ fn derive_dirs_path(base_path: &Path, digest: &B3Digest) -> Path { #[allow(clippy::identity_op)] const MAX_FRAME_LENGTH: usize = 1 * 1024 * 1024 * 1000; // 1 MiB - // +// impl ObjectStoreDirectoryService { /// Constructs a new [ObjectStoreDirectoryService] from a [Url] supported by /// [object_store]. diff --git a/snix/castore/src/directoryservice/order_validator.rs b/snix/castore/src/directoryservice/order_validator.rs index 973af92e1..df4d0782a 100644 --- a/snix/castore/src/directoryservice/order_validator.rs +++ b/snix/castore/src/directoryservice/order_validator.rs @@ -107,8 +107,8 @@ impl OrderValidator for LeavesToRootValidator { #[cfg(test)] mod tests { use super::{LeavesToRootValidator, RootToLeavesValidator}; - use crate::directoryservice::order_validator::OrderValidator; use crate::directoryservice::Directory; + use crate::directoryservice::order_validator::OrderValidator; use crate::fixtures::{DIRECTORY_A, DIRECTORY_B, DIRECTORY_C}; use rstest::rstest; diff --git a/snix/castore/src/directoryservice/redb.rs b/snix/castore/src/directoryservice/redb.rs index a1df354f5..c59c2c5e1 100644 --- a/snix/castore/src/directoryservice/redb.rs +++ b/snix/castore/src/directoryservice/redb.rs @@ -6,12 +6,13 @@ use tonic::async_trait; use tracing::{instrument, warn}; use super::{ - traverse_directory, Directory, DirectoryGraph, DirectoryPutter, DirectoryService, - LeavesToRootValidator, + Directory, DirectoryGraph, DirectoryPutter, DirectoryService, LeavesToRootValidator, + traverse_directory, }; use crate::{ + B3Digest, Error, composition::{CompositionContext, ServiceBuilder}, - proto, B3Digest, Error, + proto, }; const DIRECTORY_TABLE: TableDefinition<[u8; B3Digest::LENGTH], Vec> = diff --git a/snix/castore/src/directoryservice/tests/utils.rs b/snix/castore/src/directoryservice/tests/utils.rs index f2aefa32b..88731b4b9 100644 --- a/snix/castore/src/directoryservice/tests/utils.rs +++ b/snix/castore/src/directoryservice/tests/utils.rs @@ -1,6 +1,6 @@ use crate::directoryservice::{DirectoryService, GRPCDirectoryService}; -use crate::proto::directory_service_client::DirectoryServiceClient; use crate::proto::GRPCDirectoryServiceWrapper; +use crate::proto::directory_service_client::DirectoryServiceClient; use crate::{ directoryservice::MemoryDirectoryService, proto::directory_service_server::DirectoryServiceServer, diff --git a/snix/castore/src/directoryservice/traverse.rs b/snix/castore/src/directoryservice/traverse.rs index 843461992..960f809ba 100644 --- a/snix/castore/src/directoryservice/traverse.rs +++ b/snix/castore/src/directoryservice/traverse.rs @@ -1,4 +1,4 @@ -use crate::{directoryservice::DirectoryService, Error, Node, Path}; +use crate::{Error, Node, Path, directoryservice::DirectoryService}; use tracing::{instrument, warn}; /// This descends from a (root) node to the given (sub)path, returning the Node @@ -51,9 +51,8 @@ where #[cfg(test)] mod tests { use crate::{ - directoryservice, + Node, PathBuf, directoryservice, fixtures::{DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP, EMPTY_BLOB_DIGEST}, - Node, PathBuf, }; use super::descend_to; diff --git a/snix/castore/src/errors.rs b/snix/castore/src/errors.rs index 912bf22c3..cb0b3966d 100644 --- a/snix/castore/src/errors.rs +++ b/snix/castore/src/errors.rs @@ -4,8 +4,8 @@ use tokio::task::JoinError; use tonic::Status; use crate::{ - path::{PathComponent, PathComponentError}, SymlinkTargetError, + path::{PathComponent, PathComponentError}, }; /// Errors related to communication with the store. diff --git a/snix/castore/src/fs/fuse/tests.rs b/snix/castore/src/fs/fuse/tests.rs index 8e960c47d..5b91b1be5 100644 --- a/snix/castore/src/fs/fuse/tests.rs +++ b/snix/castore/src/fs/fuse/tests.rs @@ -8,17 +8,18 @@ use std::{ sync::Arc, }; use tempfile::TempDir; -use tokio_stream::{wrappers::ReadDirStream, StreamExt}; +use tokio_stream::{StreamExt, wrappers::ReadDirStream}; use super::FuseDaemon; use crate::{ + Node, blobservice::{BlobService, MemoryBlobService}, directoryservice::{DirectoryService, MemoryDirectoryService}, - fixtures, Node, + fixtures, }; use crate::{ - fs::{SnixStoreFs, XATTR_NAME_BLOB_DIGEST, XATTR_NAME_DIRECTORY_DIGEST}, PathComponent, + fs::{SnixStoreFs, XATTR_NAME_BLOB_DIGEST, XATTR_NAME_DIRECTORY_DIGEST}, }; const BLOB_A_NAME: &str = "00000000000000000000000000000000-test"; diff --git a/snix/castore/src/fs/inodes.rs b/snix/castore/src/fs/inodes.rs index 71d4d1bd6..8775c77c9 100644 --- a/snix/castore/src/fs/inodes.rs +++ b/snix/castore/src/fs/inodes.rs @@ -2,7 +2,7 @@ //! about inodes, which present snix-castore nodes in a filesystem. use std::time::Duration; -use crate::{path::PathComponent, B3Digest, Node}; +use crate::{B3Digest, Node, path::PathComponent}; #[derive(Clone, Debug)] pub enum InodeData { diff --git a/snix/castore/src/fs/mod.rs b/snix/castore/src/fs/mod.rs index 081164b1a..92925e15e 100644 --- a/snix/castore/src/fs/mod.rs +++ b/snix/castore/src/fs/mod.rs @@ -16,13 +16,13 @@ use self::{ inodes::{DirectoryInodeData, InodeData}, }; use crate::{ + B3Digest, Node, blobservice::{BlobReader, BlobService}, directoryservice::DirectoryService, path::PathComponent, - B3Digest, Node, }; use bstr::ByteVec; -use fuse_backend_rs::abi::fuse_abi::{stat64, OpenOptions}; +use fuse_backend_rs::abi::fuse_abi::{OpenOptions, stat64}; use fuse_backend_rs::api::filesystem::{ Context, FileSystem, FsOptions, GetxattrReply, ListxattrReply, ROOT_ID, }; @@ -33,7 +33,7 @@ use std::{ collections::HashMap, io, sync::atomic::AtomicU64, - sync::{atomic::Ordering, Arc}, + sync::{Arc, atomic::Ordering}, time::Duration, }; use std::{ffi::CStr, io::Cursor}; @@ -41,7 +41,7 @@ use tokio::{ io::{AsyncReadExt, AsyncSeekExt}, sync::mpsc, }; -use tracing::{debug, error, instrument, warn, Instrument as _, Span}; +use tracing::{Instrument as _, Span, debug, error, instrument, warn}; /// This implements a read-only FUSE filesystem for a snix-store /// with the passed [BlobService], [DirectoryService] and [RootNodes]. diff --git a/snix/castore/src/fs/root_nodes.rs b/snix/castore/src/fs/root_nodes.rs index 016c73c40..aef66893d 100644 --- a/snix/castore/src/fs/root_nodes.rs +++ b/snix/castore/src/fs/root_nodes.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use crate::nodes::Directory; -use crate::{path::PathComponent, Error, Node}; +use crate::{Error, Node, path::PathComponent}; use futures::stream::BoxStream; use tonic::async_trait; diff --git a/snix/castore/src/import/archive.rs b/snix/castore/src/import/archive.rs index 4e8d2bada..299a370e4 100644 --- a/snix/castore/src/import/archive.rs +++ b/snix/castore/src/import/archive.rs @@ -2,18 +2,18 @@ use std::collections::HashMap; +use petgraph::Direction; use petgraph::graph::{DiGraph, NodeIndex}; use petgraph::visit::{DfsPostOrder, EdgeRef}; -use petgraph::Direction; use tokio::io::AsyncRead; use tokio_stream::StreamExt; use tokio_tar::Archive; -use tracing::{instrument, warn, Level}; +use tracing::{Level, instrument, warn}; +use crate::Node; use crate::blobservice::BlobService; use crate::directoryservice::DirectoryService; -use crate::import::{ingest_entries, IngestionEntry, IngestionError}; -use crate::Node; +use crate::import::{IngestionEntry, IngestionError, ingest_entries}; use super::blobs::{self, ConcurrentBlobUploader}; @@ -295,8 +295,8 @@ mod test { use std::sync::LazyLock; use super::{Error, IngestionEntryGraph}; - use crate::import::IngestionEntry; use crate::B3Digest; + use crate::import::IngestionEntry; use rstest::rstest; diff --git a/snix/castore/src/import/blobs.rs b/snix/castore/src/import/blobs.rs index e62b2bc80..fda594258 100644 --- a/snix/castore/src/import/blobs.rs +++ b/snix/castore/src/import/blobs.rs @@ -9,9 +9,9 @@ use tokio::{ task::{JoinError, JoinSet}, }; use tokio_util::io::InspectReader; -use tracing::{info_span, Instrument}; +use tracing::{Instrument, info_span}; -use crate::{blobservice::BlobService, B3Digest, Path, PathBuf}; +use crate::{B3Digest, Path, PathBuf, blobservice::BlobService}; /// Files smaller than this threshold, in bytes, are uploaded to the [BlobService] in the /// background. diff --git a/snix/castore/src/import/fs.rs b/snix/castore/src/import/fs.rs index 06bde98de..f7b379203 100644 --- a/snix/castore/src/import/fs.rs +++ b/snix/castore/src/import/fs.rs @@ -1,17 +1,17 @@ //! Import from a real filesystem. -use futures::stream::BoxStream; use futures::StreamExt; +use futures::stream::BoxStream; use std::fs::FileType; use std::os::unix::ffi::OsStringExt; use std::os::unix::fs::MetadataExt; use std::os::unix::fs::PermissionsExt; use tokio::io::BufReader; use tokio_util::io::InspectReader; -use tracing::info_span; -use tracing::instrument; use tracing::Instrument; use tracing::Span; +use tracing::info_span; +use tracing::instrument; use tracing_indicatif::span_ext::IndicatifSpanExt; use walkdir::DirEntry; use walkdir::WalkDir; @@ -21,9 +21,9 @@ use crate::directoryservice::DirectoryService; use crate::refscan::{ReferenceReader, ReferenceScanner}; use crate::{B3Digest, Node}; -use super::ingest_entries; use super::IngestionEntry; use super::IngestionError; +use super::ingest_entries; /// Ingests the contents at a given path into the snix store, interacting with a [BlobService] and /// [DirectoryService]. It returns the root node or an error. diff --git a/snix/castore/src/import/mod.rs b/snix/castore/src/import/mod.rs index dac422c11..438b12fc6 100644 --- a/snix/castore/src/import/mod.rs +++ b/snix/castore/src/import/mod.rs @@ -211,11 +211,11 @@ mod test { use rstest::rstest; use crate::fixtures::{DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP, EMPTY_BLOB_DIGEST}; - use crate::{directoryservice::MemoryDirectoryService, fixtures::DUMMY_DIGEST}; use crate::{Directory, Node}; + use crate::{directoryservice::MemoryDirectoryService, fixtures::DUMMY_DIGEST}; - use super::ingest_entries; use super::IngestionEntry; + use super::ingest_entries; #[rstest] #[case::single_file(vec![IngestionEntry::Regular { diff --git a/snix/castore/src/nodes/directory.rs b/snix/castore/src/nodes/directory.rs index a9e8b36bd..845f292e8 100644 --- a/snix/castore/src/nodes/directory.rs +++ b/snix/castore/src/nodes/directory.rs @@ -1,6 +1,6 @@ use std::collections::btree_map::{self, BTreeMap}; -use crate::{errors::DirectoryError, path::PathComponent, proto, B3Digest, Node}; +use crate::{B3Digest, Node, errors::DirectoryError, path::PathComponent, proto}; /// A Directory contains nodes, which can be Directory, File or Symlink nodes. /// It attaches names to these nodes, which is the basename in that directory. diff --git a/snix/castore/src/path/component.rs b/snix/castore/src/path/component.rs index 7ed8409cd..a4d2b2ebe 100644 --- a/snix/castore/src/path/component.rs +++ b/snix/castore/src/path/component.rs @@ -152,7 +152,7 @@ mod tests { use bytes::Bytes; use rstest::rstest; - use super::{validate_name, PathComponent, PathComponentError}; + use super::{PathComponent, PathComponentError, validate_name}; #[rstest] #[case::empty(b"", PathComponentError::Empty)] diff --git a/snix/castore/src/proto/grpc_blobservice_wrapper.rs b/snix/castore/src/proto/grpc_blobservice_wrapper.rs index 46a5da5f0..53dc9dbb1 100644 --- a/snix/castore/src/proto/grpc_blobservice_wrapper.rs +++ b/snix/castore/src/proto/grpc_blobservice_wrapper.rs @@ -1,14 +1,14 @@ -use crate::{blobservice::BlobService, B3Digest}; +use crate::{B3Digest, blobservice::BlobService}; use core::pin::pin; -use futures::{stream::BoxStream, TryFutureExt}; +use futures::{TryFutureExt, stream::BoxStream}; use std::{ collections::VecDeque, ops::{Deref, DerefMut}, }; use tokio_stream::StreamExt; use tokio_util::io::ReaderStream; -use tonic::{async_trait, Request, Response, Status, Streaming}; -use tracing::{instrument, warn, Span}; +use tonic::{Request, Response, Status, Streaming, async_trait}; +use tracing::{Span, instrument, warn}; pub struct GRPCBlobServiceWrapper { blob_service: T, diff --git a/snix/castore/src/proto/grpc_directoryservice_wrapper.rs b/snix/castore/src/proto/grpc_directoryservice_wrapper.rs index c386d9324..f7df6ed66 100644 --- a/snix/castore/src/proto/grpc_directoryservice_wrapper.rs +++ b/snix/castore/src/proto/grpc_directoryservice_wrapper.rs @@ -1,10 +1,10 @@ use crate::directoryservice::{DirectoryGraph, DirectoryService, LeavesToRootValidator}; -use crate::{proto, B3Digest, DirectoryError}; -use futures::stream::BoxStream; +use crate::{B3Digest, DirectoryError, proto}; use futures::TryStreamExt; +use futures::stream::BoxStream; use std::ops::Deref; use tokio_stream::once; -use tonic::{async_trait, Request, Response, Status, Streaming}; +use tonic::{Request, Response, Status, Streaming, async_trait}; use tracing::{instrument, warn}; pub struct GRPCDirectoryServiceWrapper { diff --git a/snix/castore/src/proto/mod.rs b/snix/castore/src/proto/mod.rs index bc9c4501f..36cce97aa 100644 --- a/snix/castore/src/proto/mod.rs +++ b/snix/castore/src/proto/mod.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; mod grpc_blobservice_wrapper; mod grpc_directoryservice_wrapper; -use crate::{path::PathComponent, B3Digest, DirectoryError}; +use crate::{B3Digest, DirectoryError, path::PathComponent}; pub use grpc_blobservice_wrapper::GRPCBlobServiceWrapper; pub use grpc_directoryservice_wrapper::GRPCDirectoryServiceWrapper; diff --git a/snix/castore/src/proto/tests/directory.rs b/snix/castore/src/proto/tests/directory.rs index 8eb5c92a8..e9388a7a2 100644 --- a/snix/castore/src/proto/tests/directory.rs +++ b/snix/castore/src/proto/tests/directory.rs @@ -1,5 +1,5 @@ -use crate::proto::{Directory, DirectoryEntry, DirectoryError, FileEntry, SymlinkEntry}; use crate::ValidateNodeError; +use crate::proto::{Directory, DirectoryEntry, DirectoryError, FileEntry, SymlinkEntry}; use hex_literal::hex; diff --git a/snix/castore/src/proto/tests/mod.rs b/snix/castore/src/proto/tests/mod.rs index 12cdc533d..27e8c5723 100644 --- a/snix/castore/src/proto/tests/mod.rs +++ b/snix/castore/src/proto/tests/mod.rs @@ -1,4 +1,4 @@ -use super::{entry, Entry, SymlinkEntry}; +use super::{Entry, SymlinkEntry, entry}; use crate::DirectoryError; mod directory; diff --git a/snix/castore/src/refscan.rs b/snix/castore/src/refscan.rs index c6bd9e7f2..3521784bd 100644 --- a/snix/castore/src/refscan.rs +++ b/snix/castore/src/refscan.rs @@ -9,9 +9,9 @@ use pin_project::pin_project; use std::collections::BTreeSet; use std::pin::Pin; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use std::task::{ready, Poll}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::task::{Poll, ready}; use tokio::io::{AsyncBufRead, AsyncRead, ReadBuf}; use wu_manber::TwoByteWM; diff --git a/snix/castore/src/tests/import.rs b/snix/castore/src/tests/import.rs index 51d1b68a4..01c2f84f6 100644 --- a/snix/castore/src/tests/import.rs +++ b/snix/castore/src/tests/import.rs @@ -1,8 +1,8 @@ +use crate::Node; use crate::blobservice::{self, BlobService}; use crate::directoryservice; use crate::fixtures::*; use crate::import::fs::ingest_path; -use crate::Node; use tempfile::TempDir; @@ -105,16 +105,20 @@ async fn complicated() { ); // ensure DIRECTORY_WITH_KEEP and DIRECTORY_COMPLICATED have been uploaded - assert!(directory_service - .get(&DIRECTORY_WITH_KEEP.digest()) - .await - .unwrap() - .is_some()); - assert!(directory_service - .get(&DIRECTORY_COMPLICATED.digest()) - .await - .unwrap() - .is_some()); + assert!( + directory_service + .get(&DIRECTORY_WITH_KEEP.digest()) + .await + .unwrap() + .is_some() + ); + assert!( + directory_service + .get(&DIRECTORY_COMPLICATED.digest()) + .await + .unwrap() + .is_some() + ); // ensure EMPTY_BLOB_CONTENTS has been uploaded assert!(blob_service.has(&EMPTY_BLOB_DIGEST).await.unwrap()); diff --git a/snix/castore/src/utils.rs b/snix/castore/src/utils.rs index 66aca433b..6e6585492 100644 --- a/snix/castore/src/utils.rs +++ b/snix/castore/src/utils.rs @@ -4,7 +4,7 @@ use url::Url; use crate::blobservice::BlobService; use crate::composition::{ - with_registry, Composition, DeserializeWithRegistry, ServiceBuilder, REG, + Composition, DeserializeWithRegistry, REG, ServiceBuilder, with_registry, }; use crate::directoryservice::DirectoryService; diff --git a/snix/store/rustfmt.toml b/snix/store/rustfmt.toml new file mode 100644 index 000000000..4dfc1d2b7 --- /dev/null +++ b/snix/store/rustfmt.toml @@ -0,0 +1,2 @@ +# FUTUREWORK: move to .. once all crates are migrated (#114) +edition = "2024" diff --git a/snix/store/src/bin/snix-store.rs b/snix/store/src/bin/snix-store.rs index 34ce66cd7..88c99735b 100644 --- a/snix/store/src/bin/snix-store.rs +++ b/snix/store/src/bin/snix-store.rs @@ -20,16 +20,16 @@ use tonic::transport::Server; use tower::ServiceBuilder; use tower_http::classify::{GrpcCode, GrpcErrorsAsFailures, SharedClassifier}; use tower_http::trace::{DefaultMakeSpan, TraceLayer}; -use tracing::{debug, info, info_span, instrument, warn, Instrument, Level, Span}; +use tracing::{Instrument, Level, Span, debug, info, info_span, instrument, warn}; use tracing_indicatif::span_ext::IndicatifSpanExt; -use snix_castore::proto::blob_service_server::BlobServiceServer; -use snix_castore::proto::directory_service_server::DirectoryServiceServer; use snix_castore::proto::GRPCBlobServiceWrapper; use snix_castore::proto::GRPCDirectoryServiceWrapper; +use snix_castore::proto::blob_service_server::BlobServiceServer; +use snix_castore::proto::directory_service_server::DirectoryServiceServer; use snix_store::pathinfoservice::{PathInfo, PathInfoService}; -use snix_store::proto::path_info_service_server::PathInfoServiceServer; use snix_store::proto::GRPCPathInfoServiceWrapper; +use snix_store::proto::path_info_service_server::PathInfoServiceServer; #[cfg(any(feature = "fuse", feature = "virtiofs"))] use snix_store::pathinfoservice::make_fs; diff --git a/snix/store/src/fixtures.rs b/snix/store/src/fixtures.rs index 983621ad5..0762c42c1 100644 --- a/snix/store/src/fixtures.rs +++ b/snix/store/src/fixtures.rs @@ -2,10 +2,10 @@ use crate::pathinfoservice::PathInfo; use md5::Digest; use nix_compat::nixhash::{CAHash, NixHash}; use nix_compat::store_path::StorePath; +use snix_castore::Node; use snix_castore::fixtures::{ DIRECTORY_COMPLICATED, DUMMY_DIGEST, HELLOWORLD_BLOB_CONTENTS, HELLOWORLD_BLOB_DIGEST, }; -use snix_castore::Node; use std::sync::LazyLock; pub const DUMMY_PATH_STR: &str = "00000000000000000000000000000000-dummy"; diff --git a/snix/store/src/import.rs b/snix/store/src/import.rs index 9cca30141..f553af2d7 100644 --- a/snix/store/src/import.rs +++ b/snix/store/src/import.rs @@ -1,6 +1,6 @@ use bstr::ByteSlice; use snix_castore::{ - blobservice::BlobService, directoryservice::DirectoryService, import::fs::ingest_path, Node, + Node, blobservice::BlobService, directoryservice::DirectoryService, import::fs::ingest_path, }; use std::path::Path; use tracing::{debug, instrument}; diff --git a/snix/store/src/nar/hashing_reader.rs b/snix/store/src/nar/hashing_reader.rs index a049439a5..4cf4fec62 100644 --- a/snix/store/src/nar/hashing_reader.rs +++ b/snix/store/src/nar/hashing_reader.rs @@ -1,10 +1,10 @@ use std::{ io::Result, pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; -use md5::{digest::DynDigest, Digest}; +use md5::{Digest, digest::DynDigest}; use nix_compat::nixhash::{HashAlgo, NixHash}; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, ReadBuf}; diff --git a/snix/store/src/nar/import.rs b/snix/store/src/nar/import.rs index 4ff9ca21f..1db946265 100644 --- a/snix/store/src/nar/import.rs +++ b/snix/store/src/nar/import.rs @@ -4,13 +4,14 @@ use nix_compat::{ }; use sha2::Digest; use snix_castore::{ + Node, PathBuf, blobservice::BlobService, directoryservice::DirectoryService, import::{ + IngestionEntry, IngestionError, blobs::{self, ConcurrentBlobUploader}, - ingest_entries, IngestionEntry, IngestionError, + ingest_entries, }, - Node, PathBuf, }; use tokio::{ io::{AsyncBufRead, AsyncRead}, @@ -232,7 +233,7 @@ mod test { use crate::fixtures::{ NAR_CONTENTS_COMPLICATED, NAR_CONTENTS_HELLOWORLD, NAR_CONTENTS_SYMLINK, }; - use crate::nar::{ingest_nar, ingest_nar_and_hash, NarIngestionError}; + use crate::nar::{NarIngestionError, ingest_nar, ingest_nar_and_hash}; use std::io::Cursor; use std::sync::Arc; diff --git a/snix/store/src/nar/mod.rs b/snix/store/src/nar/mod.rs index f22b7b26c..c90120369 100644 --- a/snix/store/src/nar/mod.rs +++ b/snix/store/src/nar/mod.rs @@ -5,10 +5,10 @@ mod hashing_reader; mod import; mod renderer; pub mod seekable; -pub use import::{ingest_nar, ingest_nar_and_hash, NarIngestionError}; +pub use import::{NarIngestionError, ingest_nar, ingest_nar_and_hash}; +pub use renderer::SimpleRenderer; pub use renderer::calculate_size_and_sha256; pub use renderer::write_nar; -pub use renderer::SimpleRenderer; use snix_castore::Node; #[async_trait] @@ -16,7 +16,7 @@ pub trait NarCalculationService: Send + Sync { /// Return the nar size and nar sha256 digest for a given root node. /// This can be used to calculate NAR-based output paths. async fn calculate_nar(&self, root_node: &Node) - -> Result<(u64, [u8; 32]), snix_castore::Error>; + -> Result<(u64, [u8; 32]), snix_castore::Error>; } #[async_trait] @@ -44,7 +44,9 @@ pub enum RenderError { #[error("unable to find blob {0}, referred from {1:?}")] BlobNotFound(B3Digest, bytes::Bytes), - #[error("unexpected size in metadata for blob {0}, referred from {1:?} returned, expected {2}, got {3}")] + #[error( + "unexpected size in metadata for blob {0}, referred from {1:?} returned, expected {2}, got {3}" + )] UnexpectedBlobMeta(B3Digest, bytes::Bytes, u32, u32), #[error("failure using the NAR writer: {0}")] diff --git a/snix/store/src/nar/renderer.rs b/snix/store/src/nar/renderer.rs index fdaa20726..c2ffea459 100644 --- a/snix/store/src/nar/renderer.rs +++ b/snix/store/src/nar/renderer.rs @@ -4,7 +4,7 @@ use super::{NarCalculationService, RenderError}; use count_write::CountWrite; use nix_compat::nar::writer::r#async as nar_writer; use sha2::{Digest, Sha256}; -use snix_castore::{blobservice::BlobService, directoryservice::DirectoryService, Node}; +use snix_castore::{Node, blobservice::BlobService, directoryservice::DirectoryService}; use tokio::io::{self, AsyncWrite, BufReader}; use tonic::async_trait; use tracing::instrument; diff --git a/snix/store/src/nar/seekable.rs b/snix/store/src/nar/seekable.rs index 7124093e7..b4453bddb 100644 --- a/snix/store/src/nar/seekable.rs +++ b/snix/store/src/nar/seekable.rs @@ -11,16 +11,16 @@ use super::RenderError; use bytes::{BufMut, Bytes}; use nix_compat::nar::writer::sync as nar_writer; +use snix_castore::Directory; use snix_castore::blobservice::{BlobReader, BlobService}; use snix_castore::directoryservice::{ DirectoryGraph, DirectoryService, RootToLeavesValidator, ValidatedDirectoryGraph, }; -use snix_castore::Directory; use snix_castore::{B3Digest, Node}; -use futures::future::{BoxFuture, FusedFuture, TryMaybeDone}; use futures::FutureExt; use futures::TryStreamExt; +use futures::future::{BoxFuture, FusedFuture, TryMaybeDone}; use tokio::io::AsyncSeekExt; @@ -364,7 +364,7 @@ impl tokio::io::AsyncRead for Reader { return Poll::Ready(Err(io::Error::new( io::ErrorKind::UnexpectedEof, "blob short read", - ))) + ))); } (false, true) => { buf.set_filled(prev_read_buf_pos); diff --git a/snix/store/src/pathinfoservice/bigtable.rs b/snix/store/src/pathinfoservice/bigtable.rs index 0ef3c2fc4..5442adccf 100644 --- a/snix/store/src/pathinfoservice/bigtable.rs +++ b/snix/store/src/pathinfoservice/bigtable.rs @@ -8,12 +8,12 @@ use futures::stream::BoxStream; use nix_compat::nixbase32; use prost::Message; use serde::{Deserialize, Serialize}; -use serde_with::{serde_as, DurationSeconds}; -use snix_castore::composition::{CompositionContext, ServiceBuilder}; +use serde_with::{DurationSeconds, serde_as}; use snix_castore::Error; +use snix_castore::composition::{CompositionContext, ServiceBuilder}; use std::sync::Arc; use tonic::async_trait; -use tracing::{instrument, trace, warn, Span}; +use tracing::{Span, instrument, trace, warn}; /// There should not be more than 10 MiB in a single cell. /// @@ -77,7 +77,7 @@ impl BigtablePathInfoService { use async_process::{Command, Stdio}; use tempfile::TempDir; - use tokio_retry::{strategy::ExponentialBackoff, Retry}; + use tokio_retry::{Retry, strategy::ExponentialBackoff}; let tmpdir = TempDir::new().unwrap(); diff --git a/snix/store/src/pathinfoservice/cache.rs b/snix/store/src/pathinfoservice/cache.rs index d361d3904..ffcf05492 100644 --- a/snix/store/src/pathinfoservice/cache.rs +++ b/snix/store/src/pathinfoservice/cache.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use futures::stream::BoxStream; use nix_compat::nixbase32; -use snix_castore::composition::{CompositionContext, ServiceBuilder}; use snix_castore::Error; +use snix_castore::composition::{CompositionContext, ServiceBuilder}; use tonic::async_trait; use tracing::{debug, instrument}; @@ -132,11 +132,12 @@ mod test { let svc = create_pathinfoservice().await; // query the PathInfo, things should not be there. - assert!(svc - .get(*PATH_INFO.store_path.digest()) - .await - .unwrap() - .is_none()); + assert!( + svc.get(*PATH_INFO.store_path.digest()) + .await + .unwrap() + .is_none() + ); // insert it into the far one. svc.far.put(PATH_INFO.clone()).await.unwrap(); diff --git a/snix/store/src/pathinfoservice/from_addr.rs b/snix/store/src/pathinfoservice/from_addr.rs index 7e0c05bc3..98b31ce5c 100644 --- a/snix/store/src/pathinfoservice/from_addr.rs +++ b/snix/store/src/pathinfoservice/from_addr.rs @@ -1,10 +1,10 @@ use super::PathInfoService; use crate::composition::REG; -use snix_castore::composition::{ - with_registry, CompositionContext, DeserializeWithRegistry, ServiceBuilder, -}; use snix_castore::Error; +use snix_castore::composition::{ + CompositionContext, DeserializeWithRegistry, ServiceBuilder, with_registry, +}; use std::sync::Arc; use url::Url; diff --git a/snix/store/src/pathinfoservice/fs/mod.rs b/snix/store/src/pathinfoservice/fs/mod.rs index 6714f4877..9f4d1019b 100644 --- a/snix/store/src/pathinfoservice/fs/mod.rs +++ b/snix/store/src/pathinfoservice/fs/mod.rs @@ -1,9 +1,9 @@ -use futures::stream::BoxStream; use futures::StreamExt; +use futures::stream::BoxStream; use nix_compat::store_path::StorePathRef; use snix_castore::fs::{RootNodes, SnixStoreFs}; -use snix_castore::{blobservice::BlobService, directoryservice::DirectoryService}; use snix_castore::{Error, Node, PathComponent}; +use snix_castore::{blobservice::BlobService, directoryservice::DirectoryService}; use tonic::async_trait; use super::PathInfoService; diff --git a/snix/store/src/pathinfoservice/grpc.rs b/snix/store/src/pathinfoservice/grpc.rs index ede86c7f2..b8d0b5aaa 100644 --- a/snix/store/src/pathinfoservice/grpc.rs +++ b/snix/store/src/pathinfoservice/grpc.rs @@ -6,12 +6,12 @@ use crate::{ use async_stream::try_stream; use futures::stream::BoxStream; use nix_compat::nixbase32; -use snix_castore::composition::{CompositionContext, ServiceBuilder}; use snix_castore::Error; use snix_castore::Node; +use snix_castore::composition::{CompositionContext, ServiceBuilder}; use std::sync::Arc; -use tonic::{async_trait, Code}; -use tracing::{instrument, warn, Span}; +use tonic::{Code, async_trait}; +use tracing::{Span, instrument, warn}; use tracing_indicatif::span_ext::IndicatifSpanExt; /// Connects to a (remote) snix-store PathInfoService over gRPC. @@ -185,8 +185,8 @@ impl ServiceBuilder for GRPCPathInfoServiceConfig { #[cfg(test)] mod tests { - use crate::pathinfoservice::tests::make_grpc_path_info_service_client; use crate::pathinfoservice::PathInfoService; + use crate::pathinfoservice::tests::make_grpc_path_info_service_client; /// This ensures connecting via gRPC works as expected. #[tokio::test] diff --git a/snix/store/src/pathinfoservice/lru.rs b/snix/store/src/pathinfoservice/lru.rs index 6dd8503b5..7a1f71192 100644 --- a/snix/store/src/pathinfoservice/lru.rs +++ b/snix/store/src/pathinfoservice/lru.rs @@ -8,8 +8,8 @@ use tokio::sync::RwLock; use tonic::async_trait; use tracing::instrument; -use snix_castore::composition::{CompositionContext, ServiceBuilder}; use snix_castore::Error; +use snix_castore::composition::{CompositionContext, ServiceBuilder}; use super::{PathInfo, PathInfoService}; @@ -111,11 +111,12 @@ mod test { let svc = LruPathInfoService::with_capacity("test".into(), NonZeroUsize::new(1).unwrap()); // pathinfo_1 should not be there - assert!(svc - .get(*PATH_INFO.store_path.digest()) - .await - .expect("no error") - .is_none()); + assert!( + svc.get(*PATH_INFO.store_path.digest()) + .await + .expect("no error") + .is_none() + ); // insert it svc.put(PATH_INFO.clone()).await.expect("no error"); @@ -138,10 +139,11 @@ mod test { ); // … but pathinfo 1 not anymore. - assert!(svc - .get(*PATH_INFO.store_path.digest()) - .await - .expect("no error") - .is_none()); + assert!( + svc.get(*PATH_INFO.store_path.digest()) + .await + .expect("no error") + .is_none() + ); } } diff --git a/snix/store/src/pathinfoservice/memory.rs b/snix/store/src/pathinfoservice/memory.rs index 11e2cf91f..1875d4d97 100644 --- a/snix/store/src/pathinfoservice/memory.rs +++ b/snix/store/src/pathinfoservice/memory.rs @@ -2,8 +2,8 @@ use super::{PathInfo, PathInfoService}; use async_stream::try_stream; use futures::stream::BoxStream; use nix_compat::nixbase32; -use snix_castore::composition::{CompositionContext, ServiceBuilder}; use snix_castore::Error; +use snix_castore::composition::{CompositionContext, ServiceBuilder}; use std::{collections::HashMap, sync::Arc}; use tokio::sync::RwLock; use tonic::async_trait; diff --git a/snix/store/src/pathinfoservice/mod.rs b/snix/store/src/pathinfoservice/mod.rs index d3eb935dc..0c531e26a 100644 --- a/snix/store/src/pathinfoservice/mod.rs +++ b/snix/store/src/pathinfoservice/mod.rs @@ -15,8 +15,8 @@ mod tests; use auto_impl::auto_impl; use futures::stream::BoxStream; -use snix_castore::composition::{Registry, ServiceBuilder}; use snix_castore::Error; +use snix_castore::composition::{Registry, ServiceBuilder}; use tonic::async_trait; use crate::nar::NarCalculationService; diff --git a/snix/store/src/pathinfoservice/nix_http.rs b/snix/store/src/pathinfoservice/nix_http.rs index 4a66359b5..f8cf71ce1 100644 --- a/snix/store/src/pathinfoservice/nix_http.rs +++ b/snix/store/src/pathinfoservice/nix_http.rs @@ -1,6 +1,6 @@ use super::{PathInfo, PathInfoService}; use crate::nar::ingest_nar_and_hash; -use futures::{stream::BoxStream, TryStreamExt}; +use futures::{TryStreamExt, stream::BoxStream}; use nix_compat::{ narinfo::{self, NarInfo, Signature}, nixbase32, @@ -9,7 +9,7 @@ use nix_compat::{ }; use reqwest::StatusCode; use snix_castore::composition::{CompositionContext, ServiceBuilder}; -use snix_castore::{blobservice::BlobService, directoryservice::DirectoryService, Error}; +use snix_castore::{Error, blobservice::BlobService, directoryservice::DirectoryService}; use std::sync::Arc; use tokio::io::{self, AsyncRead}; use tonic::async_trait; diff --git a/snix/store/src/pathinfoservice/redb.rs b/snix/store/src/pathinfoservice/redb.rs index 0f983a3bf..a83cce302 100644 --- a/snix/store/src/pathinfoservice/redb.rs +++ b/snix/store/src/pathinfoservice/redb.rs @@ -1,12 +1,12 @@ use super::{PathInfo, PathInfoService}; use crate::proto; use data_encoding::BASE64; -use futures::{stream::BoxStream, StreamExt}; +use futures::{StreamExt, stream::BoxStream}; use prost::Message; use redb::{Database, ReadableTable, TableDefinition}; use snix_castore::{ - composition::{CompositionContext, ServiceBuilder}, Error, + composition::{CompositionContext, ServiceBuilder}, }; use std::{path::PathBuf, sync::Arc}; use tokio_stream::wrappers::ReceiverStream; diff --git a/snix/store/src/pathinfoservice/signing_wrapper.rs b/snix/store/src/pathinfoservice/signing_wrapper.rs index 44c595e50..3d02d1e12 100644 --- a/snix/store/src/pathinfoservice/signing_wrapper.rs +++ b/snix/store/src/pathinfoservice/signing_wrapper.rs @@ -10,7 +10,7 @@ use snix_castore::composition::{CompositionContext, ServiceBuilder}; use snix_castore::Error; -use nix_compat::narinfo::{parse_keypair, Signature, SigningKey}; +use nix_compat::narinfo::{Signature, SigningKey, parse_keypair}; use nix_compat::nixbase32; use tracing::instrument; @@ -158,11 +158,12 @@ mod test { ); // Asking PathInfoService, it should not be there ... - assert!(svc - .get(*PATH_INFO.store_path.digest()) - .await - .expect("no error") - .is_none()); + assert!( + svc.get(*PATH_INFO.store_path.digest()) + .await + .expect("no error") + .is_none() + ); // insert it svc.put(PATH_INFO.clone()).await.expect("no error"); diff --git a/snix/store/src/pathinfoservice/tests/mod.rs b/snix/store/src/pathinfoservice/tests/mod.rs index d47d34d1d..3afdf3ac0 100644 --- a/snix/store/src/pathinfoservice/tests/mod.rs +++ b/snix/store/src/pathinfoservice/tests/mod.rs @@ -8,9 +8,9 @@ use rstest_reuse::{self, *}; use super::{PathInfo, PathInfoService}; use crate::fixtures::{DUMMY_PATH_DIGEST, PATH_INFO}; +use crate::pathinfoservice::MemoryPathInfoService; use crate::pathinfoservice::redb::RedbPathInfoService; use crate::pathinfoservice::test_signing_service; -use crate::pathinfoservice::MemoryPathInfoService; mod utils; pub use self::utils::make_grpc_path_info_service_client; @@ -38,11 +38,12 @@ pub fn path_info_services(#[case] svc: impl PathInfoService) {} #[apply(path_info_services)] #[tokio::test] async fn not_found(svc: impl PathInfoService) { - assert!(svc - .get(DUMMY_PATH_DIGEST) - .await - .expect("must succeed") - .is_none()); + assert!( + svc.get(DUMMY_PATH_DIGEST) + .await + .expect("must succeed") + .is_none() + ); } /// Put a PathInfo into the store, get it back. diff --git a/snix/store/src/pathinfoservice/tests/utils.rs b/snix/store/src/pathinfoservice/tests/utils.rs index f39237807..495348e7e 100644 --- a/snix/store/src/pathinfoservice/tests/utils.rs +++ b/snix/store/src/pathinfoservice/tests/utils.rs @@ -8,8 +8,8 @@ use crate::{ nar::{NarCalculationService, SimpleRenderer}, pathinfoservice::{GRPCPathInfoService, MemoryPathInfoService, PathInfoService}, proto::{ - path_info_service_client::PathInfoServiceClient, - path_info_service_server::PathInfoServiceServer, GRPCPathInfoServiceWrapper, + GRPCPathInfoServiceWrapper, path_info_service_client::PathInfoServiceClient, + path_info_service_server::PathInfoServiceServer, }, tests::fixtures::{blob_service, directory_service}, }; @@ -71,10 +71,10 @@ pub async fn make_grpc_path_info_service_client() -> ( } #[cfg(all(feature = "cloud", feature = "integration"))] -pub(crate) async fn make_bigtable_path_info_service( -) -> crate::pathinfoservice::BigtablePathInfoService { - use crate::pathinfoservice::bigtable::BigtableParameters; +pub(crate) async fn make_bigtable_path_info_service() +-> crate::pathinfoservice::BigtablePathInfoService { use crate::pathinfoservice::BigtablePathInfoService; + use crate::pathinfoservice::bigtable::BigtableParameters; BigtablePathInfoService::connect("test".into(), BigtableParameters::default_for_tests()) .await diff --git a/snix/store/src/proto/grpc_pathinfoservice_wrapper.rs b/snix/store/src/proto/grpc_pathinfoservice_wrapper.rs index d94049db7..7e2c38e13 100644 --- a/snix/store/src/proto/grpc_pathinfoservice_wrapper.rs +++ b/snix/store/src/proto/grpc_pathinfoservice_wrapper.rs @@ -1,10 +1,10 @@ use crate::nar::{NarCalculationService, RenderError}; use crate::pathinfoservice::{PathInfo, PathInfoService}; use crate::proto; -use futures::{stream::BoxStream, TryStreamExt}; +use futures::{TryStreamExt, stream::BoxStream}; use snix_castore::proto as castorepb; use std::ops::Deref; -use tonic::{async_trait, Request, Response, Result, Status}; +use tonic::{Request, Response, Result, Status, async_trait}; use tracing::{instrument, warn}; pub struct GRPCPathInfoServiceWrapper { diff --git a/snix/store/src/tests/nar_renderer.rs b/snix/store/src/tests/nar_renderer.rs index 4ce54c84c..bb4e088ed 100644 --- a/snix/store/src/tests/nar_renderer.rs +++ b/snix/store/src/tests/nar_renderer.rs @@ -3,9 +3,9 @@ use crate::nar::write_nar; use crate::tests::fixtures::*; use rstest::*; use rstest_reuse::*; +use snix_castore::Node; use snix_castore::blobservice::BlobService; use snix_castore::directoryservice::DirectoryService; -use snix_castore::Node; use std::io; use std::sync::Arc; use tokio::io::sink; diff --git a/snix/store/src/tests/nar_renderer_seekable.rs b/snix/store/src/tests/nar_renderer_seekable.rs index e67388cfc..989a8e90a 100644 --- a/snix/store/src/tests/nar_renderer_seekable.rs +++ b/snix/store/src/tests/nar_renderer_seekable.rs @@ -4,9 +4,9 @@ use crate::tests::fixtures::directory_service_with_contents as directory_service use crate::tests::fixtures::*; use rstest::*; use rstest_reuse::*; +use snix_castore::Node; use snix_castore::blobservice::BlobService; use snix_castore::directoryservice::DirectoryService; -use snix_castore::Node; use std::io; use std::pin::Pin; use std::sync::Arc; diff --git a/snix/store/src/utils.rs b/snix/store/src/utils.rs index 48d9ccb15..a04b22614 100644 --- a/snix/store/src/utils.rs +++ b/snix/store/src/utils.rs @@ -14,7 +14,7 @@ use crate::composition::REG; use crate::nar::{NarCalculationService, SimpleRenderer}; use crate::pathinfoservice::PathInfoService; use snix_castore::composition::{ - with_registry, Composition, DeserializeWithRegistry, ServiceBuilder, + Composition, DeserializeWithRegistry, ServiceBuilder, with_registry, }; #[derive(serde::Deserialize, Default)]