-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Start using with_native_path
in std::sys::fs
#138832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,115 @@ | ||
#![deny(unsafe_op_in_unsafe_fn)] | ||
|
||
use crate::io; | ||
use crate::path::{Path, PathBuf}; | ||
|
||
pub mod common; | ||
|
||
cfg_if::cfg_if! { | ||
if #[cfg(target_family = "unix")] { | ||
mod unix; | ||
pub use unix::*; | ||
use unix as imp; | ||
pub use unix::{chown, fchown, lchown}; | ||
#[cfg(not(target_os = "fuchsia"))] | ||
pub use unix::chroot; | ||
pub(crate) use unix::debug_assert_fd_is_open; | ||
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
pub(crate) use unix::CachedFileMetadata; | ||
use crate::sys::common::small_c_string::run_path_with_cstr as with_native_path; | ||
} else if #[cfg(target_os = "windows")] { | ||
mod windows; | ||
pub use windows::*; | ||
use windows as imp; | ||
pub use windows::{symlink_inner, junction_point}; | ||
} else if #[cfg(target_os = "hermit")] { | ||
mod hermit; | ||
pub use hermit::*; | ||
use hermit as imp; | ||
} else if #[cfg(target_os = "solid_asp3")] { | ||
mod solid; | ||
pub use solid::*; | ||
use solid as imp; | ||
} else if #[cfg(target_os = "uefi")] { | ||
mod uefi; | ||
pub use uefi::*; | ||
use uefi as imp; | ||
} else if #[cfg(target_os = "wasi")] { | ||
mod wasi; | ||
pub use wasi::*; | ||
use wasi as imp; | ||
} else { | ||
mod unsupported; | ||
pub use unsupported::*; | ||
use unsupported as imp; | ||
} | ||
} | ||
|
||
// FIXME: Replace this with platform-specific path conversion functions. | ||
#[cfg(not(target_family = "unix"))] | ||
#[inline] | ||
pub fn with_native_path<T>(path: &Path, f: &dyn Fn(&Path) -> io::Result<T>) -> io::Result<T> { | ||
f(path) | ||
} | ||
|
||
pub use imp::{ | ||
DirBuilder, DirEntry, File, FileAttr, FilePermissions, FileTimes, FileType, OpenOptions, | ||
ReadDir, | ||
}; | ||
|
||
pub fn read_dir(path: &Path) -> io::Result<ReadDir> { | ||
// FIXME: use with_native_path | ||
imp::readdir(path) | ||
} | ||
|
||
pub fn remove_file(path: &Path) -> io::Result<()> { | ||
with_native_path(path, &imp::unlink) | ||
} | ||
|
||
pub fn rename(old: &Path, new: &Path) -> io::Result<()> { | ||
with_native_path(old, &|old| with_native_path(new, &|new| imp::rename(old, new))) | ||
} | ||
|
||
pub fn remove_dir(path: &Path) -> io::Result<()> { | ||
with_native_path(path, &imp::rmdir) | ||
} | ||
|
||
pub fn remove_dir_all(path: &Path) -> io::Result<()> { | ||
// FIXME: use with_native_path | ||
imp::remove_dir_all(path) | ||
} | ||
|
||
pub fn read_link(path: &Path) -> io::Result<PathBuf> { | ||
with_native_path(path, &imp::readlink) | ||
} | ||
|
||
pub fn symlink(original: &Path, link: &Path) -> io::Result<()> { | ||
with_native_path(original, &|original| { | ||
with_native_path(link, &|link| imp::symlink(original, link)) | ||
}) | ||
} | ||
|
||
pub fn hard_link(original: &Path, link: &Path) -> io::Result<()> { | ||
with_native_path(original, &|original| { | ||
with_native_path(link, &|link| imp::link(original, link)) | ||
}) | ||
} | ||
|
||
pub fn metadata(path: &Path) -> io::Result<FileAttr> { | ||
with_native_path(path, &imp::stat) | ||
} | ||
|
||
pub fn symlink_metadata(path: &Path) -> io::Result<FileAttr> { | ||
with_native_path(path, &imp::lstat) | ||
} | ||
|
||
pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> { | ||
with_native_path(path, &|path| imp::set_perm(path, perm.clone())) | ||
} | ||
|
||
pub fn canonicalize(path: &Path) -> io::Result<PathBuf> { | ||
with_native_path(path, &imp::canonicalize) | ||
} | ||
|
||
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { | ||
// FIXME: use with_native_path | ||
imp::copy(from, to) | ||
} | ||
|
||
pub fn exists(path: &Path) -> io::Result<bool> { | ||
// FIXME: use with_native_path | ||
imp::exists(path) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.