Skip to content

Commit

Permalink
rename release_handle to release
Browse files Browse the repository at this point in the history
  • Loading branch information
radumarias committed Apr 25, 2024
1 parent 8c7f546 commit 434cd12
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rencfs"
description = "An encrypted file system that mounts with FUSE on Linux. It can be used to create encrypted directories."
version = "0.1.33"
version = "0.1.34"
edition = "2021"
license = "Apache-2.0"
authors = ["Radu Marias <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion src/encryptedfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl EncryptedFs {
Ok(buf.len())
}

pub fn release_handle(&mut self, handle: u64) -> FsResult<()> {
pub fn release(&mut self, handle: u64) -> FsResult<()> {
if handle == 0 {
// in case of directory or if the file was crated without being opened we don't use handle
return Ok(());
Expand Down
40 changes: 20 additions & 20 deletions src/encryptedfs/encryptedfs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ fn test_write_all() {
let data = "test-42";
fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
assert_eq!(data, read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs));
let attr = fs.get_inode(attr.ino).unwrap();
assert_eq!(data.len() as u64, attr.size);
Expand All @@ -496,15 +496,15 @@ fn test_write_all() {
let fh = fs.open(attr.ino, false, true).unwrap();
fs.write_all(attr.ino, 5, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
assert_eq!(data, &read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs)[5..]);

// offset after file end
let data = "37";
let fh = fs.open(attr.ino, false, true).unwrap();
fs.write_all(attr.ino, 42, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
assert_eq!(format!("test-37{}37", "\0".repeat(35)), read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs));

// offset before current position, several blocks
Expand All @@ -519,7 +519,7 @@ fn test_write_all() {
let data2 = "02";
fs.write_all(attr.ino, 8, data2.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
assert_eq!("test-01-02-42", &read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs));

// write before current position then write to the end, also check it preserves the content from
Expand All @@ -531,7 +531,7 @@ fn test_write_all() {
fs.write_all(attr.ino, 5, b"37", fh).unwrap();
fs.write_all(attr.ino, data.len() as u64, b"-42", fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let new_content = read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs);
assert_eq!("test-37-37-42", new_content);

Expand All @@ -557,7 +557,7 @@ fn test_read() {
let mut buf = [0; 7];
fs.write_all(attr.ino, 0, data, fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr.ino, true, false).unwrap();
let len = fs.read(attr.ino, 0, &mut buf, fh).unwrap();
assert_eq!(len, 7);
Expand All @@ -573,7 +573,7 @@ fn test_read() {
let fh = fs.open(attr.ino, false, true).unwrap();
fs.write_all(attr.ino, 0, data, fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr.ino, true, false).unwrap();
fs.read(attr.ino, 5, &mut buf, fh).unwrap();
assert_eq!(b"37", &buf);
Expand All @@ -589,14 +589,14 @@ fn test_read() {
let data = "test-42";
fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr.ino, true, false).unwrap();
fs.read(attr.ino, 0, &mut [0_u8; 1], fh).unwrap();
let fh_2 = fs.open(attr.ino, false, true).unwrap();
let new_data = "37";
fs.write_all(attr.ino, 5, new_data.as_bytes(), fh_2).unwrap();
fs.flush(fh_2).unwrap();
fs.release_handle(fh_2).unwrap();
fs.release(fh_2).unwrap();
let mut buf = [0_u8; 2];
fs.read(attr.ino, 5, &mut buf, fh).unwrap();
assert_eq!(new_data, String::from_utf8(buf.to_vec()).unwrap());
Expand All @@ -607,14 +607,14 @@ fn test_read() {
let data = "test-42-37";
fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr.ino, true, false).unwrap();
fs.read(attr.ino, 8, &mut [0_u8; 1], fh).unwrap();
let fh_2 = fs.open(attr.ino, false, true).unwrap();
let new_data = "37";
fs.write_all(attr.ino, 5, new_data.as_bytes(), fh_2).unwrap();
fs.flush(fh_2).unwrap();
fs.release_handle(fh_2).unwrap();
fs.release(fh_2).unwrap();
let mut buf = [0_u8; 2];
fs.read(attr.ino, 5, &mut buf, fh).unwrap();
assert_eq!(new_data, String::from_utf8(buf.to_vec()).unwrap());
Expand All @@ -625,14 +625,14 @@ fn test_read() {
let data = "test-42-37";
fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr.ino, true, false).unwrap();
fs.read(attr.ino, 7, &mut [0_u8; 1], fh).unwrap();
let fh_2 = fs.open(attr.ino, false, true).unwrap();
let new_data = "37";
fs.write_all(attr.ino, 5, new_data.as_bytes(), fh_2).unwrap();
fs.flush(fh_2).unwrap();
fs.release_handle(fh_2).unwrap();
fs.release(fh_2).unwrap();
let mut buf = [0_u8; 2];
fs.read(attr.ino, 8, &mut buf, fh).unwrap();
assert_eq!(new_data, String::from_utf8(buf.to_vec()).unwrap());
Expand All @@ -656,7 +656,7 @@ fn test_truncate() {
let data = "test-42";
fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();

// size increase, preserve opened writer content
let fh = fs.open(attr.ino, false, true).unwrap();
Expand All @@ -665,7 +665,7 @@ fn test_truncate() {
fs.truncate(attr.ino, 10).unwrap();
assert_eq!(10, fs.get_inode(attr.ino).unwrap().size);
assert_eq!(format!("test-37{}", "\0".repeat(3)), read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs));
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();

// size doesn't change
fs.truncate(attr.ino, 10).unwrap();
Expand All @@ -679,7 +679,7 @@ fn test_truncate() {
fs.truncate(attr.ino, 4).unwrap();
assert_eq!(4, fs.get_inode(attr.ino).unwrap().size);
assert_eq!("37st", read_to_string(fs.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()), &fs));
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();

// size decrease to 0
fs.truncate(attr.ino, 0).unwrap();
Expand All @@ -698,15 +698,15 @@ fn test_copy_file_range() {
let data = "test-42";
fs.write_all(attr_1.ino, 0, data.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr_1.ino, true, false).unwrap();
let test_file_2 = "test-file-2";
let (fh2, attr_2) = fs.create_nod(ROOT_INODE, test_file_2, create_attr_from_type(FileType::RegularFile), true, true).unwrap();

// whole file
let len = fs.copy_file_range(attr_1.ino, 0, attr_2.ino, 0, 7, fh, fh2).unwrap();
fs.flush(fh2).unwrap();
fs.release_handle(fh2).unwrap();
fs.release(fh2).unwrap();
assert_eq!(len, 7);
let mut buf = [0; 7];
let fh = fs.open(attr_2.ino, true, false).unwrap();
Expand All @@ -718,12 +718,12 @@ fn test_copy_file_range() {
let fh = fs.open(attr_1.ino, false, true).unwrap();
fs.write_all(attr_1.ino, 7, data_37.as_bytes(), fh).unwrap();
fs.flush(fh).unwrap();
fs.release_handle(fh).unwrap();
fs.release(fh).unwrap();
let fh = fs.open(attr_1.ino, true, false).unwrap();
let fh_2 = fs.open(attr_2.ino, false, true).unwrap();
let len = fs.copy_file_range(attr_1.ino, 7, attr_2.ino, 5, 2, fh, fh_2).unwrap();
fs.flush(fh_2).unwrap();
fs.release_handle(fh_2).unwrap();
fs.release(fh_2).unwrap();
assert_eq!(len, 2);
let fh = fs.open(attr_2.ino, true, false).unwrap();
fs.read(attr_2.ino, 0, &mut buf, fh).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/encryptedfs_fuse3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ impl Filesystem for EncryptedFsFuse3 {

let is_write_handle = self.get_fs().borrow().is_write_handle(fh);

if let Err(err) = self.get_fs().borrow_mut().release_handle(fh) {
if let Err(err) = self.get_fs().borrow_mut().release(fh) {
error!(err = %err, "release_handle");
return Err(EIO.into());
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
//! let data = "Hello, world!";
//! fs.write_all(attr.ino, 0, data.as_bytes(), fh).unwrap();
//! fs.flush(fh).unwrap();
//! fs.release_handle(fh).unwrap();
//! fs.release(fh).unwrap();
//! let fh = fs.open(attr.ino, true, false).unwrap();
//! let mut buf = vec![0; data.len()];
//! fs.read(attr.ino, 0, &mut buf, fh).unwrap();
//! fs.release_handle(fh).unwrap();
//! fs.release(fh).unwrap();
//! assert_eq!(data, String::from_utf8(buf).unwrap());
//! fs::remove_dir_all(data_dir).unwrap();
//!
Expand Down

0 comments on commit 434cd12

Please sign in to comment.