Skip to content

Commit d72b5e3

Browse files
committed
fix: 🐛 compressed file contains extra path
1 parent b3fcc1f commit d72b5e3

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ readme = "README.md"
1010
repository = "https://github.com/Koro33/s-backup"
1111

1212
[dependencies]
13-
anyhow = "1.0.79"
13+
anyhow = "1.0.80"
1414
blake3 = { version = "1.5.0", features = ["mmap", "rayon"] }
1515
chrono = { version = "0.4.34" }
16-
clap = { version = "4.5.0", features = ["derive"] }
16+
clap = { version = "4.5.1", features = ["derive"] }
1717
humansize = { version = "2.1.3", features = ["impl_style"] }
1818
opendal = { version = "0.45.0", features = ["layers-tracing"] }
19-
serde = { version = "1.0.196", features = ["derive"] }
19+
serde = { version = "1.0.197", features = ["derive"] }
2020
tempfile = "3.10.0"
2121
tokio = { version = "1.36.0", features = [
2222
"macros",

src/main.rs

+47-26
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,13 @@ async fn main() -> Result<()> {
2626
let args = Args::parse();
2727

2828
match &args.command {
29-
Commands::Run { config } => run(config).await?,
29+
Commands::Run { config } => {
30+
run(config).await?;
31+
graceful_shutdown().await;
32+
}
3033
Commands::Test { config } => test(config).await?,
3134
}
3235

33-
#[cfg(unix)]
34-
let terminate = async {
35-
signal::unix::signal(signal::unix::SignalKind::terminate())
36-
.expect("failed to install signal handler")
37-
.recv()
38-
.await;
39-
tracing::warn!("signal terminate received");
40-
};
41-
42-
#[cfg(not(unix))]
43-
let terminate = std::future::pending::<()>();
44-
45-
let ctrl_c = async {
46-
signal::ctrl_c()
47-
.await
48-
.expect("failed to install signal handler");
49-
tracing::warn!("signal ctrl_c received");
50-
};
51-
52-
tokio::select! {
53-
_ = ctrl_c => {},
54-
_ = terminate => {},
55-
}
56-
5736
Ok(())
5837
}
5938

@@ -77,7 +56,21 @@ async fn run(config_path: &str) -> Result<()> {
7756
}
7857

7958
async fn test(config_path: &str) -> Result<()> {
80-
tracing::warn!("test unimplemented");
59+
// check config file syntax
60+
let config = read_config(config_path).await.map_err(|e| {
61+
tracing::error!("❌ read config failed at `{}`: {}", config_path, e);
62+
e
63+
})?;
64+
tracing::info!("✅ config file syntax is ok");
65+
66+
// check s3 instance
67+
let s3_op = init_s3(&config.s3).await?;
68+
s3_op.check().await.map_err(|e| {
69+
tracing::error!("❌ connect to s3 service failed: {}", e);
70+
e
71+
})?;
72+
tracing::info!("✅ connect to s3 service successfully");
73+
8174
Ok(())
8275
}
8376

@@ -123,12 +116,14 @@ async fn backup(b: &Backup, s3_oprator: &Operator) -> Result<()> {
123116
.to_string(),
124117
];
125118
args.extend(b.exclude.iter().map(|e| format!("--exclude={}", e)));
119+
args.push("-C".to_string());
126120
args.push(
127121
backup_source
128122
.to_str()
129123
.ok_or(anyhow!("failed to convert path to string"))?
130124
.to_string(),
131125
);
126+
args.push(".".to_string());
132127

133128
cmd.args(args).kill_on_drop(true);
134129

@@ -236,5 +231,31 @@ fn find_remove_files(entries: &[opendal::Entry], name: &str, keep: usize) -> Vec
236231
to_remove
237232
}
238233

234+
async fn graceful_shutdown() {
235+
#[cfg(unix)]
236+
let terminate = async {
237+
signal::unix::signal(signal::unix::SignalKind::terminate())
238+
.expect("failed to install signal handler")
239+
.recv()
240+
.await;
241+
tracing::warn!("signal terminate received");
242+
};
243+
244+
#[cfg(not(unix))]
245+
let terminate = std::future::pending::<()>();
246+
247+
let ctrl_c = async {
248+
signal::ctrl_c()
249+
.await
250+
.expect("failed to install signal handler");
251+
tracing::warn!("signal ctrl_c received");
252+
};
253+
254+
tokio::select! {
255+
_ = ctrl_c => {},
256+
_ = terminate => {},
257+
}
258+
}
259+
239260
#[cfg(test)]
240261
mod tests {}

0 commit comments

Comments
 (0)