mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-07-26 07:58:14 +00:00
refactor: rename method to avoid confusion
- rename SqliteDb::new to `_::open` as it's not return Self lint message: methods called `new` usually return `Self` help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#new_ret_no_self - rename method `add` to `add_calgorithm` The semantics of this has nothing to do with an `add` operation in the sense of the `Add` trait. And method `add` can be confused for the standard trait method std::ops::Add::add lint https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#should_implement_trait
This commit is contained in:
@@ -122,7 +122,7 @@ impl Checksummer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add(mut self, algo: Option<ChecksumAlgorithm>) -> Self {
|
||||
pub fn add_algorithm(mut self, algo: Option<ChecksumAlgorithm>) -> Self {
|
||||
match algo {
|
||||
Some(ChecksumAlgorithm::Crc32) => {
|
||||
self.crc32 = Some(new_crc32());
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn parse_streaming_body(
|
||||
request_trailer_checksum_algorithm(req.headers())?
|
||||
.ok_or_bad_request("Missing x-amz-trailer header")?,
|
||||
);
|
||||
checksummer = checksummer.add(algo);
|
||||
checksummer = checksummer.add_algorithm(algo);
|
||||
algo
|
||||
} else {
|
||||
None
|
||||
|
||||
+1
-1
@@ -545,7 +545,7 @@ pub async fn handle_upload_part_copy(
|
||||
|
||||
// Now, actually copy the blocks
|
||||
let mut checksummer = Checksummer::init(&Default::default(), !dest_encryption.is_encrypted())
|
||||
.add(dest_object_checksum_algorithm.map(|(algo, _)| algo));
|
||||
.add_algorithm(dest_object_checksum_algorithm.map(|(algo, _)| algo));
|
||||
|
||||
// First, create a stream that is able to read the source blocks
|
||||
// and extract the subrange if necessary.
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ pub(crate) async fn save_stream<S: Stream<Item = Result<Bytes, Error>> + Unpin>(
|
||||
let mut checksummer = match &checksum_mode {
|
||||
ChecksumMode::Verify(expected) => Checksummer::init(expected, !encryption.is_encrypted()),
|
||||
ChecksumMode::Calculate(algo) => {
|
||||
Checksummer::init(&Default::default(), !encryption.is_encrypted()).add(*algo)
|
||||
Checksummer::init(&Default::default(), !encryption.is_encrypted()).add_algorithm(*algo)
|
||||
}
|
||||
ChecksumMode::VerifyFrom { .. } => {
|
||||
// Checksums are calculated by the garage_api_common::signature module
|
||||
|
||||
@@ -23,7 +23,7 @@ pub use rusqlite;
|
||||
pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
|
||||
info!("Opening Sqlite database at: {}", path.display());
|
||||
let manager = r2d2_sqlite::SqliteConnectionManager::file(path);
|
||||
SqliteDb::new(manager, opt.fsync)
|
||||
SqliteDb::open(manager, opt.fsync)
|
||||
}
|
||||
|
||||
// ----
|
||||
@@ -62,7 +62,7 @@ pub struct SqliteDb {
|
||||
}
|
||||
|
||||
impl SqliteDb {
|
||||
pub fn new(manager: SqliteConnectionManager, sync_mode: bool) -> Result<Db> {
|
||||
pub fn open(manager: SqliteConnectionManager, sync_mode: bool) -> Result<Db> {
|
||||
let manager = manager.with_init(move |db| {
|
||||
db.pragma_update(None, "journal_mode", "WAL")?;
|
||||
if sync_mode {
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ fn test_sqlite_db() {
|
||||
use crate::sqlite_adapter::SqliteDb;
|
||||
|
||||
let manager = r2d2_sqlite::SqliteConnectionManager::memory();
|
||||
let db = SqliteDb::new(manager, false).unwrap();
|
||||
let db = SqliteDb::open(manager, false).unwrap();
|
||||
test_suite(db);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user