chore: global cleanup
This commit is contained in:
Generated
+10
-10
@@ -218,9 +218,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_complete"
|
name = "clap_complete"
|
||||||
version = "4.6.4"
|
version = "4.6.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3e962dae2b1e5007fe9e3db363ddc43a8bf25546d279f7a8a4401204690e80c"
|
checksum = "e0a7a9bfdb35811f9e59832f0f05975114d2251b415fb534108e6f34060fd772"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_lex",
|
"clap_lex",
|
||||||
@@ -1038,9 +1038,9 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
version = "0.10.79"
|
version = "0.10.80"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf0b434746ee2832f4f0baf10137e1cabb18cbe6912c69e2e33263c45250f542"
|
checksum = "a45fa2aa886c42762255da344f0a0d313e254066c46aad76f300c3d3da62d967"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
@@ -1069,9 +1069,9 @@ checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-sys"
|
name = "openssl-sys"
|
||||||
version = "0.9.115"
|
version = "0.9.116"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781"
|
checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -1672,9 +1672,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-http"
|
name = "tower-http"
|
||||||
version = "0.6.10"
|
version = "0.6.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68d6fdd9f81c2819c9a8b0e0cd91660e7746a8e6ea2ba7c6b2b057985f6bcb51"
|
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -2286,9 +2286,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerofrom"
|
name = "zerofrom"
|
||||||
version = "0.1.7"
|
version = "0.1.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df"
|
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerofrom-derive",
|
"zerofrom-derive",
|
||||||
]
|
]
|
||||||
|
|||||||
+51
-77
@@ -3,101 +3,75 @@ use log::info;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use crate::{base64_decode, File};
|
use crate::{File, base64_decode};
|
||||||
|
|
||||||
pub async fn files(files: &[File], root: &str, dry_run: bool) -> Result<()> {
|
pub async fn files(files: &[File], root: &str, dry_run: bool) -> Result<()> {
|
||||||
for f in files {
|
for f in files {
|
||||||
if let Err(e) = file(f, root, dry_run).await {
|
if let Err(e) = file(f, root, dry_run).await {
|
||||||
return Err(format_err!("{}: {e}", f.path))
|
return Err(format_err!("{}: {e}", f.path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn file(file: &File, root: &str, dry_run: bool) -> Result<()> {
|
pub async fn file(file: &File, root: &str, dry_run: bool) -> Result<()> {
|
||||||
let path = chroot(root, &file.path);
|
let path = chroot(root, &file.path);
|
||||||
let path = Path::new(&path);
|
let path = Path::new(&path);
|
||||||
|
|
||||||
if !dry_run && let Some(parent) = path.parent() {
|
if !dry_run && let Some(parent) = path.parent() {
|
||||||
fs::create_dir_all(parent).await?;
|
fs::create_dir_all(parent).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::{FileKind as K, FilePart as P};
|
let kind = file.kind();
|
||||||
match file.kind().as_ref() {
|
let content = kind.content()?;
|
||||||
K::Skip => {
|
|
||||||
info!("{}: kind is skip", file.path);
|
|
||||||
return Ok(())
|
|
||||||
},
|
|
||||||
K::Content(content) => {
|
|
||||||
if dry_run {
|
|
||||||
info!(
|
|
||||||
"would create {} ({} bytes from content)",
|
|
||||||
file.path,
|
|
||||||
content.len()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
fs::write(path, content.as_bytes()).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
K::Content64(content) => {
|
|
||||||
let content = base64_decode(content)?;
|
|
||||||
if dry_run {
|
|
||||||
info!(
|
|
||||||
"would create {} ({} bytes from content64)",
|
|
||||||
file.path,
|
|
||||||
content.len()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
fs::write(path, content).await?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
K::Parts(parts) => {
|
|
||||||
let mut assembly = Vec::new();
|
|
||||||
for part in parts {
|
|
||||||
match part {
|
|
||||||
P::Content(content) => assembly.extend(content.as_bytes()),
|
|
||||||
P::Content64(content) => assembly.extend(base64_decode(content)?),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if dry_run {
|
|
||||||
info!(
|
|
||||||
"would create {} ({} bytes from parts)",
|
|
||||||
file.path,
|
|
||||||
assembly.len()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
fs::write(path, assembly).await?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
K::Dir => {
|
|
||||||
if dry_run {
|
|
||||||
info!("would create {} (directory)", file.path);
|
|
||||||
} else {
|
|
||||||
fs::create_dir(path).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
K::Symlink(tgt) => {
|
|
||||||
if dry_run {
|
|
||||||
info!("would create {} (symlink to {})", file.path, tgt);
|
|
||||||
} else {
|
|
||||||
let _ = fs::remove_file(path).await; // we're ln --force
|
|
||||||
fs::symlink(tgt, path).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if dry_run {
|
use crate::{FileKind as K};
|
||||||
|
match kind.as_ref() {
|
||||||
|
K::Skip => {
|
||||||
|
info!("{}: kind is skip", file.path);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
K::Content(_) | K::Content64(_) | K::Parts(_) => {
|
||||||
if !file.is_symlink() {
|
let content = content.expect("this file kind should have content");
|
||||||
set_perms(path, file.mode).await?;
|
if dry_run {
|
||||||
|
info!(
|
||||||
|
"would create {} ({} bytes)",
|
||||||
|
file.path,
|
||||||
|
content.len()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
fs::write(path, &content).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
K::Dir => {
|
||||||
|
if dry_run {
|
||||||
|
info!("would create {} (directory)", file.path);
|
||||||
|
} else {
|
||||||
|
fs::create_dir(path).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
K::Symlink(tgt) => {
|
||||||
|
if dry_run {
|
||||||
|
info!("would create {} (symlink to {})", file.path, tgt);
|
||||||
|
} else {
|
||||||
|
let _ = fs::remove_file(path).await; // we're ln --force
|
||||||
|
fs::symlink(tgt, path).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("created {}", file.path);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dry_run {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if !file.is_symlink() {
|
||||||
|
set_perms(path, file.mode).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("created {}", file.path);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn set_perms(path: impl AsRef<Path>, mode: Option<u32>) -> std::io::Result<()> {
|
pub async fn set_perms(path: impl AsRef<Path>, mode: Option<u32>) -> std::io::Result<()> {
|
||||||
if let Some(mode) = mode.filter(|m| *m != 0) {
|
if let Some(mode) = mode.filter(|m| *m != 0) {
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
use clap::{CommandFactory, Parser, Subcommand};
|
use clap::{CommandFactory, Parser, Subcommand};
|
||||||
use eyre::{format_err, Result};
|
use eyre::{Result, format_err};
|
||||||
use human_units::Duration;
|
use human_units::Duration;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|||||||
+1
-1
@@ -64,8 +64,8 @@ pub async fn ls(
|
|||||||
}
|
}
|
||||||
|
|
||||||
use tabled::settings::{
|
use tabled::settings::{
|
||||||
object::{Column, Row},
|
|
||||||
Alignment, Modify,
|
Alignment, Modify,
|
||||||
|
object::{Column, Row},
|
||||||
};
|
};
|
||||||
let mut table = table.build();
|
let mut table = table.build();
|
||||||
table.with(tabled::settings::Style::psql());
|
table.with(tabled::settings::Style::psql());
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use eyre::{format_err, Result};
|
use eyre::{Result, format_err};
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tokio::{fs, io::AsyncWriteExt, process::Command};
|
use tokio::{fs, io::AsyncWriteExt, process::Command};
|
||||||
|
|||||||
+31
@@ -148,3 +148,34 @@ impl<'t> File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FileKind {
|
||||||
|
pub fn content<'t>(&'t self) -> Result<Option<Cow<'t, [u8]>>, base64::DecodeError> {
|
||||||
|
use FileKind::*;
|
||||||
|
Ok(match self {
|
||||||
|
Content(content) => Some(Cow::Borrowed(content.as_bytes())),
|
||||||
|
Content64(content) => {
|
||||||
|
let content = base64_decode(content)?;
|
||||||
|
Some(Cow::Owned(content))
|
||||||
|
}
|
||||||
|
Parts(parts) => {
|
||||||
|
let mut assembly = Vec::new();
|
||||||
|
for part in parts {
|
||||||
|
assembly.extend(part.content()?.into_iter());
|
||||||
|
}
|
||||||
|
Some(Cow::Owned(assembly))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FilePart {
|
||||||
|
pub fn content(&self) -> Result<Cow<[u8]>, base64::DecodeError> {
|
||||||
|
use FilePart::*;
|
||||||
|
Ok(match self {
|
||||||
|
Content(content) => Cow::Borrowed(content.as_bytes()),
|
||||||
|
Content64(content) => Cow::Owned(base64_decode(content)?),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
use async_compression::tokio::write::{ZstdDecoder, ZstdEncoder};
|
use async_compression::tokio::write::{ZstdDecoder, ZstdEncoder};
|
||||||
use chrono::{DurationRound, TimeDelta, Utc};
|
use chrono::{DurationRound, TimeDelta, Utc};
|
||||||
use eyre::{format_err, Result};
|
use eyre::{Result, format_err};
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -10,7 +10,7 @@ use tokio::{
|
|||||||
io::{self, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter},
|
io::{self, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter},
|
||||||
process::{Child, Command},
|
process::{Child, Command},
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
time::{sleep, Duration},
|
time::{Duration, sleep},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{cgroup, fs};
|
use crate::{cgroup, fs};
|
||||||
@@ -220,7 +220,7 @@ impl Logger {
|
|||||||
|
|
||||||
fn forward_signals_to(pid: i32) {
|
fn forward_signals_to(pid: i32) {
|
||||||
use nix::{
|
use nix::{
|
||||||
sys::signal::{kill, Signal},
|
sys::signal::{Signal, kill},
|
||||||
unistd::Pid,
|
unistd::Pid,
|
||||||
};
|
};
|
||||||
use signal_hook::{consts::*, low_level::register};
|
use signal_hook::{consts::*, low_level::register};
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ use std::collections::{BTreeMap as Map, BTreeSet as Set};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{copy, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader},
|
io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, copy},
|
||||||
net::{UnixListener, UnixStream},
|
net::{UnixListener, UnixStream},
|
||||||
sync::{mpsc, watch, RwLock},
|
sync::{RwLock, mpsc, watch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{cgroup, fs};
|
use crate::{cgroup, fs};
|
||||||
@@ -185,7 +185,7 @@ async fn handle(mut conn: UnixStream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_terminate() {
|
async fn wait_terminate() {
|
||||||
use tokio::signal::unix::{signal, SignalKind};
|
use tokio::signal::unix::{SignalKind, signal};
|
||||||
let Ok(mut sig) = signal(SignalKind::terminate())
|
let Ok(mut sig) = signal(SignalKind::terminate())
|
||||||
.inspect_err(|e| error!("failed to listen to SIGTERM (will be ignored): {e}"))
|
.inspect_err(|e| error!("failed to listen to SIGTERM (will be ignored): {e}"))
|
||||||
else {
|
else {
|
||||||
@@ -203,7 +203,7 @@ async fn wait_terminate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_reload() {
|
async fn wait_reload() {
|
||||||
use tokio::signal::unix::{signal, SignalKind};
|
use tokio::signal::unix::{SignalKind, signal};
|
||||||
let Ok(mut sig) = signal(SignalKind::hangup())
|
let Ok(mut sig) = signal(SignalKind::hangup())
|
||||||
.inspect_err(|e| error!("failed to listen to SIGHUP (will be ignored): {e}"))
|
.inspect_err(|e| error!("failed to listen to SIGHUP (will be ignored): {e}"))
|
||||||
else {
|
else {
|
||||||
|
|||||||
+2
-2
@@ -1,13 +1,13 @@
|
|||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use nix::{
|
use nix::{
|
||||||
sys::signal::{kill, Signal},
|
sys::signal::{Signal, kill},
|
||||||
unistd::Pid,
|
unistd::Pid,
|
||||||
};
|
};
|
||||||
use std::num::NonZero;
|
use std::num::NonZero;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
process, select,
|
process, select,
|
||||||
sync::{mpsc, watch},
|
sync::{mpsc, watch},
|
||||||
time::{sleep, sleep_until, Duration, Instant},
|
time::{Duration, Instant, sleep, sleep_until},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Error, Result, Service};
|
use super::{Error, Result, Service};
|
||||||
|
|||||||
Reference in New Issue
Block a user