Skip to content

Commit

Permalink
feat: number of files extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonPaulGithub committed Mar 11, 2024
1 parent 38bba37 commit 92976ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
45 changes: 29 additions & 16 deletions sn_cli/src/subcommands/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) async fn files_cmds(
verify_store: bool,
) -> Result<()> {
let files_api = FilesApi::build(client.clone(), root_dir.to_path_buf())?;
let chunk_manager = ChunkManager::new(root_dir);
let mut chunk_manager = ChunkManager::new(root_dir);

match cmds {
FilesCmds::Estimate {
Expand All @@ -118,23 +118,36 @@ pub(crate) async fn files_cmds(
retry_strategy,
make_data_public,
} => {
let total_files = IterativeUploader::new(chunk_manager, files_api)
.iterate_upload(
WalkDir::new(&file_path).into_iter().flatten(),
file_path.clone(),
FilesUploadOptions {
make_data_public,
verify_store,
batch_size,
retry_strategy,
},
)
.await?;
if total_files == 0 {
let total_files = chunk_manager.chunk_with_iter(
WalkDir::new(&file_path).into_iter().flatten(),
true,
make_data_public,
)?;

if total_files > 0 {
IterativeUploader::new(chunk_manager, files_api)
.iterate_upload(
total_files,
file_path.clone(),
FilesUploadOptions {
make_data_public,
verify_store,
batch_size,
retry_strategy,
},
)
.await?;
} else {
if file_path.is_dir() {
bail!("The directory specified for upload is empty. Please verify the provided path.");
bail!(
"The directory specified for upload is empty. \
Please verify the provided path."
);
} else {
bail!("The provided file path is invalid. Please verify the path.");
bail!(
"The provided file path is invalid. \
Please verify the path."
);
}
}
}
Expand Down
16 changes: 1 addition & 15 deletions sn_cli/src/subcommands/files/iterative_uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::sync::Arc;
use std::time::Instant;
use tokio::sync::mpsc::Receiver;
use tokio::task::JoinHandle;
use walkdir::DirEntry;
use xor_name::XorName;

pub(crate) struct IterativeUploader {
Expand All @@ -33,7 +32,7 @@ impl IterativeUploader {
/// Given an iterator over files, upload them. Optionally verify if the data was stored successfully.
pub(crate) async fn iterate_upload(
mut self,
entries_iter: impl Iterator<Item = DirEntry>,
total_files: usize,
files_path: PathBuf,
options: FilesUploadOptions,
) -> Result<usize> {
Expand All @@ -46,19 +45,6 @@ impl IterativeUploader {

msg_init(&files_path, &batch_size, &verify_store, make_data_public);

let total_files =
self.chunk_manager
.chunk_with_iter(entries_iter, true, make_data_public)?;

match total_files {
total_files if total_files != 0 => {}
_ => return Ok(0),
}

//if total_files == 0 {
// return Ok(0);
//}

let mut chunks_to_upload = if self.chunk_manager.is_chunks_empty() {
// make sure we don't have any failed chunks in those

Expand Down

0 comments on commit 92976ae

Please sign in to comment.