Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ rustdoc-args = ["--document-private-items", "--generate-link-to-definition"]

[dependencies]
abscissa_core = { version = "0.8.1", default-features = false, features = ["application"] }
rustic_backend = { git = "https://github.com/rustic-rs/rustic_core.git", features = ["cli"] }
rustic_core = { git = "https://github.com/rustic-rs/rustic_core.git", features = ["cli"] }
rustic_backend = { git = "https://github.com/rustic-rs/rustic_core.git", branch = "typed_path", features = ["cli"] }
rustic_core = { git = "https://github.com/rustic-rs/rustic_core.git", branch = "typed_path", features = ["cli"] }

# allocators
jemallocator-global = { version = "0.3.2", optional = true }
Expand Down Expand Up @@ -144,7 +144,7 @@ pretty_assertions = "1.4"
quickcheck = "1"
quickcheck_macros = "1"
rstest = "0.23"
rustic_testing = { git = "https://github.com/rustic-rs/rustic_core.git" }
rustic_testing = { git = "https://github.com/rustic-rs/rustic_core.git", branch = "typed_path" }
tar = "0.4.43"
tempfile = "3.14"
toml = "0.8"
Expand Down
26 changes: 13 additions & 13 deletions src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use abscissa_core::{Command, Runnable, Shutdown};
use clap::ValueHint;
use log::debug;

use std::{
fmt::Display,
path::{Path, PathBuf},
};
use std::{fmt::Display, path::PathBuf};

use anyhow::{Context, Result, bail};

use rustic_core::{
IndexedFull, LocalDestination, LocalSource, LocalSourceFilterOptions, LocalSourceSaveOptions,
LsOptions, ReadSource, ReadSourceEntry, Repository, RusticResult,
repofile::{Node, NodeType},
typed_path::{UnixPath, UnixPathBuf},
util::path_to_unix_path,
};

