|
7 | 7 |
|
8 | 8 | // spell-checker:ignore backport |
9 | 9 |
|
10 | | -#[cfg(unix)] |
11 | | -use libc::mkfifo; |
12 | 10 | #[cfg(all(unix, not(target_os = "redox")))] |
13 | 11 | pub use libc::{major, makedev, minor}; |
14 | 12 | use std::collections::HashSet; |
15 | 13 | use std::collections::VecDeque; |
16 | 14 | use std::env; |
17 | | -#[cfg(unix)] |
18 | | -use std::ffi::CString; |
19 | 15 | use std::ffi::{OsStr, OsString}; |
20 | 16 | use std::fs; |
21 | 17 | use std::fs::read_dir; |
@@ -892,37 +888,6 @@ pub fn get_filename(file: &Path) -> Option<&str> { |
892 | 888 | file.file_name().and_then(|filename| filename.to_str()) |
893 | 889 | } |
894 | 890 |
|
895 | | -/// Make a FIFO, also known as a named pipe. |
896 | | -/// |
897 | | -/// This is a safe wrapper for the unsafe [`libc::mkfifo`] function, |
898 | | -/// which makes a [named |
899 | | -/// pipe](https://en.wikipedia.org/wiki/Named_pipe) on Unix systems. |
900 | | -/// |
901 | | -/// # Errors |
902 | | -/// |
903 | | -/// If the named pipe cannot be created. |
904 | | -/// |
905 | | -/// # Examples |
906 | | -/// |
907 | | -/// ```ignore |
908 | | -/// use uucore::fs::make_fifo; |
909 | | -/// |
910 | | -/// make_fifo("my-pipe").expect("failed to create the named pipe"); |
911 | | -/// |
912 | | -/// std::thread::spawn(|| { std::fs::write("my-pipe", b"hello").unwrap(); }); |
913 | | -/// assert_eq!(std::fs::read("my-pipe").unwrap(), b"hello"); |
914 | | -/// ``` |
915 | | -#[cfg(unix)] |
916 | | -pub fn make_fifo(path: &Path) -> std::io::Result<()> { |
917 | | - let name = CString::new(path.to_str().unwrap()).unwrap(); |
918 | | - let err = unsafe { mkfifo(name.as_ptr(), 0o666) }; |
919 | | - if err == -1 { |
920 | | - Err(Error::last_os_error()) |
921 | | - } else { |
922 | | - Ok(()) |
923 | | - } |
924 | | -} |
925 | | - |
926 | 891 | // Redox's libc appears not to include the following utilities |
927 | 892 |
|
928 | 893 | #[cfg(target_os = "redox")] |
@@ -950,8 +915,6 @@ mod tests { |
950 | 915 | #[cfg(unix)] |
951 | 916 | use std::os::unix; |
952 | 917 | #[cfg(unix)] |
953 | | - use std::os::unix::fs::FileTypeExt; |
954 | | - #[cfg(unix)] |
955 | 918 | use tempfile::{NamedTempFile, tempdir}; |
956 | 919 |
|
957 | 920 | struct NormalizePathTestCase<'a> { |
@@ -1216,25 +1179,4 @@ mod tests { |
1216 | 1179 | let file_path = PathBuf::from("~/foo.txt"); |
1217 | 1180 | assert!(matches!(get_filename(&file_path), Some("foo.txt"))); |
1218 | 1181 | } |
1219 | | - |
1220 | | - #[cfg(unix)] |
1221 | | - #[test] |
1222 | | - fn test_make_fifo() { |
1223 | | - // Create the FIFO in a temporary directory. |
1224 | | - let tempdir = tempdir().unwrap(); |
1225 | | - let path = tempdir.path().join("f"); |
1226 | | - assert!(make_fifo(&path).is_ok()); |
1227 | | - |
1228 | | - // Check that it is indeed a FIFO. |
1229 | | - assert!(fs::metadata(&path).unwrap().file_type().is_fifo()); |
1230 | | - |
1231 | | - // Check that we can write to it and read from it. |
1232 | | - // |
1233 | | - // Write and read need to happen in different threads, |
1234 | | - // otherwise `write` would block indefinitely while waiting |
1235 | | - // for the `read`. |
1236 | | - let path2 = path.clone(); |
1237 | | - std::thread::spawn(move || assert!(fs::write(&path2, b"foo").is_ok())); |
1238 | | - assert_eq!(fs::read(&path).unwrap(), b"foo"); |
1239 | | - } |
1240 | 1182 | } |
0 commit comments