From a717ed7e7526777104d27a0a3ecf0381b99e39cd Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 22 Nov 2021 00:38:04 +0000 Subject: [PATCH] update changelogs --- Cargo.toml | 2 -- actix-files/CHANGES.md | 4 ++++ actix-files/src/chunked.rs | 24 +++++++----------------- actix-files/src/lib.rs | 13 ++++++------- actix-files/src/named.rs | 27 +++++++++++++-------------- actix-files/src/service.rs | 2 +- actix-http-test/CHANGES.md | 3 +++ actix-test/CHANGES.md | 3 +++ 8 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f1587f84..537d1b5fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,8 +143,6 @@ actix-web-actors = { path = "actix-web-actors" } actix-web-codegen = { path = "actix-web-codegen" } awc = { path = "awc" } -actix-rt = { git = "https://github.com/actix/actix-net.git" } - [[test]] name = "test_server" required-features = ["compress-brotli", "compress-gzip", "compress-zstd", "cookies"] diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index aadcd062e..7da775607 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -2,7 +2,11 @@ ## Unreleased - 2021-xx-xx * Add crate feature `experimental-io-uring`, enabling async file I/O to be utilized. This feature is only available on Linux OSes with recent kernel versions. This feature is semver-exempt. [#2408] +* Add `NamedFile::open_async`. [#2408] * Fix 304 Not Modified responses to omit the Content-Length header, as per the spec. [#2453] +* The `Responder` impl for `NamedFile` now has a boxed future associated type. [#2408] +* The `Service` impl for `NamedFileService` now has a boxed future associated type. [#2408] +* Add `impl Clone` for `FilesService`. [#2408] [#2408]: https://github.com/actix/actix-web/pull/2408 [#2453]: https://github.com/actix/actix-web/pull/2453 diff --git a/actix-files/src/chunked.rs b/actix-files/src/chunked.rs index 4a47a8b53..fbb46e417 100644 --- a/actix-files/src/chunked.rs +++ b/actix-files/src/chunked.rs @@ -14,9 +14,8 @@ use pin_project_lite::pin_project; use super::named::File; pin_project! { + /// Adapter to read a `std::file::File` in chunks. #[doc(hidden)] - /// A helper created from a `std::fs::File` which reads the file - /// chunk-by-chunk on a `ThreadPool`. pub struct ChunkedReadFile { size: u64, offset: u64, @@ -32,13 +31,8 @@ pin_project! { #[project = ChunkedReadFileStateProj] #[project_replace = ChunkedReadFileStateProjReplace] enum ChunkedReadFileState { - File { - file: Option, - }, - Future { - #[pin] - fut: Fut - } + File { file: Option, }, + Future { #[pin] fut: Fut }, } } @@ -47,13 +41,8 @@ pin_project! { #[project = ChunkedReadFileStateProj] #[project_replace = ChunkedReadFileStateProjReplace] enum ChunkedReadFileState { - File { - file: Option<(File, BytesMut)>, - }, - Future { - #[pin] - fut: Fut - } + File { file: Option<(File, BytesMut)> }, + Future { #[pin] fut: Fut }, } } @@ -88,7 +77,7 @@ async fn chunked_read_file_callback( offset: u64, max_bytes: usize, ) -> Result<(File, Bytes), Error> { - use io::{Read, Seek}; + use io::{Read as _, Seek as _}; let res = actix_web::rt::task::spawn_blocking(move || { let mut buf = Vec::with_capacity(max_bytes); @@ -117,6 +106,7 @@ async fn chunked_read_file_callback( mut bytes_mut: BytesMut, ) -> io::Result<(File, Bytes, BytesMut)> { bytes_mut.reserve(max_bytes); + let (res, mut bytes_mut) = file.read_at(bytes_mut, offset).await; let n_bytes = res?; diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 100c84c59..3af5282f1 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -33,12 +33,12 @@ mod path_buf; mod range; mod service; -pub use crate::chunked::ChunkedReadFile; -pub use crate::directory::Directory; -pub use crate::files::Files; -pub use crate::named::NamedFile; -pub use crate::range::HttpRange; -pub use crate::service::FilesService; +pub use self::chunked::ChunkedReadFile; +pub use self::directory::Directory; +pub use self::files::Files; +pub use self::named::NamedFile; +pub use self::range::HttpRange; +pub use self::service::FilesService; use self::directory::{directory_listing, DirectoryRenderer}; use self::error::FilesError; @@ -81,7 +81,6 @@ mod tests { }; use super::*; - use crate::named::File; #[actix_web::test] diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index 7e91bf2b6..547048bbd 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -90,7 +90,7 @@ impl fmt::Debug for NamedFile { "file", #[cfg(feature = "experimental-io-uring")] { - &"File" + &"tokio_uring::File" }, #[cfg(not(feature = "experimental-io-uring"))] { @@ -120,7 +120,6 @@ impl NamedFile { /// `ContentDisposition` headers. /// /// # Examples - /// /// ```ignore /// use actix_files::NamedFile; /// use std::io::{self, Write}; @@ -194,12 +193,14 @@ impl NamedFile { let fd = file.as_raw_fd(); - // SAFETY: fd is borrowed and lives longer than the unsafe block. + // SAFETY: fd is borrowed and lives longer than the unsafe block unsafe { - let fs = std::fs::File::from_raw_fd(fd); - let res = fs.metadata(); - std::mem::forget(fs); - res? + let file = std::fs::File::from_raw_fd(fd); + let md = file.metadata(); + // SAFETY: forget the fd before exiting block in success or error case but don't + // run destructor (that would close file handle) + std::mem::forget(file); + md? } } }; @@ -224,10 +225,8 @@ impl NamedFile { /// Attempts to open a file in read-only mode. /// /// # Examples - /// /// ``` /// use actix_files::NamedFile; - /// /// let file = NamedFile::open("foo.txt"); /// ``` pub fn open>(path: P) -> io::Result { @@ -237,11 +236,12 @@ impl NamedFile { /// Attempts to open a file asynchronously in read-only mode. /// - /// # Examples + /// When the `experimental-io-uring` crate feature is enabled, this will be async. + /// Otherwise, it will be just like [`open`][Self::open]. /// + /// # Examples /// ``` /// use actix_files::NamedFile; - /// /// # async fn open() { /// let file = NamedFile::open_async("foo.txt").await.unwrap(); /// # } @@ -271,7 +271,6 @@ impl NamedFile { /// Retrieve the path of this file. /// /// # Examples - /// /// ``` /// # use std::io; /// use actix_files::NamedFile; @@ -584,13 +583,13 @@ fn none_match(etag: Option<&header::EntityTag>, req: &HttpRequest) -> bool { impl Deref for NamedFile { type Target = File; - fn deref(&self) -> &File { + fn deref(&self) -> &Self::Target { &self.file } } impl DerefMut for NamedFile { - fn deref_mut(&mut self) -> &mut File { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.file } } diff --git a/actix-files/src/service.rs b/actix-files/src/service.rs index 1215ef23f..f6e1c2e11 100644 --- a/actix-files/src/service.rs +++ b/actix-files/src/service.rs @@ -17,7 +17,7 @@ use crate::{ /// Assembled file serving service. #[derive(Clone)] -pub struct FilesService(pub Rc); +pub struct FilesService(pub(crate) Rc); impl Deref for FilesService { type Target = FilesServiceInner; diff --git a/actix-http-test/CHANGES.md b/actix-http-test/CHANGES.md index ea00acb0c..3356f5334 100644 --- a/actix-http-test/CHANGES.md +++ b/actix-http-test/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Fix compatibility with experimental `io-uring` feature of `actix-rt`. [#2408] + +[#2408]: https://github.com/actix/actix-web/pull/2408 ## 3.0.0-beta.6 - 2021-11-15 diff --git a/actix-test/CHANGES.md b/actix-test/CHANGES.md index 5c22139ae..78fd4e4ca 100644 --- a/actix-test/CHANGES.md +++ b/actix-test/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Fix compatibility with experimental `io-uring` feature of `actix-rt`. [#2408] + +[#2408]: https://github.com/actix/actix-web/pull/2408 ## 0.1.0-beta.6 - 2021-11-15