Skip to content

Commit 432a23f

Browse files
committed
Move fs into sys
1 parent d58c42b commit 432a23f

File tree

28 files changed

+70
-55
lines changed

28 files changed

+70
-55
lines changed
File renamed without changes.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
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+
pub use crate::sys::fs::common::{copy, exists};
13+
use crate::sys::pal::fd::FileDesc;
1314
use crate::sys::time::SystemTime;
1415
use crate::sys::{cvt, unsupported};
15-
pub use crate::sys_common::fs::{copy, exists};
1616
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1717
use crate::{fmt, mem};
1818

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

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::{abi, error};
1+
#![allow(dead_code)]
2+
23
use crate::ffi::{CStr, CString, OsStr, OsString};
34
use crate::fmt;
45
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
@@ -7,9 +8,10 @@ use crate::os::raw::{c_int, c_short};
78
use crate::os::solid::ffi::OsStrExt;
89
use crate::path::{Path, PathBuf};
910
use crate::sync::Arc;
11+
pub use crate::sys::fs::common::exists;
12+
use crate::sys::pal::{abi, error};
1013
use crate::sys::time::SystemTime;
1114
use crate::sys::unsupported;
12-
pub use crate::sys_common::fs::exists;
1315
use crate::sys_common::ignore_notfound;
1416

1517
type CIntNotMinusOne = core::num::niche_types::NotAllOnes<c_int>;
File renamed without changes.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(nonstandard_style)]
2+
#![allow(unsafe_op_in_unsafe_fn)]
13
// miri has some special hacks here that make things unused.
24
#![cfg_attr(miri, allow(unused))]
35

@@ -79,13 +81,13 @@ use crate::path::{Path, PathBuf};
7981
use crate::sync::Arc;
8082
use crate::sys::common::small_c_string::run_path_with_cstr;
8183
use crate::sys::fd::FileDesc;
84+
pub use crate::sys::fs::common::exists;
8285
use crate::sys::time::SystemTime;
8386
#[cfg(all(target_os = "linux", target_env = "gnu"))]
8487
use crate::sys::weak::syscall;
8588
#[cfg(target_os = "android")]
8689
use crate::sys::weak::weak;
8790
use crate::sys::{cvt, cvt_r};
88-
pub use crate::sys_common::fs::exists;
8991
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
9092
use crate::{mem, ptr};
9193

