mirror of
https://github.com/Dummi26/rembackup.git
synced 2025-03-10 05:13:54 +01:00
improve messages, ...
This commit is contained in:
parent
7581cb24bc
commit
6566b42697
@ -20,6 +20,7 @@ pub struct Args {
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub noconfirm: bool,
|
pub noconfirm: bool,
|
||||||
|
|
||||||
|
/// the file in which you specified what files/directories should be ignored
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub ignore: Option<PathBuf>,
|
pub ignore: Option<PathBuf>,
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use std::{
|
|||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct FsEntry<'a> {
|
pub struct FsEntry<'a> {
|
||||||
pub path: &'a Path,
|
pub path: &'a Path,
|
||||||
pub is_directory: bool,
|
pub is_directory: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -73,12 +73,14 @@ impl Specifier {
|
|||||||
match self {
|
match self {
|
||||||
Self::Except(inner) => inner.matches(entry).map(std::ops::Not::not),
|
Self::Except(inner) => inner.matches(entry).map(std::ops::Not::not),
|
||||||
Self::Entries(path) => path.matches(entry.path).then_some(true),
|
Self::Entries(path) => path.matches(entry.path).then_some(true),
|
||||||
Self::Files(path) => (!entry.is_directory && path.matches(entry.path)).then_some(true),
|
Self::Files(path) => {
|
||||||
|
(entry.is_directory == Some(false) && path.matches(entry.path)).then_some(true)
|
||||||
|
}
|
||||||
Self::InDir { dir, inner } => {
|
Self::InDir { dir, inner } => {
|
||||||
if inner.0.is_empty() {
|
if inner.0.is_empty() {
|
||||||
// this has no inner things, so we just check for this directory
|
// this has no inner things, so we just check for this directory
|
||||||
// if this is a directory and it matches, then return true
|
// if this is a directory and it matches, then return true
|
||||||
(entry.is_directory && dir.matches(entry.path)).then_some(true)
|
(entry.is_directory == Some(true) && dir.matches(entry.path)).then_some(true)
|
||||||
} else {
|
} else {
|
||||||
// this has inner things, so, for every matching parent,
|
// this has inner things, so, for every matching parent,
|
||||||
// get the relative path (by removing the parent), ...
|
// get the relative path (by removing the parent), ...
|
||||||
|
@ -79,8 +79,11 @@ fn main() {
|
|||||||
&args.settings,
|
&args.settings,
|
||||||
) {
|
) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err((what, path, err)) => {
|
||||||
eprintln!("Failed to generate index diff:\n {e}");
|
eprintln!(
|
||||||
|
"Failed to generate index diff:\n {what}\n {}\n {err}",
|
||||||
|
path.to_string_lossy()
|
||||||
|
);
|
||||||
exit(EXIT_DIFF_FAILED as _);
|
exit(EXIT_DIFF_FAILED as _);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
use std::{collections::HashMap, fs, io, path::Path};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
fs, io,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
|
||||||
@ -33,7 +37,7 @@ pub fn perform_index_diff<'a>(
|
|||||||
target: Option<&'a Path>,
|
target: Option<&'a Path>,
|
||||||
mut ignore: Ignore,
|
mut ignore: Ignore,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> io::Result<Vec<IndexChange>> {
|
) -> Result<Vec<IndexChange>, (String, PathBuf, io::Error)> {
|
||||||
let mut changes = Vec::new();
|
let mut changes = Vec::new();
|
||||||
if let Ok(inner_index) = index.strip_prefix(source) {
|
if let Ok(inner_index) = index.strip_prefix(source) {
|
||||||
eprintln!("[info] source contains index at {inner_index:?}, but index will not be part of the backup.");
|
eprintln!("[info] source contains index at {inner_index:?}, but index will not be part of the backup.");
|
||||||
@ -72,7 +76,7 @@ fn rec(
|
|||||||
changes: &mut Vec<IndexChange>,
|
changes: &mut Vec<IndexChange>,
|
||||||
ignore: &Ignore,
|
ignore: &Ignore,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), io::Error> {
|
) -> Result<(), (String, PathBuf, io::Error)> {
|
||||||
// used to find removals
|
// used to find removals
|
||||||
let index_rel_path = index_files.join(rel_path);
|
let index_rel_path = index_files.join(rel_path);
|
||||||
let mut index_entries = match fs::read_dir(&index_rel_path) {
|
let mut index_entries = match fs::read_dir(&index_rel_path) {
|
||||||
@ -83,26 +87,43 @@ fn rec(
|
|||||||
Ok(e) => e
|
Ok(e) => e
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|v| v.ok())
|
.filter_map(|v| v.ok())
|
||||||
.map(|v| Ok((v.file_name(), v.file_type()?.is_dir())))
|
.map(|v| {
|
||||||
.collect::<Result<_, io::Error>>()?,
|
Ok((
|
||||||
|
v.file_name(),
|
||||||
|
v.file_type()
|
||||||
|
.map_err(|e| ("getting file type".to_owned(), v.path(), e))?
|
||||||
|
.is_dir(),
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect::<Result<_, (String, PathBuf, io::Error)>>()?,
|
||||||
};
|
};
|
||||||
// compare source files with index
|
// compare source files with index
|
||||||
let source_files = fs::read_dir(source.join(rel_path))?.collect::<Vec<_>>();
|
let source_files_path = source.join(rel_path);
|
||||||
|
let source_files = fs::read_dir(&source_files_path)
|
||||||
|
.map_err(|e| ("getting entries".to_owned(), source_files_path.clone(), e))?
|
||||||
|
.collect::<Vec<_>>();
|
||||||
// find changes/adds
|
// find changes/adds
|
||||||
for entry in source_files {
|
for entry in source_files {
|
||||||
let entry = entry?;
|
let entry = entry.map_err(|e| {
|
||||||
|
(
|
||||||
|
"error with an entry within this directory".to_owned(),
|
||||||
|
source_files_path.clone(),
|
||||||
|
e,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
let rel_path = rel_path.join(entry.file_name());
|
let rel_path = rel_path.join(entry.file_name());
|
||||||
let metadata = entry.metadata()?;
|
let metadata = entry.metadata();
|
||||||
|
|
||||||
// ignore entries
|
// ignore entries
|
||||||
let fs_entry = FsEntry {
|
let fs_entry = FsEntry {
|
||||||
path: &rel_path,
|
path: &rel_path,
|
||||||
is_directory: metadata.is_dir(),
|
is_directory: metadata.as_ref().ok().map(|v| v.is_dir()),
|
||||||
};
|
};
|
||||||
if ignore.matches_or_default(&fs_entry) {
|
if ignore.matches_or_default(&fs_entry) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let metadata = metadata.map_err(|e| ("getting metadata (you have to ignore this using a * pattern instead of + or /, because we don't know if it's a directory or not)".to_owned(), entry.path(), e))?;
|
||||||
let in_index_and_is_dir = index_entries.remove(&entry.file_name());
|
let in_index_and_is_dir = index_entries.remove(&entry.file_name());
|
||||||
if metadata.is_dir() {
|
if metadata.is_dir() {
|
||||||
if let Some(false) = in_index_and_is_dir {
|
if let Some(false) = in_index_and_is_dir {
|
||||||
|
Loading…
Reference in New Issue
Block a user