Skip to content

Commit 32992dc

Browse files
committed
Move fs into sys
1 parent 4ecd70d commit 32992dc

File tree

25 files changed

+44
-36
lines changed

25 files changed

+44
-36
lines changed

library/std/src/sys/pal/hermit/fs.rs library/std/src/sys/fs/hermit.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use super::fd::FileDesc;
2-
use super::hermit_abi::{
3-
self, DT_DIR, DT_LNK, DT_REG, DT_UNKNOWN, O_APPEND, O_CREAT, O_DIRECTORY, O_EXCL, O_RDONLY,
4-
O_RDWR, O_TRUNC, O_WRONLY, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG, dirent64, stat as stat_struct,
5-
};
61
use crate::ffi::{CStr, OsStr, OsString, c_char};
72
use crate::io::{self, BorrowedCursor, Error, ErrorKind, IoSlice, IoSliceMut, SeekFrom};
83
use crate::os::hermit::ffi::OsStringExt;
4+
use crate::os::hermit::hermit_abi::{
5+
self, DT_DIR, DT_LNK, DT_REG, DT_UNKNOWN, O_APPEND, O_CREAT, O_DIRECTORY, O_EXCL, O_RDONLY,
6+
O_RDWR, O_TRUNC, O_WRONLY, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG, dirent64, stat as stat_struct,
7+
};
98
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
109
use crate::path::{Path, PathBuf};
1110
use crate::sync::Arc;
1211
use crate::sys::common::small_c_string::run_path_with_cstr;
12+
use crate::sys::pal::fd::FileDesc;
1313
use crate::sys::time::SystemTime;
1414
use crate::sys::{cvt, unsupported};
1515
pub use crate::sys_common::fs::{copy, exists};

library/std/src/sys/fs/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cfg_if::cfg_if! {
2+
if #[cfg(target_family = "unix")] {
3+
mod unix;
4+
pub use self::unix::*;
5+
} else if #[cfg(target_os = "windows")] {
6+
mod windows;
7+
pub use self::windows::*;
8+
} else if #[cfg(target_os = "solid_asp3")] {
9+
mod solid;
10+
pub use self::solid::*;
11+
} else if #[cfg(target_os = "hermit")] {
12+
mod hermit;
13+
pub use self::hermit::*;
14+
} else if #[cfg(target_os = "wasi")] {
15+
mod wasi;
16+
pub use self::wasi::*;
17+
} else if #[cfg(target_os = "uefi")] {
18+
mod uefi;
19+
pub use self::uefi::*;
20+
} else {
21+
mod unsupported;
22+
pub use self::unsupported::*;
23+
}
24+
}

library/std/src/sys/pal/solid/fs.rs library/std/src/sys/fs/solid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::{abi, error};
21
use crate::ffi::{CStr, CString, OsStr, OsString};
32
use crate::fmt;
43
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
@@ -7,6 +6,7 @@ use crate::os::raw::{c_int, c_short};
76
use crate::os::solid::ffi::OsStrExt;
87
use crate::path::{Path, PathBuf};
98
use crate::sync::Arc;
9+
use crate::sys::pal::{abi, error};
1010
use crate::sys::time::SystemTime;
1111
use crate::sys::unsupported;
1212
pub use crate::sys_common::fs::exists;
File renamed without changes.

