##// END OF EJS Templates
hgweb: skip logging ConnectionAbortedError...
hgweb: skip logging ConnectionAbortedError Not stacktracing on `ConnectionResetError` was added in 6bbb12cba5a8 (though it was spelled differently for py2 support), but for some reason Windows occasionally triggers a `ConnectionAbortedError` here across various *.t files (notably `test-archive.t` and `test-lfs-serve-access.t`, but there are others). The payload that fails to send seems to be the html that describes the error to the client, so I suspect some code is seeing the error status code and closing the connection before the server gets to write this html. So don't log it, for test stability- nothing we can do anyway. FWIW, the CPython implementation of wsgihander specifically ignores these two errors, plus `BrokenPipeError`, with a comment that "we expect the client to close the connection abruptly from time to time"[1]. The `BrokenPipeError` is swallowed a level up in `do_write()`, and avoids writing the response following this stacktrace. I'm puzzled why a response is being written after these connection errors are detected- the CPython code referenced doesn't, and the connection is now broken at this point. Perhaps these errors should both be handled with the `BrokenPipeError` after the freeze. (The refactoring away from py2 compat may not be desireable in the freeze, but this is much easier to read, and obviously correct given the referenced CPython code.) I suspect this is what 6bceecb28806 was attempting to fix, but it wasn't specific about the sporadic errors it was seeing. [1] https://github.com/python/cpython/blob/b2eaa75b176e07730215d76d8dce4d63fb493391/Lib/wsgiref/handlers.py#L139

File last commit:

r51273:e2c8b30a default
r53050:891f6d56 stable
Show More
checkexec.rs
121 lines | 4.0 KiB | application/rls-services+xml | RustLexer
Arseniy Alekseyev
rhg: implement checkexec to support weird filesystems...
r50789 use std::fs;
use std::io;
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::Path;
const EXECFLAGS: u32 = 0o111;
fn is_executable(path: impl AsRef<Path>) -> Result<bool, io::Error> {
let metadata = fs::metadata(path)?;
let mode = metadata.mode();
Ok(mode & EXECFLAGS != 0)
}
fn make_executable(path: impl AsRef<Path>) -> Result<(), io::Error> {
let mode = fs::metadata(path.as_ref())?.mode();
fs::set_permissions(
path,
fs::Permissions::from_mode((mode & 0o777) | EXECFLAGS),
)?;
Ok(())
}
fn copy_mode(
src: impl AsRef<Path>,
dst: impl AsRef<Path>,
) -> Result<(), io::Error> {
let mode = match fs::symlink_metadata(src) {
Ok(metadata) => metadata.mode(),
Err(e) if e.kind() == io::ErrorKind::NotFound =>
// copymode in python has a more complicated handling of FileNotFound
// error, which we don't need because all it does is applying
// umask, which the OS already does when we mkdir.
{
return Ok(())
}
Err(e) => return Err(e),
};
fs::set_permissions(dst, fs::Permissions::from_mode(mode))?;
Ok(())
}
fn check_exec_impl(path: impl AsRef<Path>) -> Result<bool, io::Error> {
let basedir = path.as_ref().join(".hg");
let cachedir = basedir.join("wcache");
let storedir = basedir.join("store");
if !cachedir.exists() {
Arseniy Alekseyev
doc: add a few comments
r50790 // we want to create the 'cache' directory, not the '.hg' one.
// Automatically creating '.hg' directory could silently spawn
// invalid Mercurial repositories. That seems like a bad idea.
Arseniy Alekseyev
rhg: implement checkexec to support weird filesystems...
r50789 fs::create_dir(&cachedir)
.and_then(|()| {
if storedir.exists() {
copy_mode(&storedir, &cachedir)
} else {
copy_mode(&basedir, &cachedir)
}
})
.ok();
}
let leave_file: bool;
let checkdir: &Path;
let checkisexec = cachedir.join("checkisexec");
let checknoexec = cachedir.join("checknoexec");
if cachedir.is_dir() {
Arseniy Alekseyev
doc: add a few comments
r50790 // Check if both files already exist in cache and have correct
// permissions. if so, we assume that permissions work.
// If not, we delete the files and try again.
Arseniy Alekseyev
rhg: implement checkexec to support weird filesystems...
r50789 match is_executable(&checkisexec) {
Err(e) if e.kind() == io::ErrorKind::NotFound => (),
Err(e) => return Err(e),
Ok(is_exec) => {
if is_exec {
let noexec_is_exec = match is_executable(&checknoexec) {
Err(e) if e.kind() == io::ErrorKind::NotFound => {
fs::write(&checknoexec, "")?;
is_executable(&checknoexec)?
}
Err(e) => return Err(e),
Ok(exec) => exec,
};
if !noexec_is_exec {
// check-exec is exec and check-no-exec is not exec
return Ok(true);
}
fs::remove_file(&checknoexec)?;
}
fs::remove_file(&checkisexec)?;
}
}
checkdir = &cachedir;
leave_file = true;
} else {
Arseniy Alekseyev
doc: add a few comments
r50790 // no cache directory (probably because .hg doesn't exist):
// check directly in `path` and don't leave the temp file behind
Arseniy Alekseyev
rhg: implement checkexec to support weird filesystems...
r50789 checkdir = path.as_ref();
leave_file = false;
};
let tmp_file = tempfile::NamedTempFile::new_in(checkdir)?;
if !is_executable(tmp_file.path())? {
make_executable(tmp_file.path())?;
if is_executable(tmp_file.path())? {
if leave_file {
tmp_file.persist(checkisexec).ok();
}
return Ok(true);
}
}
Ok(false)
}
Georges Racinet
rustdoc: wording for checkexec...
r51273 /// This function is a Rust rewrite of the `checkexec` function from
/// `posix.py`.
///
/// Returns `true` if the filesystem supports execute permissions.
Arseniy Alekseyev
rhg: implement checkexec to support weird filesystems...
r50789 pub fn check_exec(path: impl AsRef<Path>) -> bool {
check_exec_impl(path).unwrap_or(false)
}