Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs, File and Path API #264

Open
wants to merge 18 commits into
base: Abstract_file_access_layer_111
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion examples/file_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;
use std::str::FromStr;
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
// use tokio::fs::OpenOptions;
use rencfs::crypto::fs::OpenOptions;
use rencfs::crypto::fs_api::r#async::fs::OpenOptions;
use rencfs::encryptedfs::PasswordProvider;

static ROOT_CIPHER_FS_DATA_DIR: &str = "/tmp/rencfs/file_layer/fs_cipher";
Expand Down
12 changes: 4 additions & 8 deletions examples/filesystem_dbg.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![allow(dead_code)]

use rencfs::crypto::fs::OpenOptions;
use rencfs::crypto::fs_api::r#async::fs::OpenOptions;
use rencfs::crypto::Cipher;
use rencfs::encryptedfs::{
CreateFileAttr, EncryptedFs, FileType, FsError, FsResult, PasswordProvider,
};
use shush_rs::SecretString;
use std::io::SeekFrom;
use std::path::Path;
use std::str::FromStr;
use tokio::io::{AsyncBufReadExt, AsyncSeekExt, AsyncWriteExt};

Expand All @@ -20,7 +19,6 @@ use std::sync::Arc;
async fn main() -> anyhow::Result<()> {
init_fs().await?;
let fs = get_fs().await?;

{
let mut opened_file1 = OpenOptions::new()
.write(true)
Expand All @@ -34,9 +32,7 @@ async fn main() -> anyhow::Result<()> {
fs.release(opened_file1.context.fh_write).await?;
opened_file1.seek(SeekFrom::Start(0)).await?;
}

let opened_file1 = OpenOptions::new().read(true).open(FILENAME).await?;

let reader = tokio::io::BufReader::new(opened_file1);
let mut lines = reader.lines();
while let Some(line) = lines.next_line().await? {
Expand All @@ -48,7 +44,7 @@ async fn main() -> anyhow::Result<()> {

async fn init_fs() -> anyhow::Result<()> {
OpenOptions::init_scope(
Path::new(ROOT_CIPHER_FS_DATA_DIR).to_path_buf(),
std::path::Path::new(ROOT_CIPHER_FS_DATA_DIR).to_path_buf(),
Box::new(PasswordProviderImpl {}),
Cipher::ChaCha20Poly1305,
false,
Expand All @@ -57,7 +53,7 @@ async fn init_fs() -> anyhow::Result<()> {
Ok(())
}

fn _add_create<'a>(opts: &'a mut OpenOptions, path: &Path) -> &'a mut OpenOptions {
fn _add_create<'a>(opts: &'a mut OpenOptions, path: &std::path::Path) -> &'a mut OpenOptions {
if !path.to_path_buf().exists() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we need to use crypto::fs_api::path::Path

opts.create(true);
}
Expand All @@ -66,7 +62,7 @@ fn _add_create<'a>(opts: &'a mut OpenOptions, path: &Path) -> &'a mut OpenOption

async fn cleanup() {
// todo: ignore if we delete first time when not present
let _ = tokio::fs::remove_dir_all(Path::new(ROOT_CIPHER_FS_DATA_DIR)).await;
let _ = tokio::fs::remove_dir_all(std::path::Path::new(ROOT_CIPHER_FS_DATA_DIR)).await;

// todo: seems we need to abstract also Path because exists() goes against local FS
// if file_path.exists() {
Expand Down
2 changes: 1 addition & 1 deletion src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::encryptedfs::FsResult;
use crate::{fs_util, stream_util};

pub mod buf_mut;
pub mod fs;
pub mod fs_api;
pub mod read;
pub mod write;

Expand Down
2 changes: 2 additions & 0 deletions src/crypto/fs_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod r#async;
pub mod path;
1 change: 1 addition & 0 deletions src/crypto/fs_api/async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod fs;
Loading