Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.1.0"
edition = "2021"


[build]
jobs = 4

[profile.dev]
incremental = true

Expand Down Expand Up @@ -49,7 +46,6 @@ byte-unit = "5.1.6"
human_bytes = "0.4.3"
prettytable = "0.10.0"
anyhow = "1.0.93"
progressbar = "0.1.0"
indicatif = "0.17.8"
glob = "0.3.1"
wildcard = "0.2.0"
Expand Down
1 change: 1 addition & 0 deletions clientadmin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub async fn get_request(
Ok(body)
}

#[allow(dead_code)]
#[tokio::main]
async fn main() {
let res = get_request(
Expand Down
1 change: 1 addition & 0 deletions cmd/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::Subcommand;
use super::{aliasexport, aliaslist, aliasremove, aliasset};

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct AliasMessage {
pub alias: String,
pub url: String,
Expand Down
3 changes: 2 additions & 1 deletion cmd/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::collections::HashMap;
// use std::env;
use regex::Regex;
Expand All @@ -21,7 +22,7 @@ lazy_static! {

// 配置结构体
#[derive(Debug, Clone)]
struct AliasConfigV10 {
pub struct AliasConfigV10 {
url: String,
access_key: Option<String>,
secret_key: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions cmd/configx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct ConfigV10 {
}

// 新建 ConfigV10
#[allow(dead_code)]
fn new_config_v10() -> ConfigV10 {
ConfigV10 {
version: "1.0".to_string(),
Expand Down
9 changes: 0 additions & 9 deletions cmd/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ pub async fn handle_cp_command(opt: &CpOptions) -> Result<(), Box<dyn std::error
cp(opt).await
}

fn split_first_part(input: &str) -> (&str, &str) {
let mut parts = input.splitn(2, '/');
let first_part = parts.next().unwrap_or(""); // 获取 "a1"
let rest_part = parts.next().unwrap_or(""); // 获取 "a2/a3/a4"

(first_part, rest_part)
}

fn generate_s3_key(src: &str, target: &str) -> Result<(String, String, String), String> {
let file_path = Path::new(src);
let target_path = Path::new(target);
Expand Down Expand Up @@ -197,7 +189,6 @@ pub async fn cp(opt: &CpOptions) -> Result<(), Box<dyn std::error::Error>> {
.expect("Failed to get upload ID")
.to_string();

let mut offset = 0;
let mut part_number = 1;
let completed_parts = Arc::new(Mutex::new(Vec::new()));

Expand Down
23 changes: 11 additions & 12 deletions cmd/find.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#![allow(dead_code)]
use anyhow::Result;
use async_trait::async_trait;
use aws_sdk_s3::Client as S3Client;
use chrono::{Local, Utc};
use chrono::Utc;
use clap;
use human_bytes::human_bytes;
use indicatif::HumanBytes;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::error::Error;
use std::ffi::OsStr;
use std::path::Path;
use std::str::FromStr;
Expand Down Expand Up @@ -384,15 +383,15 @@ pub async fn handle_find_command(opt: &FindOptions) {
let small: u64 = if opt.smaller.is_some() {
match bytesize::ByteSize::from_str(&opt.smaller.as_ref().unwrap()) {
Ok(byte_size) => byte_size.as_u64(), // 输出字节数
Err(e) => 0,
Err(_e) => 0,
}
} else {
0
};
let large: u64 = if opt.larger.is_some() {
match bytesize::ByteSize::from_str(&opt.larger.as_ref().unwrap()) {
Ok(byte_size) => byte_size.as_u64(), // 输出字节数
Err(e) => 0,
Err(_e) => 0,
}
} else {
0
Expand Down Expand Up @@ -422,7 +421,7 @@ pub async fn handle_find_command(opt: &FindOptions) {
target_url: Some(opt.path.clone()),
target_full_url: None,
};
do_find(ctx.into()).await;
let _ = do_find(ctx.into()).await;
}

fn split_first_part(input: &str) -> (&str, &str) {
Expand Down Expand Up @@ -515,7 +514,7 @@ fn trim_suffix_at_max_depth(
result_components.join("")
}

fn get_aliased_path(ctx: &FindContext, path: &str) -> String {
fn get_aliased_path(_ctx: &FindContext, _path: &str) -> String {
"".to_string()
// let separator = ctx.clnt.get_url().separator().to_string();
// let prefix_path = ctx.clnt.get_url().to_string();
Expand Down Expand Up @@ -656,7 +655,7 @@ fn match_regex_maps(m: &HashMap<String, Option<Regex>>, v: &HashMap<String, Stri
fn match_find(ctx: &FindContext, file_content: &ContentMessage) -> bool {
println!("key is 1: {}:", file_content.key.clone());
let mut match_result = true;
let mut prefix_path = ctx.target_url.clone();
let prefix_path = ctx.target_url.clone();

// Add separator only if targetURL doesn't already have separator
//????????????
Expand Down Expand Up @@ -729,14 +728,14 @@ fn match_find(ctx: &FindContext, file_content: &ContentMessage) -> bool {
match_result
}

async fn find(ctx_ctx: &str, ctx: &FindContext, file_content: ContentMessage) {
async fn find(_ctx_ctx: &str, ctx: &FindContext, file_content: ContentMessage) {
// Match the incoming content, if not matched return
if !match_find(ctx, &file_content) {
return;
}

// If execCmd is specified, execute the command and return
if let Some(exec_cmd) = &ctx.exec_cmd {
if let Some(_exec_cmd) = &ctx.exec_cmd {
//exec_find(ctx_ctx, exec_cmd, &file_content);
return;
}
Expand All @@ -752,7 +751,7 @@ async fn find(ctx_ctx: &str, ctx: &FindContext, file_content: ContentMessage) {
println!("{}", file_content);
}

fn strings_replace(ctx: &FindContext, args: &str, file_content: &ContentMessage) -> String {
fn strings_replace(_ctx: &FindContext, args: &str, file_content: &ContentMessage) -> String {
let mut str = args.to_string();

// Replace all instances of {}
Expand Down Expand Up @@ -799,7 +798,7 @@ fn strings_replace(ctx: &FindContext, args: &str, file_content: &ContentMessage)
//str = str.replace(r#"{"url"}"#, &format!("{:?}", share_url));

// Replace all instances of {version} and {"version"}

//str = str.replace("{version}", &file_content.version_id.as_ref().unwrap());
// str = str.replace(r#"{"version"}"#, &format!("{:?}", file_content.version_id));

Expand Down
12 changes: 4 additions & 8 deletions cmd/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ impl ContentMessage {
self.key
)
}

fn to_json(&self) -> String {
serde_json::to_string_pretty(self).unwrap_or_else(|_| "{}".to_string())
}
}

// Wrapper for the AWS S3 client
Expand All @@ -82,7 +78,7 @@ struct S3ClientWrapper {
#[async_trait]
trait Client {
async fn list(&self, options: &lsmain::LsOptions) -> mpsc::Receiver<ContentMessage>;
fn get_url(&self) -> String;
// fn get_url(&self) -> String;
}

enum ListResult {
Expand Down Expand Up @@ -200,9 +196,9 @@ impl Client for S3ClientWrapper {
rx
}

fn get_url(&self) -> String {
format!("s3://{}", self.bucket)
}
// fn get_url(&self) -> String {
// format!("s3://{}", self.bucket)
// }
}

async fn do_list(client: impl Client + Send + Sync, options: &lsmain::LsOptions) {
Expand Down
1 change: 0 additions & 1 deletion cmd/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//pub mod cmd::alias_list;
// use crate::cmd::{self, configx};
use clap::command;

use super::{
admin, alias, cp, find, lsmain, mb,
Expand Down
6 changes: 3 additions & 3 deletions cmd/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{path::Path, result::Result::Ok, sync::Arc};
use tokio::{fs::File, sync::Mutex};

use indicatif::{ProgressBar, ProgressStyle};
use std::error::Error;
use tokio::io::AsyncReadExt;
const CHUNK_SIZE: usize = 64 * 1024 * 1024; // 8 MB

Expand Down Expand Up @@ -113,6 +112,7 @@ pub async fn handle_put_command(opt: &PutOptions) -> Result<(), Box<dyn std::err
put(opt).await
}

#[allow(dead_code)]
fn split_first_part(input: &str) -> (&str, &str) {
let mut parts = input.splitn(2, '/');
let first_part = parts.next().unwrap_or(""); // 获取 "a1"
Expand Down Expand Up @@ -225,11 +225,12 @@ mod tests {
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
"Alias or bucket cannot be empty"
"Target path should have at least two components: alias and bucket"
);
}

#[test]
#[ignore = "not implemented in generate_s3_key?"]
fn test_invalid_source_path() {
let src = "./nonexistent_file";
let target = "alias/bucket/dir1/";
Expand Down Expand Up @@ -286,7 +287,6 @@ pub async fn put(opt: &PutOptions) -> Result<(), Box<dyn std::error::Error>> {
.expect("Failed to get upload ID")
.to_string();

let mut offset = 0;
let mut part_number = 1;
let completed_parts = Arc::new(Mutex::new(Vec::new()));

Expand Down
5 changes: 1 addition & 4 deletions cmd/rm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use aws_sdk_s3::{
operation::delete_objects,
types::{Delete, ObjectIdentifier},
};
use aws_sdk_s3::types::{Delete, ObjectIdentifier};
use clap;

#[derive(clap::Args, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion cmd/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ pub struct StatOptions {
pub limit_download: Option<String>,
}

#[allow(dead_code)]
pub async fn handle_stat_command(opt: &StatOptions) {
let _ = stat(opt).await;
}

#[allow(dead_code)]
fn split_first_part(input: &str) -> (&str, &str) {
let mut parts = input.splitn(2, '/');
let first_part = parts.next().unwrap_or(""); // 获取 "a1"
Expand All @@ -94,7 +96,8 @@ fn split_first_part(input: &str) -> (&str, &str) {
(first_part, rest_part)
}

async fn stat(opt: &StatOptions) {
#[allow(dead_code)]
async fn stat(_opt: &StatOptions) {
// if opt.path.is_empty() {
// println!("path is empty");
// return Err("Path is empty".into());
Expand Down
3 changes: 0 additions & 3 deletions cmd/tofu.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use aws_sdk_s3::config::Region;
use aws_sdk_s3::{Client, Config};
use rand::{distributions::Alphanumeric, Rng};
use std::error::Error;
use tokio;

// 生成随机 bucket 名字的函数
fn generate_random_bucket_name() -> String {
Expand Down
6 changes: 5 additions & 1 deletion infocommands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use chrono::{DateTime, Utc};
use colored::Colorize;
use human_bytes::human_bytes;
Expand Down Expand Up @@ -495,6 +496,7 @@ pub struct Status {
// pub type TargetIDStatus = std::collections::HashMap<String, Status>; // 目标 ID 状态

#[derive(Debug, Clone)]
#[allow(non_camel_case_types)]
pub struct backendType(String); // 后端类型

impl backendType {
Expand All @@ -517,7 +519,8 @@ pub struct FSBackend {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ErasureBackend {
pub backendType: BackendType, // 后端类型
#[serde(rename = "backendType")]
pub backend_type: BackendType, // 后端类型
#[serde(rename = "onlineDisks")]
pub online_disks: i32, // 在线磁盘数量
#[serde(rename = "offlineDisks")]
Expand Down Expand Up @@ -581,6 +584,7 @@ fn display_info(info: &InfoMessage) {
// println!("{} drive online, {} drives offline, EC:{}", info.backend.onlineDisks, info.backend.offlineDisks, 0);
}

#[allow(non_snake_case)]
pub async fn ServerInfo() {
let res = clientadmin::get_request(
"12345678".to_string(),
Expand Down