Merge remote-tracking branch 'origin/main' into pch/wasi_error_handling
This commit is contained in:
@@ -6,12 +6,12 @@ use crate::sys::osfile::OsFile;
|
||||
use crate::sys::AsFile;
|
||||
use crate::wasi::types;
|
||||
use crate::Result;
|
||||
use log::trace;
|
||||
use std::convert::TryInto;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
use std::os::windows::prelude::{AsRawHandle, FromRawHandle};
|
||||
use std::path::Path;
|
||||
use tracing::trace;
|
||||
use winx::file::{AccessMode, FileModeInformation, Flags};
|
||||
|
||||
pub(crate) fn fdstat_get(file: &File) -> Result<types::Fdflags> {
|
||||
|
||||
@@ -47,7 +47,7 @@ fn concatenate<P: AsRef<Path>>(file: &OsDir, path: P) -> Result<PathBuf> {
|
||||
// components with `out_path`
|
||||
let out_path = PathBuf::from(strip_extended_prefix(out_path));
|
||||
|
||||
log::debug!("out_path={:?}", out_path);
|
||||
tracing::debug!(out_path = tracing::field::debug(&out_path));
|
||||
|
||||
Ok(out_path)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ pub(crate) fn readlinkat(dirfd: &OsDir, s_path: &str) -> Result<String> {
|
||||
Err(e) => e,
|
||||
};
|
||||
if let Some(code) = err.raw_os_error() {
|
||||
log::debug!("readlinkat error={:?}", code);
|
||||
tracing::debug!("readlinkat error={:?}", code);
|
||||
if code as u32 == winerror::ERROR_INVALID_NAME {
|
||||
if s_path.ends_with('/') {
|
||||
// strip "/" and check if exists
|
||||
@@ -171,7 +171,10 @@ pub(crate) fn link(
|
||||
let new_path = concatenate(new_dirfd, new_path)?;
|
||||
if follow_symlinks {
|
||||
// in particular, this will return an error if the target path doesn't exist
|
||||
log::debug!("Following symlinks for path: {:?}", old_path);
|
||||
tracing::debug!(
|
||||
old_path = tracing::field::display(old_path.display()),
|
||||
"Following symlinks"
|
||||
);
|
||||
old_path = fs::canonicalize(&old_path).map_err(|e| match e.raw_os_error() {
|
||||
// fs::canonicalize under Windows will return:
|
||||
// * ERROR_FILE_NOT_FOUND, if it encounters a dangling symlink
|
||||
@@ -185,7 +188,7 @@ pub(crate) fn link(
|
||||
Err(e) => e,
|
||||
};
|
||||
if let Some(code) = err.raw_os_error() {
|
||||
log::debug!("path_link at fs::hard_link error code={:?}", code);
|
||||
tracing::debug!("path_link at fs::hard_link error code={:?}", code);
|
||||
if code as u32 == winerror::ERROR_ACCESS_DENIED {
|
||||
// If an attempt is made to create a hard link to a directory, POSIX-compliant
|
||||
// implementations of link return `EPERM`, but `ERROR_ACCESS_DENIED` is converted
|
||||
@@ -249,7 +252,7 @@ pub(crate) fn open(
|
||||
}
|
||||
Err(err) => match err.raw_os_error() {
|
||||
Some(code) => {
|
||||
log::debug!("path_open at symlink_metadata error code={:?}", code);
|
||||
tracing::debug!("path_open at symlink_metadata error code={:?}", code);
|
||||
match code as u32 {
|
||||
winerror::ERROR_FILE_NOT_FOUND => {
|
||||
// file not found, let it proceed to actually
|
||||
@@ -264,7 +267,7 @@ pub(crate) fn open(
|
||||
};
|
||||
}
|
||||
None => {
|
||||
log::debug!("Inconvertible OS error: {}", err);
|
||||
tracing::debug!("Inconvertible OS error: {}", err);
|
||||
return Err(Error::Io);
|
||||
}
|
||||
},
|
||||
@@ -354,7 +357,7 @@ pub(crate) fn rename(
|
||||
};
|
||||
match err.raw_os_error() {
|
||||
Some(code) => {
|
||||
log::debug!("path_rename at rename error code={:?}", code);
|
||||
tracing::debug!("path_rename at rename error code={:?}", code);
|
||||
match code as u32 {
|
||||
winerror::ERROR_ACCESS_DENIED => {
|
||||
// So most likely dealing with new_path == dir.
|
||||
@@ -386,7 +389,7 @@ pub(crate) fn rename(
|
||||
Err(err.into())
|
||||
}
|
||||
None => {
|
||||
log::debug!("Inconvertible OS error: {}", err);
|
||||
tracing::debug!("Inconvertible OS error: {}", err);
|
||||
Err(Error::Io)
|
||||
}
|
||||
}
|
||||
@@ -418,7 +421,7 @@ pub(crate) fn symlink(old_path: &str, new_dirfd: &OsDir, new_path_: &str) -> Res
|
||||
};
|
||||
match err.raw_os_error() {
|
||||
Some(code) => {
|
||||
log::debug!("path_symlink at symlink_file error code={:?}", code);
|
||||
tracing::debug!("path_symlink at symlink_file error code={:?}", code);
|
||||
match code as u32 {
|
||||
// If the target contains a trailing slash, the Windows API returns
|
||||
// ERROR_INVALID_NAME (which corresponds to ENOENT) instead of
|
||||
@@ -443,7 +446,7 @@ pub(crate) fn symlink(old_path: &str, new_dirfd: &OsDir, new_path_: &str) -> Res
|
||||
Err(err.into())
|
||||
}
|
||||
None => {
|
||||
log::debug!("Inconvertible OS error: {}", err);
|
||||
tracing::debug!("Inconvertible OS error: {}", err);
|
||||
Err(Error::Io)
|
||||
}
|
||||
}
|
||||
@@ -469,7 +472,7 @@ pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> {
|
||||
};
|
||||
match err.raw_os_error() {
|
||||
Some(code) => {
|
||||
log::debug!("path_unlink_file at symlink_file error code={:?}", code);
|
||||
tracing::debug!("path_unlink_file at symlink_file error code={:?}", code);
|
||||
if code as u32 == winerror::ERROR_ACCESS_DENIED {
|
||||
// try unlinking a dir symlink instead
|
||||
return fs::remove_dir(path).map_err(Into::into);
|
||||
@@ -478,7 +481,7 @@ pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> {
|
||||
Err(err.into())
|
||||
}
|
||||
None => {
|
||||
log::debug!("Inconvertible OS error: {}", err);
|
||||
tracing::debug!("Inconvertible OS error: {}", err);
|
||||
Err(Error::Io)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ use crate::sys::AsFile;
|
||||
use crate::wasi::types;
|
||||
use crate::{Error, Result};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{debug, error, trace, warn};
|
||||
use std::convert::TryInto;
|
||||
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError};
|
||||
use std::sync::Mutex;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use tracing::{debug, error, trace, warn};
|
||||
|
||||
struct StdinPoll {
|
||||
request_tx: Sender<()>,
|
||||
@@ -245,7 +245,7 @@ pub(crate) fn oneoff(
|
||||
handle_error_event(event, types::Errno::Notsup, events);
|
||||
}
|
||||
} else {
|
||||
log::error!("can poll FdEvent for OS resources only");
|
||||
tracing::error!("can poll FdEvent for OS resources only");
|
||||
return Err(Error::Badf);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user