vfs: add VFS::read

Summary: Adding method to VFS to read file content

Reviewed By: DurhamG

Differential Revision: D27799146

fbshipit-source-id: c7e5c2dbd496d3cfd349a435225b1d44ee14cda0
This commit is contained in:
Andrey Chursin 2021-04-15 20:07:28 -07:00 committed by Facebook GitHub Bot
parent a3eb6b227a
commit 82f93150a0

View File

@ -28,6 +28,7 @@ use util::path::remove_file;
use crate::pathauditor::PathAuditor;
use minibytes::Bytes;
use once_cell::sync::Lazy;
#[derive(Clone)]
@ -289,6 +290,13 @@ impl VFS {
Ok(())
}
// Reads file content
pub fn read(&self, path: &RepoPath) -> Result<Bytes> {
let filepath = self.inner.auditor.audit(path)?;
let content = std::fs::read(filepath)?;
Ok(content.into())
}
/// Removes file, but inlike Self::remove, does not delete empty directories.
fn remove_keep_path(&self, filepath: &PathBuf) -> Result<()> {
if let Ok(metadata) = symlink_metadata(&filepath) {