Skip to content

Commit

Permalink
run doctests in GH
Browse files Browse the repository at this point in the history
fixed examples in doc
  • Loading branch information
radumarias committed Apr 25, 2024
1 parent 29ae152 commit 1eaf1ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --tests --lib --verbose
- name: Run doctests
run: cargo test --package rencfs --doc --verbose
23 changes: 13 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//!
//! # Usage
//!
//! It can be used a library to create an encrypted file system or mount it with FUSE.\
//! \
//! It can be used a library to create an encrypted file system or mount it with FUSE.
//!
//! This crate also contains [main.rs] file that can be used as an example on how to run the encrypted file system from the command line.
//! Documentation for that can be found [here](https://crates.io/crates/encryptedfs).
//!
Expand All @@ -17,14 +17,14 @@
//!
//! # Example
//!
//! ```
//! ```no_run
//! use std::ffi::OsStr;
//! use fuse3::MountOptions;
//! use fuse3::raw::Session;
//! use rencfs::encryptedfs::Cipher;
//! use rencfs::encryptedfs_fuse3::EncryptedFsFuse3;
//!
//! async fn run_fuse(mountpoint: String, data_dir: &str, password: &str, cipher: Cipher, derive_key_hash_rounds: u32,
//! async fn run_fuse(mountpoint: &str, data_dir: &str, password: &str, cipher: Cipher, derive_key_hash_rounds: u32,
//! allow_root: bool, allow_other: bool, direct_io: bool, suid_support: bool) {
//! let uid = unsafe { libc::getuid() };
//! let gid = unsafe { libc::getgid() };
Expand All @@ -35,7 +35,7 @@
//! .allow_root(allow_root)
//! .allow_other(allow_other)
//! .clone();
//! let mount_path = OsStr::new(mountpoint.as_str());
//! let mount_path = OsStr::new(mountpoint);
//!
//! Session::new(mount_options)
//! .mount_with_unprivileged(EncryptedFsFuse3::new(&data_dir, &password, cipher, derive_key_hash_rounds, direct_io, suid_support).unwrap(), mount_path)
Expand Down Expand Up @@ -66,22 +66,25 @@
//! # Example
//!
//! ```
//! use std::fs;
//! use rencfs::encryptedfs::{EncryptedFs, FileAttr, FileType};
//! const ROOT_INODE: u64 = 1;
//! let data_dir = "/tmp/encryptedfs";
//! let data_dir = "/tmp/rencfs_data_test";
//! fs::remove_dir_all(data_dir).unwrap();
//! let password = "password";
//! let cipher = encryptedfs::encryptedfs::Cipher::ChaCha20;
//! let cipher = rencfs::encryptedfs::Cipher::ChaCha20;
//! let derive_key_hash_rounds = 1000;
//! let mut fs = EncryptedFs::new(data_dir, password, cipher, derive_key_hash_rounds).unwrap();
//!
//! let (fh, attr) = fs.create_nod(ROOT_INODE, "file1", create_attr_from_type(FileType::RegularFile), false, true).unwrap();
//! let data = "Hello, world!";
//! fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
//! fs.flush(fh).unwrap();
//! fs.release(fh).unwrap();
//! let fh = fs.open(ROOT_INODE, true, false).unwrap();
//! fs.release_handle(fh).unwrap();
//! let fh = fs.open(attr.ino, true, false).unwrap();
//! let mut buf = vec![0; data.len()];
//! fs.read(ROOT_INODE, 0, &mut buf, fh).unwrap();
//! fs.read(attr.ino, 0, &mut buf, fh).unwrap();
//! fs.release_handle(fh).unwrap();
//! assert_eq!(data, String::from_utf8(buf).unwrap());
//!
//! fn create_attr(ino: u64, file_type: FileType) -> FileAttr {
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ async fn run_normal(matches: ArgMatches, data_dir: &String, cipher: Cipher, deri
}).unwrap();
}

run_fuse(mountpoint, &data_dir, &password, cipher, derive_key_hash_rounds,
run_fuse(&mountpoint, &data_dir, &password, cipher, derive_key_hash_rounds,
matches.get_flag("allow-root"), matches.get_flag("allow-other"),
matches.get_flag("direct-io"), matches.get_flag("suid")).await;
}

#[instrument]
async fn run_fuse(mountpoint: String, data_dir: &str, password: &str, cipher: Cipher, derive_key_hash_rounds: u32,
async fn run_fuse(mountpoint: &str, data_dir: &str, password: &str, cipher: Cipher, derive_key_hash_rounds: u32,
allow_root: bool, allow_other: bool, direct_io: bool, suid_support: bool) {
let uid = unsafe { libc::getuid() };
let gid = unsafe { libc::getgid() };
Expand All @@ -282,10 +282,10 @@ async fn run_fuse(mountpoint: String, data_dir: &str, password: &str, cipher: Ci
allow_root(allow_root).
allow_other(allow_other)
.clone();
let mount_path = OsStr::new(mountpoint.as_str());
let mount_path = OsStr::new(mountpoint);

info!("Mounting FUSE filesystem");
match EncryptedFsFuse3::new(&data_dir, &password, cipher, derive_key_hash_rounds, direct_io, suid_support) {
match EncryptedFsFuse3::new(data_dir, password, cipher, derive_key_hash_rounds, direct_io, suid_support) {
Err(FsError::InvalidPassword) => {
error!("Cannot decrypt data, maybe the password is wrong");
println!("Cannot decrypt data, maybe the password is wrong");
Expand Down

0 comments on commit 1eaf1ba

Please sign in to comment.