Skip to content

Commit

Permalink
feat: cks and f cks moved
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonPaulGithub committed Mar 11, 2024
1 parent afac6aa commit 6b474fa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 39 deletions.
24 changes: 1 addition & 23 deletions sn_cli/src/subcommands/acc_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,30 +671,8 @@ impl AccountPacket {
// overlapping use of file and folder uploads (working on it!)
)?;

let chunks = chunk_manager.already_put_chunks(
&self.files_dir,
true, // todo: unknown how this value is managed over here,
// but we should consider a design to compensate for the
// overlapping use of file and folder uploads (working on it!)
)?;
println!(
"Files upload attempted previously, verifying {} chunks",
chunks.len()
);

let failed_chunks = files_api
.client()
.verify_uploaded_chunks(&chunks, options.batch_size)
.await?;

IterativeUploader::new(chunk_manager, files_api)
.iterate_upload(
chunks,
failed_chunks,
total_files,
self.files_dir.clone(),
options.clone(),
)
.iterate_upload(total_files, self.files_dir.clone(), options.clone())
.await?;

// Let's make the storage payment for Folders
Expand Down
13 changes: 0 additions & 13 deletions sn_cli/src/subcommands/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ pub(crate) async fn files_cmds(
make_data_public,
)?;

let chunks = chunk_manager.already_put_chunks(&file_path, make_data_public)?;
println!(
"Files upload attempted previously, verifying {} chunks",
chunks.len()
);

let failed_chunks = files_api
.client()
.verify_uploaded_chunks(&chunks, batch_size)
.await?;

if total_files == 0 {
if file_path.is_dir() {
bail!(
Expand All @@ -147,8 +136,6 @@ pub(crate) async fn files_cmds(
} else {
IterativeUploader::new(chunk_manager, files_api)
.iterate_upload(
chunks,
failed_chunks,
total_files,
file_path.clone(),
FilesUploadOptions {
Expand Down
4 changes: 4 additions & 0 deletions sn_cli/src/subcommands/files/chunk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ impl ChunkManager {
make_files_public: bool,
) -> Result<Vec<(XorName, PathBuf)>> {
self.chunk_path(files_path, false, make_files_public)?;
println!(
"Verifying {} previously attempted chunks",
self.get_chunks().len()
);
Ok(self.get_chunks())
}

Expand Down
13 changes: 10 additions & 3 deletions sn_cli/src/subcommands/files/iterative_uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ 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,
chunks: Vec<(XorName, PathBuf)>,
failed_chunks: Vec<(XorName, PathBuf)>,
total_files: usize,
files_path: PathBuf,
options: FilesUploadOptions,
Expand All @@ -47,9 +45,18 @@ impl IterativeUploader {

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

let already_put_chunks = self
.chunk_manager
.already_put_chunks(&files_path, make_data_public)?;

let failed_chunks = self
.files_api
.get_failed_chunks(already_put_chunks.clone(), batch_size)
.await?;

let mut chunks_to_upload = if self.chunk_manager.is_chunks_empty() {
self.chunk_manager.mark_completed(
chunks
already_put_chunks
.into_iter()
.filter(|c| !failed_chunks.contains(c))
.map(|(xor, _)| xor),
Expand Down
11 changes: 11 additions & 0 deletions sn_client/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ impl FilesApi {
}
}

pub async fn get_failed_chunks(
&self,
already_put_chunks: Vec<(XorName, PathBuf)>,
batch_size: usize,
) -> Result<Vec<(XorName, PathBuf)>> {
Ok(self
.client()
.verify_uploaded_chunks(&already_put_chunks, batch_size)
.await?)
}

/// Return the client instance
pub fn client(&self) -> &Client {
&self.client
Expand Down

0 comments on commit 6b474fa

Please sign in to comment.