mirror of
https://github.com/qwjyh/xdbm
synced 2025-04-20 19:55:49 +09:00
Compare commits
6 commits
6f8a71fe8d
...
fe2847ba5b
Author | SHA1 | Date | |
---|---|---|---|
fe2847ba5b | |||
d64cf6e255 | |||
|
2b4efd71bc | ||
87b73bd125 | |||
df0ce53d84 | |||
feb51a5653 |
9 changed files with 37 additions and 30 deletions
|
@ -1,5 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
## [0.2.0] - 2024-05-21
|
||||
|
||||
### Changed
|
||||
- Added CI on GitHub Actions (#10).
|
||||
- Replaced `HashMap` with `BTreeMap` to produce cleaner diff (#11).
|
||||
|
||||
## [0.1.0] - 2024-03-18
|
||||
|
||||
### Added
|
||||
|
@ -15,4 +21,5 @@
|
|||
- `backup done` subcommand
|
||||
- `completion` subcommand
|
||||
|
||||
[0.2.0]: https://github.com/qwjyh/xdbm/releases/tag/v0.2.0
|
||||
[0.1.0]: https://github.com/qwjyh/xdbm/releases/tag/v0.1.0
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1438,7 +1438,7 @@ checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
|
|||
|
||||
[[package]]
|
||||
name = "xdbm"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "xdbm"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["qwjyh <urataw421@gmail.com>"]
|
||||
edition = "2021"
|
||||
description = "Cross device backup manager, which manages backups on several storages mounted on multiple devices."
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use core::panic;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
collections::BTreeMap,
|
||||
fs, io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
@ -202,14 +202,14 @@ impl Backup {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Backups {
|
||||
pub list: HashMap<String, Backup>,
|
||||
pub list: BTreeMap<String, Backup>,
|
||||
}
|
||||
|
||||
impl Backups {
|
||||
/// Empty [`Backups`].
|
||||
pub fn new() -> Backups {
|
||||
Backups {
|
||||
list: HashMap::new(),
|
||||
list: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
collections::BTreeMap,
|
||||
io::{self, stdout, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
@ -103,14 +103,14 @@ pub fn cmd_backup_list(
|
|||
storages: &Storages,
|
||||
) -> Result<()> {
|
||||
let devices = devices::get_devices(config_dir)?;
|
||||
let backups: HashMap<(String, String), Backup> = match device_name {
|
||||
let backups: BTreeMap<(String, String), Backup> = match device_name {
|
||||
Some(device_name) => {
|
||||
let device = devices
|
||||
.iter()
|
||||
.find(|dev| dev.name() == device_name)
|
||||
.context(format!("Device with name {} doesn't exist", device_name))?;
|
||||
let backups = Backups::read(config_dir, device)?;
|
||||
let mut allbackups = HashMap::new();
|
||||
let mut allbackups = BTreeMap::new();
|
||||
for (name, backup) in backups.list {
|
||||
if allbackups.insert((device.name(), name), backup).is_some() {
|
||||
return Err(anyhow!("unexpected duplication in backups hashmap"));
|
||||
|
@ -119,7 +119,7 @@ pub fn cmd_backup_list(
|
|||
allbackups
|
||||
}
|
||||
None => {
|
||||
let mut allbackups = HashMap::new();
|
||||
let mut allbackups = BTreeMap::new();
|
||||
for device in &devices {
|
||||
let backups = Backups::read(config_dir, device)?;
|
||||
for (name, backup) in backups.list {
|
||||
|
@ -132,7 +132,7 @@ pub fn cmd_backup_list(
|
|||
}
|
||||
};
|
||||
// source/destination filtering
|
||||
let backups: HashMap<(String, String), Backup> = backups
|
||||
let backups: BTreeMap<(String, String), Backup> = backups
|
||||
.into_iter()
|
||||
.filter(|((_dev, _name), backup)| {
|
||||
let src_matched = match &src_storage {
|
||||
|
@ -156,7 +156,7 @@ pub fn cmd_backup_list(
|
|||
/// TODO: status printing
|
||||
fn write_backups_list(
|
||||
mut writer: impl io::Write,
|
||||
backups: HashMap<(String, String), Backup>,
|
||||
backups: BTreeMap<(String, String), Backup>,
|
||||
longprint: bool,
|
||||
storages: &Storages,
|
||||
devices: &[Device],
|
||||
|
|
|
@ -9,7 +9,7 @@ use anyhow::{anyhow, Context, Result};
|
|||
use clap::ValueEnum;
|
||||
use core::panic;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, fmt, fs, io, path, u64};
|
||||
use std::{collections::BTreeMap, fmt, fs, io, path, u64};
|
||||
|
||||
/// YAML file to store known storages..
|
||||
pub const STORAGESFILE: &str = "storages.yml";
|
||||
|
@ -135,7 +135,7 @@ pub trait StorageExt {
|
|||
fn local_info(&self, device: &devices::Device) -> Option<&local_info::LocalInfo>;
|
||||
|
||||
/// Get mount path of `self` on `device`.
|
||||
/// `storages` is a `HashMap` with key of storage name and value of the storage.
|
||||
/// `storages` is a `BTreeMap` with key of storage name and value of the storage.
|
||||
fn mount_path(&self, device: &devices::Device) -> Result<path::PathBuf>;
|
||||
|
||||
/// Add local info of `device` to `self`.
|
||||
|
@ -157,14 +157,14 @@ pub mod physical_drive_partition;
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Storages {
|
||||
pub list: HashMap<String, Storage>,
|
||||
pub list: BTreeMap<String, Storage>,
|
||||
}
|
||||
|
||||
impl Storages {
|
||||
/// Construct empty [`Storages`]
|
||||
pub fn new() -> Storages {
|
||||
Storages {
|
||||
list: HashMap::new(),
|
||||
list: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, fmt, path};
|
||||
use std::{collections::BTreeMap, fmt, path};
|
||||
|
||||
use crate::devices;
|
||||
use crate::util;
|
||||
|
@ -20,7 +20,7 @@ pub struct Directory {
|
|||
relative_path: path::PathBuf,
|
||||
pub notes: String,
|
||||
/// Device and localinfo pairs.
|
||||
local_infos: HashMap<String, LocalInfo>,
|
||||
local_infos: BTreeMap<String, LocalInfo>,
|
||||
}
|
||||
|
||||
impl Directory {
|
||||
|
@ -33,7 +33,7 @@ impl Directory {
|
|||
parent: String,
|
||||
relative_path: path::PathBuf,
|
||||
notes: String,
|
||||
local_infos: HashMap<String, LocalInfo>,
|
||||
local_infos: BTreeMap<String, LocalInfo>,
|
||||
) -> Directory {
|
||||
Directory {
|
||||
name,
|
||||
|
@ -61,7 +61,7 @@ impl Directory {
|
|||
parent.name().to_string(),
|
||||
diff_path,
|
||||
notes,
|
||||
HashMap::from([(device.name(), local_info)]),
|
||||
BTreeMap::from([(device.name(), local_info)]),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ impl fmt::Display for Directory {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::{collections::BTreeMap, path::PathBuf};
|
||||
|
||||
use crate::{
|
||||
devices::Device,
|
||||
|
@ -161,7 +161,7 @@ mod test {
|
|||
let local_info_dir =
|
||||
LocalInfo::new("dir_alias".to_string(), PathBuf::from("/mnt/sample/subdir"));
|
||||
let device = Device::new("test_device".to_string());
|
||||
let mut local_infos = HashMap::new();
|
||||
let mut local_infos = BTreeMap::new();
|
||||
local_infos.insert(device.name(), local_info_dir);
|
||||
let physical = PhysicalDrivePartition::new(
|
||||
"parent".to_string(),
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use anyhow::{Context, Result};
|
||||
use byte_unit::Byte;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::path;
|
||||
|
||||
|
@ -23,7 +23,7 @@ pub struct OnlineStorage {
|
|||
/// Capacity in bytes.
|
||||
capacity: u64,
|
||||
/// Device and local info pairs.
|
||||
local_infos: HashMap<String, LocalInfo>,
|
||||
local_infos: BTreeMap<String, LocalInfo>,
|
||||
}
|
||||
|
||||
impl OnlineStorage {
|
||||
|
@ -42,7 +42,7 @@ impl OnlineStorage {
|
|||
name,
|
||||
provider,
|
||||
capacity,
|
||||
local_infos: HashMap::from([(device.name(), local_info)]),
|
||||
local_infos: BTreeMap::from([(device.name(), local_info)]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use anyhow::{anyhow, Context, Result};
|
|||
use byte_unit::Byte;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{self, Path};
|
||||
use std::{collections::HashMap, fmt};
|
||||
use std::{collections::BTreeMap, fmt};
|
||||
use sysinfo::{Disk, DiskExt, SystemExt};
|
||||
|
||||
use super::local_info::{self, LocalInfo};
|
||||
|
@ -20,8 +20,8 @@ pub struct PhysicalDrivePartition {
|
|||
capacity: u64,
|
||||
fs: String,
|
||||
is_removable: bool,
|
||||
// system_names: HashMap<String, String>,
|
||||
local_infos: HashMap<String, LocalInfo>,
|
||||
// system_names: BTreeMap<String, String>,
|
||||
local_infos: BTreeMap<String, LocalInfo>,
|
||||
}
|
||||
|
||||
impl PhysicalDrivePartition {
|
||||
|
@ -40,7 +40,7 @@ impl PhysicalDrivePartition {
|
|||
capacity,
|
||||
fs,
|
||||
is_removable,
|
||||
local_infos: HashMap::from([(device.name(), local_info)]),
|
||||
local_infos: BTreeMap::from([(device.name(), local_info)]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,8 @@ impl PhysicalDrivePartition {
|
|||
capacity: disk.total_space(),
|
||||
fs: fs.to_string(),
|
||||
is_removable: disk.is_removable(),
|
||||
// system_names: HashMap::from([(device.name(), alias)]),
|
||||
local_infos: HashMap::from([(device.name(), local_info)]),
|
||||
// system_names: BTreeMap::from([(device.name(), alias)]),
|
||||
local_infos: BTreeMap::from([(device.name(), local_info)]),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue