Skip to content

Commit b8bf308

Browse files
committed
Various OS implementations of NativePath
1 parent 35fb3dc commit b8bf308

File tree

3 files changed

+166
-115
lines changed

3 files changed

+166
-115
lines changed

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

+54-56
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,66 @@ use crate::io::{self, Error, ErrorKind};
77
use crate::io::{BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
88
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
99
use crate::path::{Path, PathBuf};
10-
use crate::sys::common::small_c_string::run_path_with_cstr;
1110
use crate::sys::cvt;
1211
use crate::sys::time::SystemTime;
1312
use crate::sys::unsupported;
1413
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1514

16-
pub use crate::sys_common::fs::{copy, try_exists};
1715
//pub use crate::sys_common::fs::remove_dir_all;
1816

17+
pub(crate) mod fs_imp {
18+
pub(crate) use super::{
19+
DirBuilder, DirEntry, File, FileAttr, FilePermissions, FileTimes, FileType, OpenOptions,
20+
ReadDir,
21+
};
22+
use crate::io;
23+
use crate::path::{AsPath, PathBuf};
24+
use crate::sys::unsupported;
25+
26+
pub(crate) fn remove_file<P: AsPath>(_path: P) -> io::Result<()> {
27+
unsupported()
28+
}
29+
pub(crate) fn symlink_metadata<P: AsPath>(_path: P) -> io::Result<FileAttr> {
30+
unsupported()
31+
}
32+
pub(crate) fn metadata<P: AsPath>(_path: P) -> io::Result<FileAttr> {
33+
unsupported()
34+
}
35+
pub(crate) fn rename<P: AsPath, Q: AsPath>(_from: P, _to: Q) -> io::Result<()> {
36+
unsupported()
37+
}
38+
pub(crate) fn hard_link<P: AsPath, Q: AsPath>(_original: P, _link: Q) -> io::Result<()> {
39+
unsupported()
40+
}
41+
pub(crate) fn soft_link<P: AsPath, Q: AsPath>(_original: P, _link: Q) -> io::Result<()> {
42+
unsupported()
43+
}
44+
pub(crate) fn remove_dir<P: AsPath>(_path: P) -> io::Result<()> {
45+
unsupported()
46+
}
47+
pub(crate) fn read_dir<P: AsPath>(_path: P) -> io::Result<ReadDir> {
48+
unsupported()
49+
}
50+
pub(crate) fn set_permissions<P: AsPath>(_path: P, _perms: FilePermissions) -> io::Result<()> {
51+
unsupported()
52+
}
53+
pub(crate) fn copy<P: AsPath, Q: AsPath>(_from: P, _to: Q) -> io::Result<u64> {
54+
unsupported()
55+
}
56+
pub(crate) fn canonicalize<P: AsPath>(_path: P) -> io::Result<PathBuf> {
57+
unsupported()
58+
}
59+
pub(crate) fn remove_dir_all<P: AsPath>(_path: P) -> io::Result<()> {
60+
unsupported()
61+
}
62+
pub(crate) fn read_link<P: AsPath>(_path: P) -> io::Result<PathBuf> {
63+
unsupported()
64+
}
65+
pub(crate) fn try_exists<P: AsPath>(_path: P) -> io::Result<bool> {
66+
unsupported()
67+
}
68+
}
69+
1970
#[derive(Debug)]
2071
pub struct File(FileDesc);
2172

@@ -268,11 +319,7 @@ impl OpenOptions {
268319
}
269320

270321
impl File {
271-
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
272-
run_path_with_cstr(path, &|path| File::open_c(&path, opts))
273-
}
274-
275-
pub fn open_c(path: &CStr, opts: &OpenOptions) -> io::Result<File> {
322+
pub fn open_native(path: &CStr, opts: &OpenOptions) -> io::Result<File> {
276323
let mut flags = opts.get_access_mode()?;
277324
flags = flags | opts.get_creation_mode()?;
278325

@@ -415,52 +462,3 @@ impl FromRawFd for File {
415462
Self(FromRawFd::from_raw_fd(raw_fd))
416463
}
417464
}
418-
419-
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
420-
unsupported()
421-
}
422-
423-
pub fn unlink(path: &Path) -> io::Result<()> {
424-
run_path_with_cstr(path, &|path| cvt(unsafe { abi::unlink(path.as_ptr()) }).map(|_| ()))
425-
}
426-
427-
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
428-
unsupported()
429-
}
430-
431-
pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> {
432-
match perm.0 {}
433-
}
434-
435-
pub fn rmdir(_p: &Path) -> io::Result<()> {
436-
unsupported()
437-
}
438-
439-
pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
440-
//unsupported()
441-
Ok(())
442-
}
443-
444-
pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
445-
unsupported()
446-
}
447-
448-
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
449-
unsupported()
450-
}
451-
452-
pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
453-
unsupported()
454-
}
455-
456-
pub fn stat(_p: &Path) -> io::Result<FileAttr> {
457-
unsupported()
458-
}
459-
460-
pub fn lstat(_p: &Path) -> io::Result<FileAttr> {
461-
unsupported()
462-
}
463-
464-
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
465-
unsupported()
466-
}

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

+56-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,58 @@ use crate::{
1414

1515
pub use crate::sys_common::fs::try_exists;
1616

17+
pub(crate) mod fs_imp {
18+
pub(crate) use super::{
19+
DirBuilder, DirEntry, File, FileAttr, FilePermissions, FileTimes, FileType, OpenOptions,
20+
ReadDir,
21+
};
22+
use crate::io;
23+
use crate::path::{AsPath, PathBuf};
24+
25+
pub(crate) fn remove_file<P: AsPath>(path: P) -> io::Result<()> {
26+
path.with_path(super::unlink)
27+
}
28+
pub(crate) fn symlink_metadata<P: AsPath>(path: P) -> io::Result<FileAttr> {
29+
path.with_path(|path| super::lstat(path))
30+
}
31+
pub(crate) fn metadata<P: AsPath>(path: P) -> io::Result<FileAttr> {
32+
path.with_path(|path| super::stat(path))
33+
}
34+
pub(crate) fn rename<P: AsPath, Q: AsPath>(from: P, to: Q) -> io::Result<()> {
35+
from.with_path(|from| to.with_path(|to| super::rename(from, to)))
36+
}
37+
pub(crate) fn hard_link<P: AsPath, Q: AsPath>(original: P, link: Q) -> io::Result<()> {
38+
original.with_path(|original| link.with_path(|link| super::link(original, link)))
39+
}
40+
pub(crate) fn soft_link<P: AsPath, Q: AsPath>(original: P, link: Q) -> io::Result<()> {
41+
original.with_path(|original| link.with_path(|link| super::symlink(original, link)))
42+
}
43+
pub(crate) fn remove_dir<P: AsPath>(path: P) -> io::Result<()> {
44+
path.with_path(super::rmdir)
45+
}
46+
pub(crate) fn read_dir<P: AsPath>(path: P) -> io::Result<ReadDir> {
47+
path.with_path(super::readdir)
48+
}
49+
pub(crate) fn set_permissions<P: AsPath>(path: P, perms: FilePermissions) -> io::Result<()> {
50+
path.with_path(|path| super::set_perm(path, perms))
51+
}
52+
pub(crate) fn copy<P: AsPath, Q: AsPath>(from: P, to: Q) -> io::Result<u64> {
53+
from.with_path(|from| to.with_path(|to| super::copy(from, to)))
54+
}
55+
pub(crate) fn canonicalize<P: AsPath>(path: P) -> io::Result<PathBuf> {
56+
path.with_path(super::canonicalize)
57+
}
58+
pub(crate) fn remove_dir_all<P: AsPath>(path: P) -> io::Result<()> {
59+
path.with_path(super::remove_dir_all)
60+
}
61+
pub(crate) fn read_link<P: AsPath>(path: P) -> io::Result<PathBuf> {
62+
path.with_path(super::readlink)
63+
}
64+
pub(crate) fn try_exists<P: AsPath>(path: P) -> io::Result<bool> {
65+
path.with_path(super::try_exists)
66+
}
67+
}
68+
1769
/// A file descriptor.
1870
#[derive(Clone, Copy)]
1971
#[rustc_layout_scalar_valid_range_start(0)]
@@ -325,14 +377,17 @@ fn cstr(path: &Path) -> io::Result<CString> {
325377

326378
impl File {
327379
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
380+
Self::open_native(&cstr(path)?, opts)
381+
}
382+
pub fn open_native(path: &CStr, opts: &OpenOptions) -> io::Result<File> {
328383
let flags = opts.get_access_mode()?
329384
| opts.get_creation_mode()?
330385
| (opts.custom_flags as c_int & !abi::O_ACCMODE);
331386
unsafe {
332387
let mut fd = MaybeUninit::uninit();
333388
error::SolidError::err_if_negative(abi::SOLID_FS_Open(
334389
fd.as_mut_ptr(),
335-
cstr(path)?.as_ptr(),
390+
path.as_ptr(),
336391
flags,
337392
))
338393
.map_err(|e| e.as_io_error())?;

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

+56-58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ffi::OsString;
1+
use crate::ffi::{CStr, OsString};
22
use crate::fmt;
33
use crate::hash::{Hash, Hasher};
44
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
@@ -14,6 +14,60 @@ pub struct ReadDir(!);
1414

1515
pub struct DirEntry(!);
1616

17+
#[allow(unused_variables)]
18+
pub(crate) mod fs_imp {
19+
use super::unsupported;
20+
pub(crate) use super::{
21+
DirBuilder, DirEntry, File, FileAttr, FilePermissions, FileTimes, FileType, OpenOptions,
22+
ReadDir,
23+
};
24+
use crate::io;
25+
use crate::path::{AsPath, PathBuf};
26+
27+
pub(crate) fn remove_file<P: AsPath>(path: P) -> io::Result<()> {
28+
unsupported()
29+
}
30+
pub(crate) fn symlink_metadata<P: AsPath>(path: P) -> io::Result<FileAttr> {
31+
unsupported()
32+
}
33+
pub(crate) fn metadata<P: AsPath>(path: P) -> io::Result<FileAttr> {
34+
unsupported()
35+
}
36+
pub(crate) fn rename<P: AsPath, Q: AsPath>(from: P, to: Q) -> io::Result<()> {
37+
unsupported()
38+
}
39+
pub(crate) fn hard_link<P: AsPath, Q: AsPath>(original: P, link: Q) -> io::Result<()> {
40+
unsupported()
41+
}
42+
pub(crate) fn soft_link<P: AsPath, Q: AsPath>(original: P, link: Q) -> io::Result<()> {
43+
unsupported()
44+
}
45+
pub(crate) fn remove_dir<P: AsPath>(path: P) -> io::Result<()> {
46+
unsupported()
47+
}
48+
pub(crate) fn read_dir<P: AsPath>(path: P) -> io::Result<ReadDir> {
49+
unsupported()
50+
}
51+
pub(crate) fn set_permissions<P: AsPath>(path: P, perms: FilePermissions) -> io::Result<()> {
52+
unsupported()
53+
}
54+
pub(crate) fn copy<P: AsPath, Q: AsPath>(from: P, to: Q) -> io::Result<u64> {
55+
unsupported()
56+
}
57+
pub(crate) fn canonicalize<P: AsPath>(path: P) -> io::Result<PathBuf> {
58+
unsupported()
59+
}
60+
pub(crate) fn remove_dir_all<P: AsPath>(path: P) -> io::Result<()> {
61+
unsupported()
62+
}
63+
pub(crate) fn read_link<P: AsPath>(path: P) -> io::Result<PathBuf> {
64+
unsupported()
65+
}
66+
pub(crate) fn try_exists<P: AsPath>(path: P) -> io::Result<bool> {
67+
unsupported()
68+
}
69+
}
70+
1771
#[derive(Clone, Debug)]
1872
pub struct OpenOptions {}
1973

@@ -182,7 +236,7 @@ impl OpenOptions {
182236
}
183237

184238
impl File {
185-
pub fn open(_path: &Path, _opts: &OpenOptions) -> io::Result<File> {
239+
pub fn open_native(_path: &CStr, _opts: &OpenOptions) -> io::Result<File> {
186240
unsupported()
187241
}
188242

@@ -266,59 +320,3 @@ impl fmt::Debug for File {
266320
self.0
267321
}
268322
}
269-
270-
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
271-
unsupported()
272-
}
273-
274-
pub fn unlink(_p: &Path) -> io::Result<()> {
275-
unsupported()
276-
}
277-
278-
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
279-
unsupported()
280-
}
281-
282-
pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> {
283-
match perm.0 {}
284-
}
285-
286-
pub fn rmdir(_p: &Path) -> io::Result<()> {
287-
unsupported()
288-
}
289-
290-
pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
291-
unsupported()
292-
}
293-
294-
pub fn try_exists(_path: &Path) -> io::Result<bool> {
295-
unsupported()
296-
}
297-
298-
pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
299-
unsupported()
300-
}
301-
302-
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
303-
unsupported()
304-
}
305-
306-
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
307-
unsupported()
308-
}
309-
310-
pub fn stat(_p: &Path) -> io::Result<FileAttr> {
311-
unsupported()
312-
}
313-
314-
pub fn lstat(_p: &Path) -> io::Result<FileAttr> {
315-
unsupported()
316-
}
317-
318-
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
319-
unsupported()
320-
}
321-
322-
pub fn copy(_from: &Path, _to: &Path) -> io::Result<u64> {
323-
unsupported()
324-
}

0 commit comments

Comments
 (0)