diff --git a/Cargo.toml b/Cargo.toml index 05e3de22c00..7333a8d58bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ members = [ "tokio", "tokio-codec", "tokio-executor", - "tokio-fs", "tokio-io", "tokio-macros", "tokio-net", diff --git a/README.md b/README.md index fccfede46a3..32e160b7ecc 100644 --- a/README.md +++ b/README.md @@ -120,39 +120,6 @@ project. [guide]: CONTRIBUTING.md -## Project layout - -The `tokio` crate, found at the root, is primarily intended for use by -application developers. Library authors should depend on the sub crates, which -have greater guarantees of stability. - -The crates included as part of Tokio are: - -* [`tokio-executor`]: Task executors and related utilities. Includes a - single-threaded executor and a multi-threaded, work-stealing, executor. - -* [`tokio-fs`]: Filesystem (and standard in / out) APIs. - -* [`tokio-codec`]: Utilities for encoding and decoding protocol frames. - -* [`tokio-io`]: Asynchronous I/O related traits and utilities. - -* [`tokio-macros`]: Macros for usage with Tokio. - -* [`tokio-net`]: Event loop that drives I/O resources as well as TCP, UDP, and - unix domain socket apis. - -* [ `tokio-timer`]: Time related APIs. - -[`tokio-codec`]: tokio-codec -[`tokio-current-thread`]: tokio-current-thread -[`tokio-executor`]: tokio-executor -[`tokio-fs`]: tokio-fs -[`tokio-io`]: tokio-io -[`tokio-macros`]: tokio-macros -[`tokio-net`]: tokio-net -[`tokio-timer`]: tokio-timer - ## Related Projects In addition to the crates in this repository, the Tokio project also maintains diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0d7c1077a06..374df5f6bfd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -47,7 +47,6 @@ jobs: cross: true rust: beta crates: - tokio-fs: [] tokio-net: - process - signal diff --git a/ci/patch.toml b/ci/patch.toml index e615fab9bd1..49a7252f6eb 100644 --- a/ci/patch.toml +++ b/ci/patch.toml @@ -4,7 +4,6 @@ tokio = { path = "tokio" } tokio-codec = { path = "tokio-codec" } tokio-executor = { path = "tokio-executor" } -tokio-fs = { path = "tokio-fs" } tokio-io = { path = "tokio-io" } tokio-macros = { path = "tokio-macros" } tokio-net = { path = "tokio-net" } diff --git a/tokio-fs/CHANGELOG.md b/tokio-fs/CHANGELOG.md deleted file mode 100644 index 5859a5dee69..00000000000 --- a/tokio-fs/CHANGELOG.md +++ /dev/null @@ -1,61 +0,0 @@ -# 0.2.0-alpha.6 (September 30, 2019) - -- Move to `futures-*-preview 0.3.0-alpha.19` -- Move to `pin-project 0.4` - -# 0.2.0-alpha.5 (September 19, 2019) - -### Fix -- propagate flush for stdout / stderr. (#1528). - -# 0.2.0-alpha.4 (August 29, 2019) - -- Track tokio release. - -# 0.2.0-alpha.3 (August 28, 2019) - -### Changed -- Temporarily use a dedicated thread pool for all blocking operations (#1495). - -# 0.2.0-alpha.2 (August 17, 2019) - -### Changed -- Update `futures` dependency to 0.3.0-alpha.18. - -# 0.2.0-alpha.1 (August 8, 2019) - -### Changed -- Switch to `async`, `await`, and `std::future`. - -# 0.1.6 (March 1, 2019) - -### Added -- File::try_clone() (#850). -- Async equivalent of read / write file helpers being added to `std` (#896). - -# 0.1.5 (January 6, 2019) - -* Add examples to `File` API docs (#786). - -# 0.1.4 (October 23, 2018) - -* Provide `File::from_std` (#696). - -# 0.1.3 (August 6, 2018) - -* Add async equivalents to most of `std::fs` (#494). - -# 0.1.2 (July 11, 2018) - -* Add `metadata` and `File::metadata` ([#433](https://github.com/tokio-rs/tokio/pull/433), [#385](https://github.com/tokio-rs/tokio/pull/385)) -* Add `File::seek` ([#434](https://github.com/tokio-rs/tokio/pull/434)) - -# 0.1.1 (June 13, 2018) - -* Add `OpenOptions` ([#390](https://github.com/tokio-rs/tokio/pull/390)) -* Add `into_std` to `File` ([#403](https://github.com/tokio-rs/tokio/pull/403)) -* Use `tokio-codec` in examples - -# 0.1.0 (May 2, 2018) - -* Initial release diff --git a/tokio-fs/Cargo.toml b/tokio-fs/Cargo.toml deleted file mode 100644 index 77f8329aa3f..00000000000 --- a/tokio-fs/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -[package] -name = "tokio-fs" -# When releasing to crates.io: -# - Remove path dependencies -# - Update html_root_url. -# - Update doc url -# - Cargo.toml -# - Update CHANGELOG.md. -# - Create "v0.2.x" git tag. -version = "0.2.0-alpha.6" -edition = "2018" -authors = ["Tokio Contributors "] -license = "MIT" -readme = "README.md" -repository = "https://github.com/tokio-rs/tokio" -homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-fs/0.2.0-alpha.6/tokio_fs" -description = """ -Filesystem API for Tokio. -""" -keywords = ["tokio", "futures", "fs", "file", "async"] -categories = ["asynchronous", "network-programming", "filesystem"] - -[dependencies] -tokio-io = { version = "=0.2.0-alpha.6", features = ["util"], path = "../tokio-io" } -tokio-executor = { version = "=0.2.0-alpha.6", features = ["blocking"], path = "../tokio-executor" } -tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" } - -futures-core-preview = "=0.3.0-alpha.19" -futures-util-preview = "=0.3.0-alpha.19" -lazy_static = "1.3.0" - -[dev-dependencies] -tokio = { version = "=0.2.0-alpha.6", path = "../tokio" } -tokio-test = { version = "=0.2.0-alpha.6", path = "../tokio-test" } - -rand = "0.7" -tempfile = "3" - -[package.metadata.docs.rs] -all-features = true diff --git a/tokio-fs/LICENSE b/tokio-fs/LICENSE deleted file mode 100644 index cdb28b4b56a..00000000000 --- a/tokio-fs/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2019 Tokio Contributors - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/tokio-fs/README.md b/tokio-fs/README.md deleted file mode 100644 index 55a5ad481bb..00000000000 --- a/tokio-fs/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Tokio FS - -Asynchronous filesystem manipulation operations (and stdin, stdout, stderr). - -## License - -This project is licensed under the [MIT license](LICENSE). - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in Tokio by you, shall be licensed as MIT, without any additional -terms or conditions. diff --git a/tokio-fs/tests/file.rs b/tokio-fs/tests/file.rs deleted file mode 100644 index db26becef13..00000000000 --- a/tokio-fs/tests/file.rs +++ /dev/null @@ -1,199 +0,0 @@ -#![warn(rust_2018_idioms)] - -use tokio::fs::File; -use tokio::prelude::*; - -use std::io::prelude::*; -use tempfile::NamedTempFile; - -/* -use rand::{distributions, thread_rng, Rng}; -use std::fs; -use std::io::SeekFrom; -use tempfile::Builder as TmpBuilder; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio_fs::*; -*/ - -const HELLO: &[u8] = b"hello world..."; - -#[tokio::test] -async fn basic_read() { - let mut tempfile = tempfile(); - tempfile.write_all(HELLO).unwrap(); - - let mut file = File::open(tempfile.path()).await.unwrap(); - - let mut buf = [0; 1024]; - let n = file.read(&mut buf).await.unwrap(); - - assert_eq!(n, HELLO.len()); - assert_eq!(&buf[..n], HELLO); -} - -#[tokio::test] -async fn basic_write() { - let tempfile = tempfile(); - - let mut file = File::create(tempfile.path()).await.unwrap(); - - file.write_all(HELLO).await.unwrap(); - file.flush().await.unwrap(); - - let file = std::fs::read(tempfile.path()).unwrap(); - assert_eq!(file, HELLO); -} - -fn tempfile() -> NamedTempFile { - NamedTempFile::new().unwrap() -} - -/* -mod pool; - -#[test] -fn read_write() { - const NUM_CHARS: usize = 16 * 1_024; - - let dir = TmpBuilder::new() - .prefix("tokio-fs-tests") - .tempdir() - .unwrap(); - let file_path = dir.path().join("read_write.txt"); - - let contents: Vec = thread_rng() - .sample_iter(&distributions::Alphanumeric) - .take(NUM_CHARS) - .collect::() - .into(); - - let file_path_2 = file_path.clone(); - let contents_2 = contents.clone(); - - pool::run(async move { - let mut file = File::create(file_path).await?; - let metadata = file.metadata().await?; - assert!(metadata.is_file()); - file.write(&contents).await?; - file.sync_all().await?; - Ok(()) - }); - - let dst = fs::read(&file_path_2).unwrap(); - assert_eq!(dst, contents_2); - - pool::run(async move { - let buf = read(file_path_2).await?; - assert_eq!(buf, contents_2); - Ok(()) - }); -} - -#[test] -fn read_write_helpers() { - const NUM_CHARS: usize = 16 * 1_024; - - let dir = TmpBuilder::new() - .prefix("tokio-fs-tests") - .tempdir() - .unwrap(); - let file_path = dir.path().join("read_write_all.txt"); - - let contents: Vec = thread_rng() - .sample_iter(&distributions::Alphanumeric) - .take(NUM_CHARS) - .collect::() - .into(); - - let file_path_2 = file_path.clone(); - let contents_2 = contents.clone(); - - pool::run(async move { - write(file_path, contents).await?; - Ok(()) - }); - - let dst = fs::read(&file_path_2).unwrap(); - assert_eq!(dst, contents_2); - - pool::run(async move { - let buf = read(file_path_2).await?; - assert_eq!(buf, contents_2); - Ok(()) - }); -} - -#[test] -fn metadata() { - let dir = TmpBuilder::new() - .prefix("tokio-fs-tests") - .tempdir() - .unwrap(); - let file_path = dir.path().join("metadata.txt"); - - pool::run(async move { - assert!(tokio_fs::metadata(file_path.clone()).await.is_err()); - File::create(file_path.clone()).await?; - let metadata = tokio_fs::metadata(file_path.clone()).await?; - assert!(metadata.is_file()); - Ok(()) - }); -} - -#[test] -fn seek() { - let dir = TmpBuilder::new() - .prefix("tokio-fs-tests") - .tempdir() - .unwrap(); - let file_path = dir.path().join("seek.txt"); - - pool::run(async move { - let mut options = OpenOptions::new(); - - options.create(true).read(true).write(true); - - let mut file = options.open(file_path).await.unwrap(); - - assert!(file.write(b"Hello, world!").await.is_ok()); - file.seek(SeekFrom::End(-6)).await.unwrap(); - let mut buf = vec![0; 5]; - assert!(file.read(buf.as_mut()).await.is_ok()); - assert_eq!(buf, b"world"); - file.seek(SeekFrom::Start(0)).await.unwrap(); - let mut buf = vec![0; 5]; - assert!(file.read(buf.as_mut()).await.is_ok()); - assert_eq!(buf, b"Hello"); - Ok(()) - }); -} - -#[test] -fn clone() { - use std::io::prelude::*; - - let dir = TmpBuilder::new() - .prefix("tokio-fs-tests") - .tempdir() - .unwrap(); - let file_path = dir.path().join("clone.txt"); - let file_path_2 = file_path.clone(); - - pool::run(async move { - let mut file = File::create(file_path.clone()).await.unwrap(); - let mut clone = file.try_clone().await.unwrap(); - assert!(AsyncWriteExt::write(&mut file, b"clone ").await.is_ok()); - assert!(AsyncWriteExt::write(&mut clone, b"successful") - .await - .is_ok()); - Ok(()) - }); - - let mut file = std::fs::File::open(&file_path_2).unwrap(); - - let mut dst = vec![]; - file.read_to_end(&mut dst).unwrap(); - - assert_eq!(dst, b"clone successful") -} -*/ diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 6ed8002c714..1084db0f8a3 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -37,7 +37,7 @@ default = [ ] codec = ["io", "tokio-codec", "bytes"] -fs = ["tokio-fs"] +fs = [] io = ["tokio-io"] macros = ["tokio-macros"] net = ["tcp", "udp", "uds"] @@ -74,7 +74,6 @@ futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink"] } bytes = { version = "0.4", optional = true } num_cpus = { version = "1.8.0", optional = true } tokio-codec = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-codec" } -tokio-fs = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-fs" } tokio-io = { version = "=0.2.0-alpha.6", optional = true, features = ["util"], path = "../tokio-io" } tokio-executor = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-executor" } tokio-macros = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-macros" } @@ -101,6 +100,7 @@ libc = "0.2" num_cpus = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +tempfile = "3.1.0" time = "0.1" [package.metadata.docs.rs] diff --git a/tokio/README.md b/tokio/README.md index e9cdc413175..14b8b238d1d 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -119,39 +119,6 @@ project. [guide]: CONTRIBUTING.md -## Project layout - -The `tokio` crate, found at the root, is primarily intended for use by -application developers. Library authors should depend on the sub crates, which -have greater guarantees of stability. - -The crates included as part of Tokio are: - -* [`tokio-executor`]: Task executors and related utilities. Includes a - single-threaded executor and a multi-threaded, work-stealing, executor. - -* [`tokio-fs`]: Filesystem (and standard in / out) APIs. - -* [`tokio-codec`]: Utilities for encoding and decoding protocol frames. - -* [`tokio-io`]: Asynchronous I/O related traits and utilities. - -* [`tokio-macros`]: Macros for usage with Tokio. - -* [`tokio-net`]: Event loop that drives I/O resources as well as TCP, UDP, and - unix domain socket apis. - -* [ `tokio-timer`]: Time related APIs. - -[`tokio-codec`]: tokio-codec -[`tokio-current-thread`]: tokio-current-thread -[`tokio-executor`]: tokio-executor -[`tokio-fs`]: tokio-fs -[`tokio-io`]: tokio-io -[`tokio-macros`]: tokio-macros -[`tokio-net`]: tokio-net -[`tokio-timer`]: tokio-timer - ## Related Projects In addition to the crates in this repository, the Tokio project also maintains diff --git a/tokio/src/fs.rs b/tokio/src/fs.rs deleted file mode 100644 index cf902f8ec0f..00000000000 --- a/tokio/src/fs.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Asynchronous filesystem manipulation operations. -//! -//! This module contains basic methods and types for manipulating the contents -//! of the local filesystem from within the context of the Tokio runtime. -//! -//! Unlike *most* other Tokio APIs, the filesystem APIs **must** be used from -//! the context of the Tokio runtime as they require Tokio specific features to -//! function. - -pub use tokio_fs::{ - create_dir, create_dir_all, hard_link, metadata, os, read, read_dir, read_link, read_to_string, - remove_dir, remove_dir_all, remove_file, rename, set_permissions, symlink_metadata, write, - File, OpenOptions, -}; diff --git a/tokio-fs/src/blocking.rs b/tokio/src/fs/blocking.rs similarity index 99% rename from tokio-fs/src/blocking.rs rename to tokio/src/fs/blocking.rs index 5cee2d13b86..71b627c10a4 100644 --- a/tokio-fs/src/blocking.rs +++ b/tokio/src/fs/blocking.rs @@ -1,4 +1,4 @@ -use crate::sys; +use crate::fs::sys; use tokio_io::{AsyncRead, AsyncWrite}; diff --git a/tokio-fs/src/create_dir.rs b/tokio/src/fs/create_dir.rs similarity index 93% rename from tokio-fs/src/create_dir.rs rename to tokio/src/fs/create_dir.rs index 73a2bf4e15d..a74ca71d1e5 100644 --- a/tokio-fs/src/create_dir.rs +++ b/tokio/src/fs/create_dir.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/create_dir_all.rs b/tokio/src/fs/create_dir_all.rs similarity index 94% rename from tokio-fs/src/create_dir_all.rs rename to tokio/src/fs/create_dir_all.rs index f9cb3e5fa50..2a7374a3b21 100644 --- a/tokio-fs/src/create_dir_all.rs +++ b/tokio/src/fs/create_dir_all.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/file.rs b/tokio/src/fs/file.rs similarity index 99% rename from tokio-fs/src/file.rs rename to tokio/src/fs/file.rs index 43cfcd0b768..7c3a6948aa6 100644 --- a/tokio-fs/src/file.rs +++ b/tokio/src/fs/file.rs @@ -3,8 +3,8 @@ //! [`File`]: file/struct.File.html use self::State::*; -use crate::blocking::Buf; -use crate::{asyncify, sys}; +use crate::fs::blocking::Buf; +use crate::fs::{asyncify, sys}; use tokio_io::{AsyncRead, AsyncWrite}; diff --git a/tokio-fs/src/hard_link.rs b/tokio/src/fs/hard_link.rs similarity index 96% rename from tokio-fs/src/hard_link.rs rename to tokio/src/fs/hard_link.rs index ff68694103d..564807a60c6 100644 --- a/tokio-fs/src/hard_link.rs +++ b/tokio/src/fs/hard_link.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/metadata.rs b/tokio/src/fs/metadata.rs similarity index 91% rename from tokio-fs/src/metadata.rs rename to tokio/src/fs/metadata.rs index 668f12a560e..d78294a078e 100644 --- a/tokio-fs/src/metadata.rs +++ b/tokio/src/fs/metadata.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::fs::Metadata; use std::io; diff --git a/tokio-fs/src/lib.rs b/tokio/src/fs/mod.rs similarity index 63% rename from tokio-fs/src/lib.rs rename to tokio/src/fs/mod.rs index 5e01a72ffe8..08055757af0 100644 --- a/tokio-fs/src/lib.rs +++ b/tokio/src/fs/mod.rs @@ -1,16 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tokio-fs/0.2.0-alpha.6")] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] -#![deny(intra_doc_link_resolution_failure)] -#![doc(test( - no_crate_inject, - attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) -))] - //! Asynchronous file and standard stream adaptation. //! //! This module contains utility methods and adapter types for input/output to @@ -38,53 +25,65 @@ //! [`AsyncRead`]: https://docs.rs/tokio-io/0.1/tokio_io/trait.AsyncRead.html //! [tokio-executor]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/index.html -mod blocking; +pub(crate) mod blocking; + mod create_dir; +pub use self::create_dir::create_dir; + mod create_dir_all; +pub use self::create_dir_all::create_dir_all; + mod file; +pub use self::file::File; + mod hard_link; +pub use self::hard_link::hard_link; + mod metadata; +pub use self::metadata::metadata; + mod open_options; +pub use self::open_options::OpenOptions; + pub mod os; + mod read; +pub use self::read::read; + mod read_dir; +pub use self::read_dir::{read_dir, DirEntry, ReadDir}; + mod read_link; +pub use self::read_link::read_link; + mod read_to_string; +pub use self::read_to_string::read_to_string; + mod remove_dir; +pub use self::remove_dir::remove_dir; + mod remove_dir_all; +pub use self::remove_dir_all::remove_dir_all; + mod remove_file; +pub use self::remove_file::remove_file; + mod rename; +pub use self::rename::rename; + mod set_permissions; -mod stderr; -mod stdin; -mod stdout; +pub use self::set_permissions::set_permissions; + + mod symlink_metadata; -mod write; +pub use self::symlink_metadata::symlink_metadata; -pub use crate::create_dir::create_dir; -pub use crate::create_dir_all::create_dir_all; -pub use crate::file::File; -pub use crate::hard_link::hard_link; -pub use crate::metadata::metadata; -pub use crate::open_options::OpenOptions; -pub use crate::read::read; -pub use crate::read_dir::{read_dir, DirEntry, ReadDir}; -pub use crate::read_link::read_link; -pub use crate::read_to_string::read_to_string; -pub use crate::remove_dir::remove_dir; -pub use crate::remove_dir_all::remove_dir_all; -pub use crate::remove_file::remove_file; -pub use crate::rename::rename; -pub use crate::set_permissions::set_permissions; -pub use crate::stderr::{stderr, Stderr}; -pub use crate::stdin::{stdin, Stdin}; -pub use crate::stdout::{stdout, Stdout}; -pub use crate::symlink_metadata::symlink_metadata; -pub use crate::write::write; +mod write; +pub use self::write::write; use std::io; -async fn asyncify(f: F) -> io::Result +pub(crate) async fn asyncify(f: F) -> io::Result where F: FnOnce() -> io::Result + Send + 'static, T: Send + 'static, diff --git a/tokio-fs/src/open_options.rs b/tokio/src/fs/open_options.rs similarity index 99% rename from tokio-fs/src/open_options.rs rename to tokio/src/fs/open_options.rs index 438c0cef277..ef88d9a7fdc 100644 --- a/tokio-fs/src/open_options.rs +++ b/tokio/src/fs/open_options.rs @@ -1,4 +1,4 @@ -use crate::{asyncify, File}; +use crate::fs::{asyncify, File}; use std::io; use std::path::Path; diff --git a/tokio-fs/src/os/mod.rs b/tokio/src/fs/os/mod.rs similarity index 100% rename from tokio-fs/src/os/mod.rs rename to tokio/src/fs/os/mod.rs diff --git a/tokio-fs/src/os/unix/mod.rs b/tokio/src/fs/os/unix/mod.rs similarity index 99% rename from tokio-fs/src/os/unix/mod.rs rename to tokio/src/fs/os/unix/mod.rs index c3bb562fef4..3b0bec38bd5 100644 --- a/tokio-fs/src/os/unix/mod.rs +++ b/tokio/src/fs/os/unix/mod.rs @@ -1,5 +1,4 @@ //! Unix-specific extensions to primitives in the `tokio_fs` module. mod symlink; - pub use self::symlink::symlink; diff --git a/tokio-fs/src/os/unix/symlink.rs b/tokio/src/fs/os/unix/symlink.rs similarity index 95% rename from tokio-fs/src/os/unix/symlink.rs rename to tokio/src/fs/os/unix/symlink.rs index b546578acf3..c2a101dc638 100644 --- a/tokio-fs/src/os/unix/symlink.rs +++ b/tokio/src/fs/os/unix/symlink.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/os/windows/mod.rs b/tokio/src/fs/os/windows/mod.rs similarity index 100% rename from tokio-fs/src/os/windows/mod.rs rename to tokio/src/fs/os/windows/mod.rs index 12ed8458a4b..42eb7bdb92f 100644 --- a/tokio-fs/src/os/windows/mod.rs +++ b/tokio/src/fs/os/windows/mod.rs @@ -1,7 +1,7 @@ //! Windows-specific extensions for the primitives in the `tokio_fs` module. mod symlink_dir; -mod symlink_file; - pub use self::symlink_dir::symlink_dir; + +mod symlink_file; pub use self::symlink_file::symlink_file; diff --git a/tokio-fs/src/os/windows/symlink_dir.rs b/tokio/src/fs/os/windows/symlink_dir.rs similarity index 95% rename from tokio-fs/src/os/windows/symlink_dir.rs rename to tokio/src/fs/os/windows/symlink_dir.rs index 8d8e0b43467..04692618764 100644 --- a/tokio-fs/src/os/windows/symlink_dir.rs +++ b/tokio/src/fs/os/windows/symlink_dir.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/os/windows/symlink_file.rs b/tokio/src/fs/os/windows/symlink_file.rs similarity index 95% rename from tokio-fs/src/os/windows/symlink_file.rs rename to tokio/src/fs/os/windows/symlink_file.rs index c6d9ad80201..da8d9d6378d 100644 --- a/tokio-fs/src/os/windows/symlink_file.rs +++ b/tokio/src/fs/os/windows/symlink_file.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/read.rs b/tokio/src/fs/read.rs similarity index 96% rename from tokio-fs/src/read.rs rename to tokio/src/fs/read.rs index 21092aaf528..88211228331 100644 --- a/tokio-fs/src/read.rs +++ b/tokio/src/fs/read.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::{io, path::Path}; diff --git a/tokio-fs/src/read_dir.rs b/tokio/src/fs/read_dir.rs similarity index 99% rename from tokio-fs/src/read_dir.rs rename to tokio/src/fs/read_dir.rs index 9266ae730e3..03284b72a15 100644 --- a/tokio-fs/src/read_dir.rs +++ b/tokio/src/fs/read_dir.rs @@ -1,4 +1,4 @@ -use crate::{asyncify, sys}; +use crate::fs::{asyncify, sys}; use futures_core::ready; use futures_core::stream::Stream; diff --git a/tokio-fs/src/read_link.rs b/tokio/src/fs/read_link.rs similarity index 93% rename from tokio-fs/src/read_link.rs rename to tokio/src/fs/read_link.rs index e32574abefc..51786f97a46 100644 --- a/tokio-fs/src/read_link.rs +++ b/tokio/src/fs/read_link.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::{Path, PathBuf}; diff --git a/tokio-fs/src/read_to_string.rs b/tokio/src/fs/read_to_string.rs similarity index 96% rename from tokio-fs/src/read_to_string.rs rename to tokio/src/fs/read_to_string.rs index 9676a15cd7a..77149bfc61d 100644 --- a/tokio-fs/src/read_to_string.rs +++ b/tokio/src/fs/read_to_string.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::{io, path::Path}; diff --git a/tokio-fs/src/remove_dir.rs b/tokio/src/fs/remove_dir.rs similarity index 92% rename from tokio-fs/src/remove_dir.rs rename to tokio/src/fs/remove_dir.rs index 22c6ba3eba1..3989c1de51e 100644 --- a/tokio-fs/src/remove_dir.rs +++ b/tokio/src/fs/remove_dir.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/remove_dir_all.rs b/tokio/src/fs/remove_dir_all.rs similarity index 94% rename from tokio-fs/src/remove_dir_all.rs rename to tokio/src/fs/remove_dir_all.rs index 3a1d8be18e9..50fe719b00b 100644 --- a/tokio-fs/src/remove_dir_all.rs +++ b/tokio/src/fs/remove_dir_all.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/remove_file.rs b/tokio/src/fs/remove_file.rs similarity index 95% rename from tokio-fs/src/remove_file.rs rename to tokio/src/fs/remove_file.rs index 634e7d0b720..3921f55b519 100644 --- a/tokio-fs/src/remove_file.rs +++ b/tokio/src/fs/remove_file.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/rename.rs b/tokio/src/fs/rename.rs similarity index 95% rename from tokio-fs/src/rename.rs rename to tokio/src/fs/rename.rs index 16c966631b8..dc9b8765c84 100644 --- a/tokio-fs/src/rename.rs +++ b/tokio/src/fs/rename.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::io; use std::path::Path; diff --git a/tokio-fs/src/set_permissions.rs b/tokio/src/fs/set_permissions.rs similarity index 94% rename from tokio-fs/src/set_permissions.rs rename to tokio/src/fs/set_permissions.rs index 9c663d44af4..6e64054408f 100644 --- a/tokio-fs/src/set_permissions.rs +++ b/tokio/src/fs/set_permissions.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::fs::Permissions; use std::io; diff --git a/tokio-fs/src/symlink_metadata.rs b/tokio/src/fs/symlink_metadata.rs similarity index 94% rename from tokio-fs/src/symlink_metadata.rs rename to tokio/src/fs/symlink_metadata.rs index 1ebcc1e6204..dc607971e53 100644 --- a/tokio-fs/src/symlink_metadata.rs +++ b/tokio/src/fs/symlink_metadata.rs @@ -1,4 +1,4 @@ -use super::asyncify; +use crate::fs::asyncify; use std::fs::Metadata; use std::io; diff --git a/tokio-fs/src/write.rs b/tokio/src/fs/write.rs similarity index 96% rename from tokio-fs/src/write.rs rename to tokio/src/fs/write.rs index 492c65fc962..81176740bb3 100644 --- a/tokio-fs/src/write.rs +++ b/tokio/src/fs/write.rs @@ -1,4 +1,4 @@ -use crate::asyncify; +use crate::fs::asyncify; use std::{io, path::Path}; diff --git a/tokio/src/io.rs b/tokio/src/io/mod.rs similarity index 91% rename from tokio/src/io.rs rename to tokio/src/io/mod.rs index d694e08d531..31f6a24115e 100644 --- a/tokio/src/io.rs +++ b/tokio/src/io/mod.rs @@ -36,9 +36,16 @@ //! [`ErrorKind`]: enum.ErrorKind.html //! [`Result`]: type.Result.html -// standard input, output, and error -#[cfg(feature = "fs")] -pub use tokio_fs::{stderr, stdin, stdout, Stderr, Stdin, Stdout}; + +mod stderr; +pub use self::stderr::{stderr, Stderr}; + +mod stdin; +pub use self::stdin::{stdin, Stdin}; + +mod stdout; +pub use self::stdout::{stdout, Stdout}; + pub use tokio_io::split::split; pub use tokio_io::{ empty, repeat, sink, AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, diff --git a/tokio-fs/src/stderr.rs b/tokio/src/io/stderr.rs similarity index 97% rename from tokio-fs/src/stderr.rs rename to tokio/src/io/stderr.rs index c0e071700a1..617b5d1e32f 100644 --- a/tokio-fs/src/stderr.rs +++ b/tokio/src/io/stderr.rs @@ -1,4 +1,4 @@ -use crate::blocking::Blocking; +use crate::fs::blocking::Blocking; use tokio_io::AsyncWrite; diff --git a/tokio-fs/src/stdin.rs b/tokio/src/io/stdin.rs similarity index 97% rename from tokio-fs/src/stdin.rs rename to tokio/src/io/stdin.rs index a0fea9814c8..7c85abdad5d 100644 --- a/tokio-fs/src/stdin.rs +++ b/tokio/src/io/stdin.rs @@ -1,4 +1,4 @@ -use crate::blocking::Blocking; +use crate::fs::blocking::Blocking; use tokio_io::AsyncRead; diff --git a/tokio-fs/src/stdout.rs b/tokio/src/io/stdout.rs similarity index 97% rename from tokio-fs/src/stdout.rs rename to tokio/src/io/stdout.rs index 04bd8796cc5..39da06af672 100644 --- a/tokio-fs/src/stdout.rs +++ b/tokio/src/io/stdout.rs @@ -1,4 +1,4 @@ -use crate::blocking::Blocking; +use crate::fs::blocking::Blocking; use tokio_io::AsyncWrite; diff --git a/tokio-fs/tests/dir.rs b/tokio/tests/fs_dir.rs similarity index 100% rename from tokio-fs/tests/dir.rs rename to tokio/tests/fs_dir.rs diff --git a/tokio/tests/fs_file.rs b/tokio/tests/fs_file.rs new file mode 100644 index 00000000000..555a1e64a0f --- /dev/null +++ b/tokio/tests/fs_file.rs @@ -0,0 +1,40 @@ +#![warn(rust_2018_idioms)] + +use tokio::fs::File; +use tokio::prelude::*; + +use std::io::prelude::*; +use tempfile::NamedTempFile; + +const HELLO: &[u8] = b"hello world..."; + +#[tokio::test] +async fn basic_read() { + let mut tempfile = tempfile(); + tempfile.write_all(HELLO).unwrap(); + + let mut file = File::open(tempfile.path()).await.unwrap(); + + let mut buf = [0; 1024]; + let n = file.read(&mut buf).await.unwrap(); + + assert_eq!(n, HELLO.len()); + assert_eq!(&buf[..n], HELLO); +} + +#[tokio::test] +async fn basic_write() { + let tempfile = tempfile(); + + let mut file = File::create(tempfile.path()).await.unwrap(); + + file.write_all(HELLO).await.unwrap(); + file.flush().await.unwrap(); + + let file = std::fs::read(tempfile.path()).unwrap(); + assert_eq!(file, HELLO); +} + +fn tempfile() -> NamedTempFile { + NamedTempFile::new().unwrap() +} diff --git a/tokio-fs/tests/file_mocked.rs b/tokio/tests/fs_file_mocked.rs similarity index 96% rename from tokio-fs/tests/file_mocked.rs rename to tokio/tests/fs_file_mocked.rs index 422588760a4..b078b3c0b6e 100644 --- a/tokio-fs/tests/file_mocked.rs +++ b/tokio/tests/fs_file_mocked.rs @@ -1,23 +1,35 @@ #![warn(rust_2018_idioms)] -mod sys { - mod file; - pub(crate) mod pool; - - pub(crate) use self::file::File; - pub(crate) use self::pool::{run, Blocking}; -} -use sys::pool::{self, asyncify}; - +// Load source #[allow(warnings)] -#[path = "../src/file.rs"] +#[path = "../src/fs/file.rs"] mod file; use file::File; #[allow(warnings)] -#[path = "../src/blocking.rs"] +#[path = "../src/fs/blocking.rs"] mod blocking; +// Load mocked types +mod support { + pub(crate) mod mock_file; + pub(crate) mod mock_pool; +} +pub(crate) use support::mock_pool as pool; + +// Place them where the source expects them +pub(crate) mod fs { + pub(crate) use crate::blocking; + + pub(crate) mod sys { + pub(crate) use crate::support::mock_file::File; + pub(crate) use crate::support::mock_pool::{run, Blocking}; + } + + pub(crate) use crate::support::mock_pool::asyncify; +} +use fs::sys; + use tokio::prelude::*; use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task}; diff --git a/tokio-fs/tests/link.rs b/tokio/tests/fs_link.rs similarity index 100% rename from tokio-fs/tests/link.rs rename to tokio/tests/fs_link.rs diff --git a/tokio-fs/tests/sys/file.rs b/tokio/tests/support/mock_file.rs similarity index 100% rename from tokio-fs/tests/sys/file.rs rename to tokio/tests/support/mock_file.rs diff --git a/tokio-fs/tests/sys/pool.rs b/tokio/tests/support/mock_pool.rs similarity index 100% rename from tokio-fs/tests/sys/pool.rs rename to tokio/tests/support/mock_pool.rs