Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sync progress bars optional #1125

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ data-encoding = "2.3"
dirs = "5.0"
dunce = "1.0.4"
dyn-clone = "1.0"
enum_dispatch = "0.3.13"
flatbuffers = "23.5.26"
fuser = "0.14.0"
futures = "0.3.28"
Expand Down
26 changes: 22 additions & 4 deletions crates/spfs-cli/common/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ use tracing_subscriber::prelude::*;

const SPFS_LOG: &str = "SPFS_LOG";

/// Options for showing progress
#[derive(Clone, Copy, Debug, Default, clap::ValueEnum)]
pub enum Progress {
/// Show progress bars (default)
#[default]
Bars,
/// Do not show any progress
None,
}

/// Command line flags for configuring sync operations
#[derive(Debug, Clone, clap::Args)]
pub struct Sync {
Expand Down Expand Up @@ -54,6 +64,10 @@ pub struct Sync {
default_value_t = spfs::sync::DEFAULT_MAX_CONCURRENT_PAYLOADS
)]
pub max_concurrent_payloads: usize,

/// Options for showing progress
#[clap(long, value_enum)]
pub progress: Option<Progress>,
}

impl Sync {
Expand All @@ -63,13 +77,17 @@ impl Sync {
&self,
src: &'src spfs::storage::RepositoryHandle,
dest: &'dst spfs::storage::RepositoryHandle,
) -> spfs::Syncer<'src, 'dst, spfs::sync::ConsoleSyncReporter> {
) -> spfs::Syncer<'src, 'dst> {
let policy = self.sync_policy();
spfs::Syncer::new(src, dest)
let syncer = spfs::Syncer::new(src, dest)
.with_policy(policy)
.with_max_concurrent_manifests(self.max_concurrent_manifests)
.with_max_concurrent_payloads(self.max_concurrent_payloads)
.with_reporter(spfs::sync::ConsoleSyncReporter::default())
.with_max_concurrent_payloads(self.max_concurrent_payloads);

match self.progress.unwrap_or_default() {
Progress::Bars => syncer.with_reporter(spfs::sync::reporter::SyncReporters::console()),
Progress::None => syncer,
}
}

/// The selected sync policy for these options
Expand Down
10 changes: 9 additions & 1 deletion crates/spfs-cli/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ pub mod __private {
pub use {libc, spfs};
}

pub use args::{capture_if_relevant, AnnotationViewing, CommandName, Logging, Render, Sync};
pub use args::{
capture_if_relevant,
AnnotationViewing,
CommandName,
Logging,
Progress,
Render,
Sync,
};
#[cfg(feature = "sentry")]
pub use args::{configure_sentry, shutdown_sentry};
1 change: 1 addition & 0 deletions crates/spfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data-encoding = "2.3"
derive_builder = { workspace = true }
dirs = { workspace = true }
dunce = { workspace = true }
enum_dispatch = { workspace = true }
faccess = "0.2.3"
flatbuffers = { workspace = true }
futures = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/spfs/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use tokio::sync::Semaphore;

use crate::graph::AnnotationValue;
use crate::prelude::*;
use crate::sync::{SyncObjectResult, SyncPayloadResult, SyncPolicy};
use crate::sync::reporter::{SyncObjectResult, SyncPayloadResult};
use crate::sync::SyncPolicy;
use crate::{encoding, graph, storage, tracking, Error, Result};

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions crates/spfs/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub fn format_changes<'a, U1: 'a, U2: 'a>(
}

/// Return a human-readable representation of the sync summary data.
pub fn format_sync_summary(summary: &super::sync::SyncSummary) -> String {
let super::sync::SyncSummary {
pub fn format_sync_summary(summary: &super::sync::reporter::SyncSummary) -> String {
let super::sync::reporter::SyncSummary {
skipped_tags,
synced_tags,
skipped_objects,
Expand Down
3 changes: 2 additions & 1 deletion crates/spfs/src/storage/fallback/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::prelude::*;
use crate::storage::fs::{FsHashStore, ManifestRenderPath, OpenFsRepository, RenderStore};
use crate::storage::tag::TagSpecAndTagStream;
use crate::storage::{EntryType, LocalRepository, TagNamespace, TagNamespaceBuf, TagStorageMut};
use crate::sync::reporter::SyncReporters;
use crate::tracking::BlobRead;
use crate::{encoding, graph, storage, tracking, Error, Result};

Expand Down Expand Up @@ -238,7 +239,7 @@ impl PayloadStorage for FallbackProxy {
.with_reporter(
// There may already be a progress bar in use in this
// context, so don't make another one here.
crate::sync::SilentSyncReporter::default(),
SyncReporters::silent(),
);
match syncer.sync_digest(digest).await {
Ok(_) => {
Expand Down
Loading
Loading