Skip to content

Commit

Permalink
fix(cli): use chunk-mgr with iterator skipping tracking info files
Browse files Browse the repository at this point in the history
  • Loading branch information
bochaco committed Mar 12, 2024
1 parent 326b5ac commit 6d0fb49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions sn_cli/src/subcommands/acc_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,10 @@ impl AccountPacket {
let files_api = FilesApi::build(self.client.clone(), self.wallet_dir.clone())?;
let mut chunk_manager = ChunkManager::new(&self.tracking_info_dir.clone());

let chunks_to_upload = files::chunks_to_upload(
let chunks_to_upload = files::chunks_to_upload_with_iter(
&files_api,
&mut chunk_manager,
&self.files_dir.clone(),
self.iter_only_files(),
options.batch_size,
options.make_data_public,
true,
Expand Down
27 changes: 24 additions & 3 deletions sn_cli/src/subcommands/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::{
path::{Path, PathBuf},
};
use upload::{FilesUploadOptions, UploadedFile, UPLOADED_FILES};
use walkdir::WalkDir;
use walkdir::{DirEntry, WalkDir};
use xor_name::XorName;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -276,13 +276,34 @@ pub(crate) async fn files_cmds(
pub async fn chunks_to_upload(
files_api: &FilesApi,
chunk_manager: &mut ChunkManager,
file_path: &Path,
files_path: &Path,
batch_size: usize,
make_data_public: bool,
acc_pac: bool,
) -> Result<Vec<(XorName, PathBuf)>> {
chunks_to_upload_with_iter(
files_api,
chunk_manager,
WalkDir::new(files_path).into_iter().flatten(),
batch_size,
make_data_public,
acc_pac,
)
.await
}

pub async fn chunks_to_upload_with_iter(
files_api: &FilesApi,
chunk_manager: &mut ChunkManager,
entries_iter: impl Iterator<Item = DirEntry>,
batch_size: usize,
make_data_public: bool,
acc_pac: bool,
) -> Result<Vec<(XorName, PathBuf)>> {
let chunks_to_upload = if chunk_manager.is_chunks_empty() {
let chunks = chunk_manager.already_put_chunks(file_path, make_data_public)?;
chunk_manager.chunk_with_iter(entries_iter, false, make_data_public)?;

let chunks = chunk_manager.get_chunks();

let failed_chunks = files_api
.client()
Expand Down
11 changes: 0 additions & 11 deletions sn_cli/src/subcommands/files/chunk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,6 @@ impl ChunkManager {
.collect()
}

/// Return the filename and the file's Xor address if all their chunks has been marked as
/// completed
pub(crate) fn already_put_chunks(
&mut self,
files_path: &Path,
make_files_public: bool,
) -> Result<Vec<(XorName, PathBuf)>> {
self.chunk_path(files_path, false, make_files_public)?;
Ok(self.get_chunks())
}

/// Returns an iterator over the list of chunked files
pub(crate) fn iter_chunked_files(&mut self) -> impl Iterator<Item = &ChunkedFile> {
self.chunks.values()
Expand Down

0 comments on commit 6d0fb49

Please sign in to comment.