Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchypark committed Sep 3, 2024
1 parent 20fa9cc commit 34185ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
34 changes: 20 additions & 14 deletions object_store_factory/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ impl LocalConfig {
map: &HashMap<String, String>,
) -> Result<Self, object_store::Error> {
Ok(Self {
data_dir: map.get("data_dir")
.ok_or_else(|| object_store::Error::Generic {
store: "local",
source: "Missing data_dir".into(),
})?
.clone(),
disable_hardlinks: map.get("disable_hardlinks").map(|s| s == "true").unwrap_or(false),
data_dir: map
.get("data_dir")
.ok_or_else(|| object_store::Error::Generic {
store: "local",
source: "Missing data_dir".into(),
})?
.clone(),
disable_hardlinks: map
.get("disable_hardlinks")
.map(|s| s == "true")
.unwrap_or(false),
})
}

pub fn to_hashmap(&self) -> HashMap<String, String> {
let mut map = HashMap::new();
map.insert("data_dir".to_string(), self.data_dir.clone());
map.insert("disable_hardlinks".to_string(), self.disable_hardlinks.to_string());
map.insert(
"disable_hardlinks".to_string(),
self.disable_hardlinks.to_string());
map
}

Expand All @@ -57,7 +63,7 @@ mod tests {
let config = LocalConfig::from_hashmap(&map)
.expect("Failed to create config from hashmap");
assert_eq!(config.data_dir, "/tmp/data".to_string());
assert_eq!(config.disable_hardlinks, false); // Default value
assert!(!config.disable_hardlinks); // Default value
}

#[test]
Expand All @@ -69,7 +75,7 @@ mod tests {
let config = LocalConfig::from_hashmap(&map)
.expect("Failed to create config from hashmap");
assert_eq!(config.data_dir, "/tmp/data".to_string());
assert_eq!(config.disable_hardlinks, true);
assert!(config.disable_hardlinks);
}

#[test]
Expand All @@ -81,7 +87,7 @@ mod tests {
let config = LocalConfig::from_hashmap(&map)
.expect("Failed to create config from hashmap");
assert_eq!(config.data_dir, "/tmp/data".to_string());
assert_eq!(config.disable_hardlinks, false);
assert!(!config.disable_hardlinks);
}

#[test]
Expand Down Expand Up @@ -133,7 +139,7 @@ mod tests {

#[test]
fn test_default_false() {
assert_eq!(default_false(), false);
assert!(!default_false());
}

#[test]
Expand All @@ -146,7 +152,7 @@ mod tests {

let config: LocalConfig = serde_json::from_str(json).unwrap();
assert_eq!(config.data_dir, "/tmp/data");
assert_eq!(config.disable_hardlinks, false);
assert!(!config.disable_hardlinks);
}

#[test]
Expand All @@ -160,6 +166,6 @@ mod tests {

let config: LocalConfig = serde_json::from_str(json).unwrap();
assert_eq!(config.data_dir, "/tmp/data");
assert_eq!(config.disable_hardlinks, true);
assert!(config.disable_hardlinks);
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use seafowl::{

use tokio::time::{interval, Duration};
use tracing::level_filters::LevelFilter;
use tracing::{error, info, debug, subscriber, warn};
use tracing::{debug, error, info, subscriber, warn};
use tracing_log::LogTracer;
use tracing_subscriber::filter::EnvFilter;

Expand Down
31 changes: 26 additions & 5 deletions src/object_store/wrapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use url::Url;

use object_store_factory::aws::S3Config;
use object_store_factory::google::GCSConfig;
use object_store_factory::ObjectStoreConfig;
use object_store_factory::local::LocalConfig;
use object_store_factory::ObjectStoreConfig;

// Wrapper around the object_store crate that holds on to the original config
// in order to provide a more efficient "upload" for the local object store
Expand Down Expand Up @@ -152,8 +152,21 @@ impl ObjectStore for InternalObjectStore {
payload: PutPayload,
opts: PutOptions,
) -> Result<PutResult> {
if let ObjectStoreConfig::Local(LocalConfig { disable_hardlinks: true, .. }) = self.config {
return self.inner.put_opts(location, payload, PutOptions{mode: object_store::PutMode::Overwrite, ..opts}).await
if let ObjectStoreConfig::Local(LocalConfig {
disable_hardlinks: true,
..
}) = self.config
{
return self
.inner
.put_opts(
location,
payload,
PutOptions{
mode: object_store::PutMode::Overwrite,
..opts
},
).await;
};
self.inner.put_opts(location, payload, opts).await
}
Expand Down Expand Up @@ -243,7 +256,11 @@ impl ObjectStore for InternalObjectStore {
///
/// Will return an error if the destination already has an object.
async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
if let ObjectStoreConfig::Local(LocalConfig { disable_hardlinks: true, .. }) = self.config {
if let ObjectStoreConfig::Local(LocalConfig {
disable_hardlinks: true,
..
}) = self.config
{
return self.inner.copy(from, to).await;
}
self.inner.copy_if_not_exists(from, to).await
Expand All @@ -261,7 +278,11 @@ impl ObjectStore for InternalObjectStore {
// this with a lock too, so look into using that down the line instead.
return self.inner.rename(from, to).await;
}
if let ObjectStoreConfig::Local(LocalConfig { disable_hardlinks: true, .. }) = self.config {
if let ObjectStoreConfig::Local(LocalConfig {
disable_hardlinks: true,
..
}) = self.config
{
return self.inner.rename(from, to).await;
}
self.inner.rename_if_not_exists(from, to).await
Expand Down

0 comments on commit 34185ee

Please sign in to comment.