@@ -699,6 +701,8 @@ impl Iterator for ReadDir {
699701
target_os = "hurd",
700702
))]
701703
fn next(&mut self) -> Option<io::Result<DirEntry>> {
704+
use crate::sys::os::{errno, set_errno};
705+
702706
if self.end_of_stream {
703707
return None;
704708
}
@@ -710,7 +714,7 @@ impl Iterator for ReadDir {
710714
// with unlimited or variable NAME_MAX. Many modern platforms guarantee
711715
// thread safety for readdir() as long an individual DIR* is not accessed
712716
// concurrently, which is sufficient for Rust.
713-
super::os::set_errno(0);
717+
set_errno(0);
714718
let entry_ptr: *const dirent64 = readdir64(self.inner.dirp.0);
715719
if entry_ptr.is_null() {
716720
// We either encountered an error, or reached the end. Either way,
@@ -719,7 +723,7 @@ impl Iterator for ReadDir {
719723

720724
// To distinguish between errors and end-of-directory, we had to clear
721725
// errno beforehand to check for an error now.
722-
return match super::os::errno() {
726+
return match errno() {
723727
0 => None,
724728
e => Some(Err(Error::from_raw_os_error(e))),
725729
};
@@ -1932,7 +1936,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
19321936

19331937
fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)> {
19341938
use crate::fs::File;
1935-
use crate::sys_common::fs::NOT_FILE_ERROR;
1939+
use crate::sys::fs::common::NOT_FILE_ERROR;
19361940

19371941
let reader = File::open(from)?;
19381942
let metadata = reader.metadata()?;
@@ -2151,7 +2155,7 @@ pub use remove_dir_impl::remove_dir_all;
21512155
miri
21522156
))]
21532157
mod remove_dir_impl {
2154-
pub use crate::sys_common::fs::remove_dir_all;
2158+
pub use crate::sys::fs::common::remove_dir_all;
21552159
}
21562160

21572161
// Modern implementation using openat(), unlinkat() and fdopendir()

library/std/src/sys/pal/unix/fs/tests.rs renamed to library/std/src/sys/fs/unix/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::sys::pal::unix::fs::FilePermissions;
1+
use crate::sys::fs::FilePermissions;
22

33
#[test]
44
fn test_debug_permissions() {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![forbid(unsafe_op_in_unsafe_fn)]
2-
3-
use super::fd::WasiFd;
41
use crate::ffi::{CStr, OsStr, OsString};
52
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
63
use crate::mem::{self, ManuallyDrop};
@@ -10,9 +7,10 @@ use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd
107
use crate::path::{Path, PathBuf};
118
use crate::sync::Arc;
129
use crate::sys::common::small_c_string::run_path_with_cstr;
10+
use crate::sys::fd::WasiFd;
11+
pub use crate::sys::fs::common::exists;
1312
use crate::sys::time::SystemTime;
1413
use crate::sys::unsupported;
15-
pub use crate::sys_common::fs::exists;
1614
use crate::sys_common::{AsInner, FromInner, IntoInner, ignore_notfound};
1715
use crate::{fmt, iter, ptr};
1816

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::api::{self, WinError, set_file_information_by_handle};
2-
use super::{IoResult, to_u16s};
1+
#![allow(nonstandard_style)]
2+
33
use crate::alloc::{alloc, handle_alloc_error};
44
use crate::borrow::Cow;
55
use crate::ffi::{OsStr, OsString, c_void};
@@ -10,6 +10,8 @@ use crate::os::windows::prelude::*;
1010
use crate::path::{Path, PathBuf};
1111
use crate::sync::Arc;
1212
use crate::sys::handle::Handle;
13+
use crate::sys::pal::api::{self, WinError, set_file_information_by_handle};
14+
use crate::sys::pal::{IoResult, fill_utf16_buf, to_u16s, truncate_utf16_at_nul};
1315
use crate::sys::path::maybe_verbatim;
1416
use crate::sys::time::SystemTime;
1517
use crate::sys::{Align8, c, cvt};
@@ -167,7 +169,7 @@ impl DirEntry {
167169
}
168170

169171
pub fn file_name(&self) -> OsString {
170-
let filename = super::truncate_utf16_at_nul(&self.data.cFileName);
172+
let filename = truncate_utf16_at_nul(&self.data.cFileName);
171173
OsString::from_wide(filename)
172174
}
173175

@@ -695,7 +697,7 @@ impl File {
695697
// Turn `\??\` into `\\?\` (a verbatim path).
696698
subst[1] = b'\\' as u16;
697699
// Attempt to convert to a more user-friendly path.
698-
let user = super::args::from_wide_to_user_path(
700+
let user = crate::sys::args::from_wide_to_user_path(
699701
subst.iter().copied().chain([0]).collect(),
700702
)?;
701703
Ok(PathBuf::from(OsString::from_wide(user.strip_suffix(&[0]).unwrap_or(&user))))
@@ -1562,7 +1564,7 @@ pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
15621564
}
15631565

15641566
fn get_path(f: &File) -> io::Result<PathBuf> {
1565-
super::fill_utf16_buf(
1567+
fill_utf16_buf(
15661568
|buf, sz| unsafe {
15671569
c::GetFinalPathNameByHandleW(f.handle.as_raw_handle(), buf, sz, c::VOLUME_NAME_DOS)
15681570
},

0 commit comments

Comments
 (0)