Skip to content

Commit

Permalink
Refactor file import in file_cache.rs
Browse files Browse the repository at this point in the history
The commit updates file import in file_cache.rs by replacing individual usages with direct namespace access. These changes include the way the File and Error classes from the std library are accessed. The aim is to improve readability and maintainability.
  • Loading branch information
popcnt1 committed Jul 6, 2024
1 parent d568645 commit 8a6d4f7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/rooch-common/src/fs/file_cache.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use std::fs::File;
use std::io::{Error, Result};
use std::os::unix::io::AsRawFd;
use std::io::Result;
use std::path::PathBuf;

pub struct FileCacheManager {
#[cfg(target_os = "linux")]
file: File,
file: std::fs::File,
}

impl FileCacheManager {
#[cfg(target_os = "linux")]
pub fn new(file_path: PathBuf) -> Result<Self> {
let file = File::open(file_path)?;
let file = std::fs::File::open(file_path)?;
Ok(FileCacheManager { file })
}

#[cfg(target_os = "linux")]
pub fn drop_cache_range(&self, offset: u64, len: u64) -> Result<()> {
use std::os::unix::io::AsRawFd;

let fd = self.file.as_raw_fd();
let ret = unsafe {
libc::posix_fadvise(
Expand All @@ -31,7 +31,7 @@ impl FileCacheManager {
};

if ret != 0 {
return Err(Error::from_raw_os_error(ret));
return Err(std::io::Error::from_raw_os_error(ret));
}

Ok(())
Expand Down

0 comments on commit 8a6d4f7

Please sign in to comment.