/// `diff` subcommand
Expand Down Expand Up @@ -97,6 +96,7 @@ impl DiffCmd {
let node1 = repo.node_from_snapshot_and_path(&snap1, path1)?;
let local = LocalDestination::new(path2, false, !node1.is_dir())?;
let path2 = PathBuf::from(path2);
let path2_unix = path_to_unix_path(&path2)?;
let is_dir = path2
.metadata()
.with_context(|| format!("Error accessing {path2:?}"))?
Expand All @@ -111,10 +111,10 @@ impl DiffCmd {
let ReadSourceEntry { path, node, .. } = item?;
let path = if is_dir {
// remove given path prefix for dirs as local path
path.strip_prefix(&path2).unwrap().to_path_buf()
path.strip_prefix(&path2_unix).unwrap().to_path_buf()
} else {
// ensure that we really get the filename if local path is a file
path2.file_name().unwrap().into()
path2_unix.file_name().unwrap().into()
};
Ok((path, node))
});
Expand Down Expand Up @@ -190,7 +190,7 @@ fn arg_to_snap_path<'a>(arg: &'a str, default_path: &'a str) -> (Option<&'a str>
fn identical_content_local<P, S: IndexedFull>(
local: &LocalDestination,
repo: &Repository<P, S>,
path: &Path,
path: &UnixPath,
node: &Node,
) -> Result<bool> {
let Some(mut open_file) = local.get_matching_file(path, node.meta.size) else {
Expand Down Expand Up @@ -317,10 +317,10 @@ impl Display for DiffStatistics {
///
// TODO!: add errors!
fn diff(
mut tree_streamer1: impl Iterator<Item = RusticResult<(PathBuf, Node)>>,
mut tree_streamer2: impl Iterator<Item = RusticResult<(PathBuf, Node)>>,
mut tree_streamer1: impl Iterator<Item = RusticResult<(UnixPathBuf, Node)>>,
mut tree_streamer2: impl Iterator<Item = RusticResult<(UnixPathBuf, Node)>>,
no_content: bool,
file_identical: impl Fn(&Path, &Node, &Node) -> Result<bool>,
file_identical: impl Fn(&UnixPath, &Node, &Node) -> Result<bool>,
metadata: bool,
) -> Result<()> {
let mut item1 = tree_streamer1.next().transpose()?;
Expand Down Expand Up @@ -393,9 +393,9 @@ fn diff(
}

fn diff_identical(
mut tree_streamer1: impl Iterator<Item = RusticResult<(PathBuf, Node)>>,
mut tree_streamer2: impl Iterator<Item = RusticResult<(PathBuf, Node)>>,
file_identical: impl Fn(&Path, &Node, &Node) -> Result<bool>,
mut tree_streamer1: impl Iterator<Item = RusticResult<(UnixPathBuf, Node)>>,
mut tree_streamer2: impl Iterator<Item = RusticResult<(UnixPathBuf, Node)>>,
file_identical: impl Fn(&UnixPath, &Node, &Node) -> Result<bool>,
) -> Result<()> {
let mut item1 = tree_streamer1.next().transpose()?;
let mut item2 = tree_streamer2.next().transpose()?;
Expand Down
5 changes: 4 additions & 1 deletion src/commands/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use log::warn;
use rustic_core::{
LsOptions,
repofile::{Node, NodeType},
util::{typed_path_to_path, unix_path_to_path},
vfs::OpenFile,
};
use tar::{Builder, EntryType, Header};
Expand Down Expand Up @@ -203,7 +204,7 @@ fn dump_tar(

// handle special files
if node.is_symlink() {
header.set_link_name(node.node_type.to_link())?;
header.set_link_name(typed_path_to_path(&node.node_type.to_link())?)?;
}
match node.node_type {
NodeType::Dev { device } | NodeType::Chardev { device } => {
Expand All @@ -213,6 +214,7 @@ fn dump_tar(
_ => {}
}

let path = unix_path_to_path(&path)?;
if node.is_file() {
// write file content if this is a regular file
let open_file = OpenFileReader {
Expand Down Expand Up @@ -280,6 +282,7 @@ fn write_zip_contents(
options =
options.last_modified_time(mtime.naive_local().try_into().unwrap_or_default());
}
let path = unix_path_to_path(&path)?;
if node.is_file() {
zip.start_file_from_path(path, options)?;
repo.dump(&node, zip)?;
Expand Down
13 changes: 8 additions & 5 deletions src/commands/find.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! `find` subcommand

use std::path::{Path, PathBuf};

use crate::{Application, RUSTIC_APP, repository::CliIndexedRepo, status_err};

use abscissa_core::{Command, Runnable, Shutdown};
Expand All @@ -13,6 +11,8 @@ use itertools::Itertools;
use rustic_core::{
FindMatches, FindNode, SnapshotGroupCriterion,
repofile::{Node, SnapshotFile},
typed_path::{UnixPath, UnixPathBuf},
util::u8_to_path,
};

use super::ls::print_node;
Expand All @@ -30,7 +30,7 @@ pub(crate) struct FindCmd {

/// exact path to find
#[clap(long, value_name = "PATH", value_hint = ValueHint::AnyPath)]
path: Option<PathBuf>,
path: Option<UnixPathBuf>,

/// Snapshots to search in. If none is given, use filter options to filter from all snapshots
#[clap(value_name = "ID")]
Expand Down Expand Up @@ -105,8 +105,11 @@ impl FindCmd {
_ = builder.add(GlobBuilder::new(glob).case_insensitive(true).build()?);
}
let globset = builder.build()?;
let matches = |path: &Path, _: &Node| {
globset.is_match(path) || path.file_name().is_some_and(|f| globset.is_match(f))
let matches = |path: &UnixPath, _: &Node| {
globset.is_match(u8_to_path(path))
|| path
.file_name()
.is_some_and(|f| globset.is_match(u8_to_path(f)))
};
let FindMatches {
paths,
Expand Down
7 changes: 3 additions & 4 deletions src/commands/ls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! `ls` subcommand

use std::path::Path;

use crate::{Application, RUSTIC_APP, repository::CliIndexedRepo, status_err};

use abscissa_core::{Command, Runnable, Shutdown};
Expand All @@ -10,6 +8,7 @@ use anyhow::Result;
use rustic_core::{
LsOptions,
repofile::{Node, NodeType},
typed_path::UnixPath,
};

mod constants {
Expand Down Expand Up @@ -153,7 +152,7 @@ impl LsCmd {
if !first_item {
print!(",");
}
print!("{}", serde_json::to_string(&path)?);
print!("{}", path.display());
} else if self.long {
print_node(&node, &path, self.numeric_id);
} else {
Expand Down Expand Up @@ -183,7 +182,7 @@ impl LsCmd {
///
/// * `node` - the node to print
/// * `path` - the path of the node
pub fn print_node(node: &Node, path: &Path, numeric_uid_gid: bool) {
pub fn print_node(node: &Node, path: &UnixPath, numeric_uid_gid: bool) {
println!(
"{:>10} {:>8} {:>8} {:>9} {:>17} {path:?} {}",
node.mode_str(),
Expand Down
21 changes: 14 additions & 7 deletions src/commands/mount/fusefs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#[cfg(not(windows))]
use std::os::unix::prelude::OsStrExt;
use std::{
collections::BTreeMap,
ffi::{CString, OsStr},
os::unix::ffi::OsStrExt,
path::Path,
sync::RwLock,
time::{Duration, SystemTime},
Expand All @@ -11,6 +10,8 @@ use std::{
use rustic_core::{
IndexedFull, Repository,
repofile::{Node, NodeType},
typed_path::UnixPathBuf,
util::{path_to_unix_path, typed_path_to_unix_path},
vfs::{FilePolicy, OpenFile, Vfs},
};

Expand Down Expand Up @@ -43,13 +44,19 @@ impl<P, S: IndexedFull> FuseFS<P, S> {

fn node_from_path(&self, path: &Path) -> Result<Node, i32> {
self.vfs
.node_from_path(&self.repo, path)
.node_from_path(
&self.repo,
&path_to_unix_path(path).map_err(|_| libc::ENOENT)?,
)
.map_err(|_| libc::ENOENT)
}

fn dir_entries_from_path(&self, path: &Path) -> Result<Vec<Node>, i32> {
self.vfs
.dir_entries_from_path(&self.repo, path)
.dir_entries_from_path(
&self.repo,
&path_to_unix_path(path).map_err(|_| libc::ENOENT)?,
)
.map_err(|_| libc::ENOENT)
}
}
Expand All @@ -74,9 +81,9 @@ fn node_type_to_rdev(tpe: &NodeType) -> u32 {
.unwrap()
}

fn node_to_linktarget(node: &Node) -> Option<&OsStr> {
fn node_to_linktarget(node: &Node) -> Option<UnixPathBuf> {
if node.is_symlink() {
Some(node.node_type.to_link().as_os_str())
Some(typed_path_to_unix_path(&node.node_type.to_link()).to_path_buf())
} else {
None
}
Expand Down Expand Up @@ -187,7 +194,7 @@ impl<P, S: IndexedFull> FilesystemMT for FuseFS<P, S> {
let result = nodes
.into_iter()
.map(|node| DirectoryEntry {
name: node.name(),
name: OsStr::from_bytes(&node.name()).to_os_string(),
kind: node_to_filetype(&node),
})
.collect();
Expand Down
Loading
Loading