chore(rust): update lockfile and format sources
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+25
-13
@@ -1,14 +1,13 @@
|
||||
use crate::models::folder::FolderSimple;
|
||||
use crate::cache::{create_authenticated_conn, load_cache_with_token_refresh};
|
||||
use crate::commands::shared::{
|
||||
find_file_by_name, find_folder, find_lab_in_cache,
|
||||
nfc, parse_remote_path,
|
||||
find_file_by_name, find_folder, find_lab_in_cache, nfc, parse_remote_path,
|
||||
};
|
||||
use crate::models::folder::FolderSimple;
|
||||
use anyhow::{anyhow, bail};
|
||||
use futures::stream::{FuturesUnordered, StreamExt};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tokio::fs;
|
||||
use anyhow::{anyhow, bail};
|
||||
|
||||
pub async fn upload(
|
||||
local_path: &str,
|
||||
@@ -40,7 +39,8 @@ pub async fn upload(
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.upload_file(&dest_folder.id, &local.to_string_lossy()).await?;
|
||||
conn.upload_file(&dest_folder.id, &local.to_string_lossy())
|
||||
.await?;
|
||||
println!("{}{}", dest_folder.path, filename);
|
||||
} else if local.is_dir() {
|
||||
if !recursive {
|
||||
@@ -50,13 +50,18 @@ pub async fn upload(
|
||||
// remote_path. E.g. `upload ./mydir remote:/lab/path/` creates
|
||||
// `/lab/path/mydir/` on the remote and uploads into that folder.
|
||||
let local_basename = local.file_name().unwrap().to_string_lossy().to_string();
|
||||
let top_remote_id = find_or_create_folder(&conn, &dest_folder.id, &dest_folder.sub_folders, &local_basename).await?;
|
||||
let top_remote_id = find_or_create_folder(
|
||||
&conn,
|
||||
&dest_folder.id,
|
||||
&dest_folder.sub_folders,
|
||||
&local_basename,
|
||||
)
|
||||
.await?;
|
||||
let top_folder = conn.retrieve_folder(&top_remote_id).await?;
|
||||
println!("{}", top_folder.path.trim_end_matches('/'));
|
||||
|
||||
// Iterative depth-first walk: each entry is (local_dir, remote_folder_id)
|
||||
let mut stack: Vec<(PathBuf, String)> =
|
||||
vec![(local.to_path_buf(), top_remote_id)];
|
||||
let mut stack: Vec<(PathBuf, String)> = vec![(local.to_path_buf(), top_remote_id)];
|
||||
|
||||
while let Some((local_dir, remote_id)) = stack.pop() {
|
||||
let folder_detail = conn.retrieve_folder(&remote_id).await?;
|
||||
@@ -77,15 +82,16 @@ pub async fn upload(
|
||||
// Ensure each local sub-directory exists on the remote side
|
||||
for subdir in subdirs {
|
||||
let dirname = subdir.file_name().unwrap().to_string_lossy().to_string();
|
||||
let sub_remote_id = find_or_create_folder(&conn, &remote_id, &folder_detail.sub_folders, &dirname).await?;
|
||||
let sub_remote_id =
|
||||
find_or_create_folder(&conn, &remote_id, &folder_detail.sub_folders, &dirname)
|
||||
.await?;
|
||||
let sub_folder = conn.retrieve_folder(&sub_remote_id).await?;
|
||||
println!("{}", sub_folder.path.trim_end_matches('/'));
|
||||
stack.push((subdir, sub_remote_id));
|
||||
}
|
||||
|
||||
// Upload files in this directory (up to 10 concurrent)
|
||||
let mut futs: FuturesUnordered<tokio::task::JoinHandle<()>> =
|
||||
FuturesUnordered::new();
|
||||
let mut futs: FuturesUnordered<tokio::task::JoinHandle<()>> = FuturesUnordered::new();
|
||||
for file_path in files {
|
||||
let filename = file_path.file_name().unwrap().to_string_lossy().to_string();
|
||||
let file_path_str = file_path.to_string_lossy().to_string();
|
||||
@@ -111,7 +117,10 @@ pub async fn upload(
|
||||
// (connection pool) while supplying a fresh Bearer token.
|
||||
let task_conn = match load_cache_with_token_refresh(&remote).await {
|
||||
Ok(c) => conn.with_token(c.token.access),
|
||||
Err(e) => { eprintln!("Error: {}", e); return; }
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
match task_conn.upload_file(&folder_id, &file_path_str).await {
|
||||
Ok(_) => println!("{}{}", remote_path_prefix, fname),
|
||||
@@ -138,7 +147,10 @@ async fn find_or_create_folder(
|
||||
existing: &[FolderSimple],
|
||||
name: &str,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
if let Some(sf) = existing.iter().find(|f| nfc(&f.name).to_lowercase() == nfc(name).to_lowercase()) {
|
||||
if let Some(sf) = existing
|
||||
.iter()
|
||||
.find(|f| nfc(&f.name).to_lowercase() == nfc(name).to_lowercase())
|
||||
{
|
||||
return Ok(sf.id.clone());
|
||||
}
|
||||
let resp = conn.create_folder(parent_id, &nfc(name)).await?;
|
||||
|
||||
Reference in New Issue
Block a user