Mount as a feature
This commit is contained in:
parent
94a3627a0f
commit
198a75d0ee
|
@ -532,8 +532,8 @@ dependencies = [
|
|||
"env_logger",
|
||||
"log",
|
||||
"rpassword",
|
||||
"rustcryptfs-fuse",
|
||||
"rustcryptfs-lib",
|
||||
"rustcryptfs-mount",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
@ -566,6 +566,13 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustcryptfs-mount"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustcryptfs-fuse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.11"
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
members = [
|
||||
"rustcryptfs",
|
||||
"rustcryptfs-lib",
|
||||
"rustcryptfs-fuse"
|
||||
"rustcryptfs-fuse",
|
||||
"rustcryptfs-mount"
|
||||
]
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "rustcryptfs-mount"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
rustcryptfs-fuse = { path = "../rustcryptfs-fuse" }
|
|
@ -0,0 +1,14 @@
|
|||
use std::path::Path;
|
||||
|
||||
use rustcryptfs_fuse::EncryptedFs;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn mount<P>(path: P, mount_point: P, password: &str) -> rustcryptfs_fuse::error::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let fs = EncryptedFs::new(path, password)?;
|
||||
|
||||
fs.mount(mount_point)?;
|
||||
Ok(())
|
||||
}
|
|
@ -5,6 +5,10 @@ edition = "2021"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["mount"]
|
||||
mount = ["rustcryptfs-mount"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.53"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
|
@ -14,6 +18,4 @@ log = "0.4.17"
|
|||
rustcryptfs-lib = { path = "../rustcryptfs-lib" }
|
||||
env_logger = "0.9.0"
|
||||
rpassword = "7.0.0"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
rustcryptfs-fuse = { path = "../rustcryptfs-fuse" }
|
||||
rustcryptfs-mount = { path = "../rustcryptfs-mount", optional = true }
|
|
@ -1,3 +1,4 @@
|
|||
#[cfg(feature = "mount")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
@ -14,9 +15,10 @@ pub(crate) enum Commands {
|
|||
/// Decrypt a file
|
||||
Decrypt(DecryptCommand),
|
||||
|
||||
// List file contained in a directory
|
||||
/// List file contained in a directory
|
||||
Ls(LsCommand),
|
||||
|
||||
#[cfg(feature = "mount")]
|
||||
/// Mount an encrypted folder
|
||||
Mount(MountCommand),
|
||||
}
|
||||
|
@ -49,6 +51,7 @@ pub(crate) struct LsCommand {
|
|||
pub(crate) password : Option<String>
|
||||
}
|
||||
|
||||
#[cfg(feature = "mount")]
|
||||
#[derive(Debug, Parser)]
|
||||
pub(crate) struct MountCommand {
|
||||
/// The directory
|
||||
|
|
|
@ -6,19 +6,22 @@ use std::{
|
|||
|
||||
use clap::Parser;
|
||||
|
||||
use args::{DecryptCommand, LsCommand, MountCommand};
|
||||
use args::{DecryptCommand, LsCommand};
|
||||
use rustcryptfs_lib::GocryptFs;
|
||||
|
||||
#[cfg(feature = "mount")]
|
||||
use args::MountCommand;
|
||||
|
||||
mod args;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::init();
|
||||
let args = args::Args::parse();
|
||||
log::debug!("{:?}", args);
|
||||
|
||||
match &args.command {
|
||||
args::Commands::Decrypt(c) => decrypt_file(c),
|
||||
args::Commands::Ls(c) => ls(c),
|
||||
#[cfg(feature = "mount")]
|
||||
args::Commands::Mount(c) => mount(c),
|
||||
}
|
||||
}
|
||||
|
@ -116,9 +119,9 @@ fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "mount")]
|
||||
fn mount(mount: &MountCommand) -> anyhow::Result<()> {
|
||||
use anyhow::Context;
|
||||
use rustcryptfs_fuse::EncryptedFs;
|
||||
|
||||
let password = if let Some(password) = &mount.password {
|
||||
password.clone()
|
||||
|
@ -126,14 +129,14 @@ fn mount(mount: &MountCommand) -> anyhow::Result<()> {
|
|||
rpassword::prompt_password("Your password: ")?
|
||||
};
|
||||
|
||||
let fs = EncryptedFs::new(&mount.path, &password)?;
|
||||
|
||||
fs.mount(&mount.mountpoint)
|
||||
rustcryptfs_mount::mount(&mount.path, &mount.mountpoint, &password)
|
||||
.context("Failed to run fuse fs")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[cfg(feature = "mount")]
|
||||
fn mount(mount: &MountCommand) -> anyhow::Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue