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 29c35bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
7 changes: 3 additions & 4 deletions sn_cli/src/subcommands/acc_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,17 @@ 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,
)
.await?;

IterativeUploader::new(chunk_manager, files_api)
.iterate_upload(chunks_to_upload, self.files_dir.clone(), options.clone())
.iterate_upload(chunks_to_upload, &self.files_dir, options.clone())
.await?;

// Let's make the storage payment for Folders
Expand Down
35 changes: 24 additions & 11 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 @@ -142,14 +142,13 @@ pub(crate) async fn files_cmds(
&file_path,
batch_size,
make_data_public,
false,
)
.await?;

IterativeUploader::new(chunk_manager, files_api)
.iterate_upload(
chunks_to_upload,
file_path.clone(),
&file_path,
FilesUploadOptions {
make_data_public,
verify_store,
Expand Down Expand Up @@ -276,13 +275,31 @@ 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,
) -> 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,
)
.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 All @@ -307,11 +324,7 @@ pub async fn chunks_to_upload(
}
iterative_uploader::msg_chunk_manager_upload_complete(chunk_manager.clone());

if acc_pac {
bail!("")
} else {
return Ok(vec![]);
}
return Ok(vec![]);
}
msg_unverified_chunks_reattempted(&failed_chunks.len());
failed_chunks
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
8 changes: 4 additions & 4 deletions sn_cli/src/subcommands/files/iterative_uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use color_eyre::{eyre::eyre, Result};
use indicatif::ProgressBar;
use sn_client::transfers::{NanoTokens, TransferError, WalletError};
use sn_client::{Error as ClientError, Error, FileUploadEvent, FilesApi, FilesUpload};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use std::time::Instant;
Expand All @@ -31,7 +31,7 @@ impl IterativeUploader {
pub(crate) async fn iterate_upload(
self,
chunks_to_upload: Vec<(XorName, PathBuf)>,
files_path: PathBuf,
files_path: &Path,
options: FilesUploadOptions,
) -> Result<()> {
let FilesUploadOptions {
Expand All @@ -41,7 +41,7 @@ impl IterativeUploader {
retry_strategy,
} = options;

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

let mut files_upload = FilesUpload::new(self.files_api)
.set_batch_size(batch_size)
Expand Down Expand Up @@ -179,7 +179,7 @@ fn msg_check_incomplete_files(chunk_manager: &mut ChunkManager) {
}
}

fn msg_init(files_path: &PathBuf, batch_size: &usize, verify_store: &bool, make_data_public: bool) {
fn msg_init(files_path: &Path, batch_size: &usize, verify_store: &bool, make_data_public: bool) {
debug!("Uploading file(s) from {files_path:?}, batch size {batch_size:?} will verify?: {verify_store}");
if make_data_public {
info!("{files_path:?} will be made public and linkable");
Expand Down

0 comments on commit 29c35bb

Please sign in to comment.