Fix and simplify open() code
This commit is contained in:
parent
e594fad962
commit
6283f7cc6f
@ -43,7 +43,14 @@ pub async fn handle_command_stream(
|
|||||||
send_bare_message(&mut tx, &file_access.lookup(dir_vnode, name).await?).await?;
|
send_bare_message(&mut tx, &file_access.lookup(dir_vnode, name).await?).await?;
|
||||||
}
|
}
|
||||||
DataCommand::OpenFile { vnode, mode } => {
|
DataCommand::OpenFile { vnode, mode } => {
|
||||||
send_bare_message(&mut tx, &file_access.open(vnode, mode).await?).await?;
|
send_bare_message(
|
||||||
|
&mut tx,
|
||||||
|
&file_access
|
||||||
|
.open(vnode, mode)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(error_to_response),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
DataCommand::ReleaseFile { file_handle } => {
|
DataCommand::ReleaseFile { file_handle } => {
|
||||||
send_bare_message(&mut tx, &file_access.release(file_handle).await?).await?;
|
send_bare_message(&mut tx, &file_access.release(file_handle).await?).await?;
|
||||||
|
@ -498,11 +498,9 @@ impl FileAccess {
|
|||||||
/// Symlink safety:
|
/// Symlink safety:
|
||||||
/// Safe — uses O_NOFOLLOW after dereferencing safe symlinks.
|
/// Safe — uses O_NOFOLLOW after dereferencing safe symlinks.
|
||||||
pub async fn open(&self, vnode: VnodeId, mode: OpenMode) -> anyhow::Result<DataResponse<u32>> {
|
pub async fn open(&self, vnode: VnodeId, mode: OpenMode) -> anyhow::Result<DataResponse<u32>> {
|
||||||
match self
|
let path = self
|
||||||
.resolve_vnode_including_follow_symlinks_safely_best_effort(vnode)
|
.resolve_vnode_including_follow_symlinks_safely_best_effort(vnode)
|
||||||
.await
|
.await?;
|
||||||
{
|
|
||||||
Ok(path) => {
|
|
||||||
let mut open_options = OpenOptions::new();
|
let mut open_options = OpenOptions::new();
|
||||||
|
|
||||||
// IMPORTANT — Don't follow symlinks
|
// IMPORTANT — Don't follow symlinks
|
||||||
@ -522,8 +520,7 @@ impl FileAccess {
|
|||||||
}
|
}
|
||||||
// TODO truncate?
|
// TODO truncate?
|
||||||
|
|
||||||
match open_options.open(&path).await {
|
let file = open_options.open(&path).await?;
|
||||||
Ok(file) => {
|
|
||||||
// TODO offset & append files: how does that work?
|
// TODO offset & append files: how does that work?
|
||||||
let handle = Arc::new(RwLock::new(FileHandle { file, offset: 0 }));
|
let handle = Arc::new(RwLock::new(FileHandle { file, offset: 0 }));
|
||||||
|
|
||||||
@ -537,16 +534,6 @@ impl FileAccess {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(DataResponse::Success(file_handle))
|
Ok(DataResponse::Success(file_handle))
|
||||||
}
|
}
|
||||||
Err(error) => Ok(io_error_to_response(
|
|
||||||
error,
|
|
||||||
EFAULT,
|
|
||||||
&format!("open {:?}", path),
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(response) => Ok(response),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Symlink safety:
|
/// Symlink safety:
|
||||||
/// No paths are touched during this operation.
|
/// No paths are touched during this operation.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user