Clean up lookup()
This commit is contained in:
parent
6283f7cc6f
commit
28971fb424
@ -40,7 +40,14 @@ pub async fn handle_command_stream(
|
||||
send_bare_message(&mut tx, &file_access.releasedir(dir_handle).await?).await?;
|
||||
}
|
||||
DataCommand::Lookup { dir_vnode, name } => {
|
||||
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
|
||||
.unwrap_or_else(error_to_response),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
DataCommand::OpenFile { vnode, mode } => {
|
||||
send_bare_message(
|
||||
|
@ -459,8 +459,9 @@ impl FileAccess {
|
||||
name: String,
|
||||
) -> anyhow::Result<DataResponse<FileMetadata>> {
|
||||
// TODO switch to the easier ones and then handle I/O errors in the callsite
|
||||
match self.resolve_vnode(dir_vnode).await {
|
||||
Ok(dir_path) => {
|
||||
let dir_path = self
|
||||
.resolve_vnode_including_follow_symlinks_safely_best_effort(dir_vnode)
|
||||
.await?;
|
||||
let lookup_path = dir_path.join(name);
|
||||
// TODO check the security of this: make sure you can't escape the root
|
||||
match lookup_path.absolutize_virtually(&self.client_info.root) {
|
||||
@ -470,18 +471,15 @@ impl FileAccess {
|
||||
match self.read_metadata(the_path.borrow(), VnodeId(0)).await {
|
||||
Ok(mut metadata) => {
|
||||
// Now allocate a Vnode and fill it in.
|
||||
let vnode_id =
|
||||
self.allocate_vnode(the_path.to_path_buf()).await?;
|
||||
let vnode_id = self.allocate_vnode(the_path.to_path_buf()).await?;
|
||||
metadata.ino = vnode_id;
|
||||
|
||||
// Respond with the getattr-style response.
|
||||
DataResponse::Success(metadata)
|
||||
}
|
||||
Err(error) => io_error_to_response(
|
||||
error,
|
||||
ENOENT,
|
||||
&format!("lookup {:?}", the_path),
|
||||
),
|
||||
Err(error) => {
|
||||
io_error_to_response(error, ENOENT, &format!("lookup {:?}", the_path))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -491,9 +489,6 @@ impl FileAccess {
|
||||
}),
|
||||
}
|
||||
}
|
||||
Err(response) => Ok(response),
|
||||
}
|
||||
}
|
||||
|
||||
/// Symlink safety:
|
||||
/// Safe — uses O_NOFOLLOW after dereferencing safe symlinks.
|
||||
|
Loading…
x
Reference in New Issue
Block a user