Compare commits

..

No commits in common. "55c5f2493705e32d1c52f324ce1ba541ae392d9d" and "f71db90922a8eaa3758e569e763d8f999caec53d" have entirely different histories.

3 changed files with 9 additions and 38 deletions

View File

@ -122,11 +122,10 @@ where
&self,
layer: &str,
start_time: chrono::DateTime<Utc>,
dirs: &Vec<(PathBuf, PathBuf)>,
) -> Option<io::Result<()>> {
self.managers
.get(layer)
.map(|manager| manager.restore_backup(start_time, dirs))
.map(|manager| manager.restore_backup(start_time))
}
pub fn managers(&self) -> &HashMap<String, Manager<T>> {

View File

@ -161,11 +161,7 @@ where
/// Restore the backup with the given start time by restoring its chain up to and including the
/// backup, in order.
pub fn restore_backup(
&self,
start_time: chrono::DateTime<Utc>,
dirs: &Vec<(PathBuf, PathBuf)>,
) -> io::Result<()> {
pub fn restore_backup(&self, start_time: chrono::DateTime<Utc>) -> io::Result<()> {
// Iterate over each chain, skipping elements until the element with the given start time
// is possibly found.
for chain in &self.chains {
@ -176,7 +172,7 @@ where
.position(|b| b.start_time.trunc_subsecs(0) == start_time)
{
for backup in chain.iter().take(index + 1) {
backup.restore(&self.backup_dir, dirs)?;
backup.restore(&self.backup_dir, &self.dirs)?;
}
return Ok(());

View File

@ -38,16 +38,9 @@ pub struct BackupListArgs {
pub struct BackupRestoreArgs {
/// Path to the backup inside the backup directory
path: PathBuf,
/// Directory to store config in
output_config: PathBuf,
/// Directory to store worlds in
output_worlds: PathBuf,
/// Whether to overwrite the contents of the existing directories
#[arg(short, long, default_value_t = false)]
force: bool,
/// Create output directories if they don't exist
#[arg(short, long, default_value_t = false)]
make: bool,
}
impl BackupArgs {
@ -76,15 +69,6 @@ impl BackupRestoreArgs {
pub fn run(&self, cli: &Cli) -> io::Result<()> {
let backup_dir = cli.backup.canonicalize()?;
// Create directories if needed
if self.make {
std::fs::create_dir_all(&self.output_config)?;
std::fs::create_dir_all(&self.output_worlds)?;
}
let output_config = self.output_config.canonicalize()?;
let output_worlds = self.output_worlds.canonicalize()?;
// Parse input path
let path = self.path.canonicalize()?;
@ -113,9 +97,11 @@ impl BackupRestoreArgs {
let meta = cli.meta()?;
// Clear previous contents of directories
let mut entries = output_config
let mut entries = cli
.config
.canonicalize()?
.read_dir()?
.chain(output_worlds.read_dir()?)
.chain(cli.world.canonicalize()?.read_dir()?)
.peekable();
if entries.peek().is_some() && !self.force {
@ -132,13 +118,8 @@ impl BackupRestoreArgs {
}
}
let dirs = vec![
(PathBuf::from("config"), output_config),
(PathBuf::from("worlds"), output_worlds),
];
// Restore the backup
if let Some(res) = meta.restore_backup(&layer, timestamp, &dirs) {
if let Some(res) = meta.restore_backup(&layer, timestamp) {
res
} else {
Err(other("Unknown layer"))
@ -150,12 +131,7 @@ impl BackupListArgs {
pub fn run(&self, cli: &Cli) -> io::Result<()> {
let meta = cli.meta()?;
// A bit scuffed? Sure
for (name, manager) in meta
.managers()
.iter()
.filter(|(name, _)| self.layer.is_none() || &self.layer.as_ref().unwrap() == name)
{
for (name, manager) in meta.managers().iter() {
println!("{}", name);
for chain in manager.chains().iter().filter(|c| !c.is_empty()) {