library/std/src/sys/pal/unix/fs.rs library/std/src/sys/fs/unix.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ impl Iterator for ReadDir {
699699
target_os = "hurd",
700700
))]
701701
fn next(&mut self) -> Option<io::Result<DirEntry>> {
702+
use crate::sys::os::{errno, set_errno};
703+
702704
if self.end_of_stream {
703705
return None;
704706
}
@@ -710,7 +712,7 @@ impl Iterator for ReadDir {
710712
// with unlimited or variable NAME_MAX. Many modern platforms guarantee
711713
// thread safety for readdir() as long an individual DIR* is not accessed
712714
// concurrently, which is sufficient for Rust.
713-
super::os::set_errno(0);
715+
set_errno(0);
714716
let entry_ptr: *const dirent64 = readdir64(self.inner.dirp.0);
715717
if entry_ptr.is_null() {
716718
// We either encountered an error, or reached the end. Either way,
@@ -719,7 +721,7 @@ impl Iterator for ReadDir {
719721

720722
// To distinguish between errors and end-of-directory, we had to clear
721723
// errno beforehand to check for an error now.
722-
return match super::os::errno() {
724+
return match errno() {
723725
0 => None,
724726
e => Some(Err(Error::from_raw_os_error(e))),
725727
};
File renamed without changes.

library/std/src/sys/pal/wasi/fs.rs library/std/src/sys/fs/wasi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![forbid(unsafe_op_in_unsafe_fn)]
22

3-
use super::fd::WasiFd;
43
use crate::ffi::{CStr, OsStr, OsString};
54
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
65
use crate::mem::{self, ManuallyDrop};
@@ -10,6 +9,7 @@ use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd
109
use crate::path::{Path, PathBuf};
1110
use crate::sync::Arc;
1211
use crate::sys::common::small_c_string::run_path_with_cstr;
12+
use crate::sys::fd::WasiFd;
1313
use crate::sys::time::SystemTime;
1414
use crate::sys::unsupported;
1515
pub use crate::sys_common::fs::exists;

library/std/src/sys/pal/windows/fs.rs library/std/src/sys/fs/windows.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use super::api::{self, WinError, set_file_information_by_handle};
2-
use super::{IoResult, to_u16s};
31
use crate::alloc::{alloc, handle_alloc_error};
42
use crate::borrow::Cow;
53
use crate::ffi::{OsStr, OsString, c_void};
@@ -10,6 +8,8 @@ use crate::os::windows::prelude::*;
108
use crate::path::{Path, PathBuf};
119
use crate::sync::Arc;
1210
use crate::sys::handle::Handle;
11+
use crate::sys::pal::api::{self, WinError, set_file_information_by_handle};
12+
use crate::sys::pal::{IoResult, fill_utf16_buf, to_u16s, truncate_utf16_at_nul};
1313
use crate::sys::path::maybe_verbatim;
1414
use crate::sys::time::SystemTime;
1515
use crate::sys::{Align8, c, cvt};
@@ -167,7 +167,7 @@ impl DirEntry {
167167
}
168168

169169
pub fn file_name(&self) -> OsString {
170-
let filename = super::truncate_utf16_at_nul(&self.data.cFileName);
170+
let filename = truncate_utf16_at_nul(&self.data.cFileName);
171171
OsString::from_wide(filename)
172172
}
173173

@@ -695,7 +695,7 @@ impl File {
695695
// Turn `\??\` into `\\?\` (a verbatim path).
696696
subst[1] = b'\\' as u16;
697697
// Attempt to convert to a more user-friendly path.
698-
let user = super::args::from_wide_to_user_path(
698+
let user = crate::sys::args::from_wide_to_user_path(
699699
subst.iter().copied().chain([0]).collect(),
700700
)?;
701701
Ok(PathBuf::from(OsString::from_wide(user.strip_suffix(&[0]).unwrap_or(&user))))
@@ -1562,7 +1562,7 @@ pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
15621562
}
15631563

15641564
fn get_path(f: &File) -> io::Result<PathBuf> {
1565-
super::fill_utf16_buf(
1565+
fill_utf16_buf(
15661566
|buf, sz| unsafe {
15671567
c::GetFinalPathNameByHandleW(f.handle.as_raw_handle(), buf, sz, c::VOLUME_NAME_DOS)
15681568
},

library/std/src/sys/pal/windows/fs/remove_dir_all.rs library/std/src/sys/fs/windows/remove_dir_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
3333

3434
use super::{AsRawHandle, DirBuff, File, FromRawHandle};
3535
use crate::sys::c;
36-
use crate::sys::pal::windows::api::WinError;
36+
use crate::sys::pal::api::WinError;
3737
use crate::thread;
3838

3939
// The maximum number of times to spin when waiting for deletes to complete.

library/std/src/sys/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod anonymous_pipe;
1212
pub mod backtrace;
1313
pub mod cmath;
1414
pub mod exit_guard;
15+
pub mod fs;
1516
pub mod io;
1617
pub mod net;
1718
pub mod os_str;

library/std/src/sys/pal/hermit/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::os::raw::c_char;
2121
pub mod args;
2222
pub mod env;
2323
pub mod fd;
24-
pub mod fs;
2524
pub mod futex;
2625
pub mod os;
2726
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/sgx/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub mod abi;
1212
pub mod args;
1313
pub mod env;
1414
pub mod fd;
15-
#[path = "../unsupported/fs.rs"]
16-
pub mod fs;
1715
mod libunwind_integration;
1816
pub mod os;
1917
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/solid/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod env;
2222
// `error` is `pub(crate)` so that it can be accessed by `itron/error.rs` as
2323
// `crate::sys::error`
2424
pub(crate) mod error;
25-
pub mod fs;
2625
pub mod os;
2726
#[path = "../unsupported/pipe.rs"]
2827
pub mod pipe;

library/std/src/sys/pal/solid/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl SystemTime {
3535
SystemTime(t)
3636
}
3737

38-
pub(super) fn from_time_t(t: abi::time_t) -> Self {
38+
pub fn from_time_t(t: abi::time_t) -> Self {
3939
Self(t)
4040
}
4141

library/std/src/sys/pal/teeos/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pub mod args;
1111
#[path = "../unsupported/env.rs"]
1212
pub mod env;
1313
//pub mod fd;
14-
#[path = "../unsupported/fs.rs"]
15-
pub mod fs;
1614
pub mod os;
1715
#[path = "../unsupported/pipe.rs"]
1816
pub mod pipe;

library/std/src/sys/pal/uefi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
pub mod args;
1717
pub mod env;
18-
pub mod fs;
1918
pub mod helpers;
2019
pub mod os;
2120
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/unix/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod weak;
99
pub mod args;
1010
pub mod env;
1111
pub mod fd;
12-
pub mod fs;
1312
pub mod futex;
1413
#[cfg(any(target_os = "linux", target_os = "android"))]
1514
pub mod kernel_copy;

library/std/src/sys/pal/unsupported/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
pub mod args;
44
pub mod env;
5-
pub mod fs;
65
pub mod os;
76
pub mod pipe;
87
pub mod process;

library/std/src/sys/pal/wasi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
pub mod args;
1717
pub mod env;
1818
pub mod fd;
19-
pub mod fs;
2019
#[allow(unused)]
2120
#[path = "../wasm/atomics/futex.rs"]
2221
pub mod futex;

library/std/src/sys/pal/wasip2/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub mod args;
1212
pub mod env;
1313
#[path = "../wasi/fd.rs"]
1414
pub mod fd;
15-
#[path = "../wasi/fs.rs"]
16-
pub mod fs;
1715
#[allow(unused)]
1816
#[path = "../wasm/atomics/futex.rs"]
1917
pub mod futex;

library/std/src/sys/pal/wasm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#[path = "../unsupported/args.rs"]
2020
pub mod args;
2121
pub mod env;
22-
#[path = "../unsupported/fs.rs"]
23-
pub mod fs;
2422
#[path = "../unsupported/os.rs"]
2523
pub mod os;
2624
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/windows/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod api;
1717
pub mod args;
1818
pub mod c;
1919
pub mod env;
20-
pub mod fs;
2120
#[cfg(not(target_vendor = "win7"))]
2221
pub mod futex;
2322
pub mod handle;
@@ -37,7 +36,7 @@ cfg_if::cfg_if! {
3736
}
3837

3938
/// Map a [`Result<T, WinError>`] to [`io::Result<T>`](crate::io::Result<T>).
40-
trait IoResult<T> {
39+
pub trait IoResult<T> {
4140
fn io_result(self) -> crate::io::Result<T>;
4241
}
4342
impl<T> IoResult<T> for Result<T, api::WinError> {

library/std/src/sys/pal/xous/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
pub mod args;
44
#[path = "../unsupported/env.rs"]
55
pub mod env;
6-
#[path = "../unsupported/fs.rs"]
7-
pub mod fs;
86
pub mod os;
97
#[path = "../unsupported/pipe.rs"]
108
pub mod pipe;

library/std/src/sys/pal/zkvm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub mod abi;
1414
#[path = "../zkvm/args.rs"]
1515
pub mod args;
1616
pub mod env;
17-
#[path = "../unsupported/fs.rs"]
18-
pub mod fs;
1917
pub mod os;
2018
#[path = "../unsupported/pipe.rs"]
2119
pub mod pipe;

0 commit comments

Comments
 (0)