radumarias / rencfs

An encrypted file system written in Rust that is mounted with FUSE on Linux. It can be used to create encrypted directories
Apache License 2.0
102 stars 21 forks source link

Refactoring of functions to reduce the number of arguments #185

Open rakurame96 opened 2 months ago

rakurame96 commented 2 months ago

This function has 8 arguments. This can be reduced to 4 or 5 arguments if identical set of arguments are contained within a structure. Filepath: /workspaces/rencfs/src/encryptedfs.rs

/// Helpful when we want to copy just some portions of the file.
    pub async fn copy_file_range(
        &self,
        src_ino: u64,
        src_offset: u64,
        dest_ino: u64,
        dest_offset: u64,
        size: usize,
        src_fh: u64,
        dest_fh: u64,
    ) -> FsResult<usize>
struct FileHandle {
       src_fh: u64,
       dest_fh: u64,
}
struct InodeMetaData {
        src_ino: u64,
        src_offset: u64,
        dest_ino: u64,
        dest_offset: u64,
}

Based on above optimisation, same function will have reduced set of arguments yet achieves the same functionality

/// Helpful when we want to copy just some portions of the file.
    pub async fn copy_file_range(
        &self,
        ino: InodeMetaData,
        size: usize,
        fh: FileHandle,
    ) -> FsResult<usize>

https://crates.io/crates/bon