Disambiguate symlink argument names

This commit is contained in:
David Tolnay 2020-11-14 14:40:08 -08:00
parent 98d66340d6
commit 29128a5aa2
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
9 changed files with 67 additions and 60 deletions

View file

@ -1698,12 +1698,14 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
/// Creates a new hard link on the filesystem. /// Creates a new hard link on the filesystem.
/// ///
/// The `dst` path will be a link pointing to the `src` path. Note that systems /// The `link` path will be a link pointing to the `original` path. Note that
/// often require these two paths to both be located on the same filesystem. /// systems often require these two paths to both be located on the same
/// filesystem.
/// ///
/// If `src` names a symbolic link, it is platform-specific whether the symbolic /// If `original` names a symbolic link, it is platform-specific whether the
/// link is followed. On platforms where it's possible to not follow it, it is /// symbolic link is followed. On platforms where it's possible to not follow
/// not followed, and the created hard link points to the symbolic link itself. /// it, it is not followed, and the created hard link points to the symbolic
/// link itself.
/// ///
/// # Platform-specific behavior /// # Platform-specific behavior
/// ///
@ -1718,7 +1720,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
/// This function will return an error in the following situations, but is not /// This function will return an error in the following situations, but is not
/// limited to just these cases: /// limited to just these cases:
/// ///
/// * The `src` path is not a file or doesn't exist. /// * The `original` path is not a file or doesn't exist.
/// ///
/// # Examples /// # Examples
/// ///
@ -1731,13 +1733,13 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
/// } /// }
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
fs_imp::link(src.as_ref(), dst.as_ref()) fs_imp::link(original.as_ref(), link.as_ref())
} }
/// Creates a new symbolic link on the filesystem. /// Creates a new symbolic link on the filesystem.
/// ///
/// The `dst` path will be a symbolic link pointing to the `src` path. /// The `link` path will be a symbolic link pointing to the `original` path.
/// On Windows, this will be a file symlink, not a directory symlink; /// On Windows, this will be a file symlink, not a directory symlink;
/// for this reason, the platform-specific [`std::os::unix::fs::symlink`] /// for this reason, the platform-specific [`std::os::unix::fs::symlink`]
/// and [`std::os::windows::fs::symlink_file`] or [`symlink_dir`] should be /// and [`std::os::windows::fs::symlink_file`] or [`symlink_dir`] should be
@ -1763,8 +1765,8 @@ pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<(
reason = "replaced with std::os::unix::fs::symlink and \ reason = "replaced with std::os::unix::fs::symlink and \
std::os::windows::fs::{symlink_file, symlink_dir}" std::os::windows::fs::{symlink_file, symlink_dir}"
)] )]
pub fn soft_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { pub fn soft_link<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
fs_imp::symlink(src.as_ref(), dst.as_ref()) fs_imp::symlink(original.as_ref(), link.as_ref())
} }
/// Reads a symbolic link, returning the file that the link points to. /// Reads a symbolic link, returning the file that the link points to.

View file

@ -283,7 +283,7 @@ pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
unsupported() unsupported()
} }
pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
unsupported() unsupported()
} }

View file

@ -377,11 +377,11 @@ pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
unsupported() unsupported()
} }
pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
unsupported() unsupported()
} }
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> { pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
unsupported() unsupported()
} }

View file

@ -841,7 +841,7 @@ impl DirEntryExt for fs::DirEntry {
/// Creates a new symbolic link on the filesystem. /// Creates a new symbolic link on the filesystem.
/// ///
/// The `dst` path will be a symbolic link pointing to the `src` path. /// The `link` path will be a symbolic link pointing to the `original` path.
/// ///
/// # Examples /// # Examples
/// ///
@ -854,8 +854,8 @@ impl DirEntryExt for fs::DirEntry {
/// } /// }
/// ``` /// ```
#[stable(feature = "symlink", since = "1.1.0")] #[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
sys::fs::symlink(src.as_ref(), dst.as_ref()) sys::fs::symlink(original.as_ref(), link.as_ref())
} }
/// Unix-specific extensions to [`fs::DirBuilder`]. /// Unix-specific extensions to [`fs::DirBuilder`].

View file

@ -1071,28 +1071,28 @@ pub fn readlink(p: &Path) -> io::Result<PathBuf> {
} }
} }
pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
let src = cstr(src)?; let original = cstr(original)?;
let dst = cstr(dst)?; let link = cstr(link)?;
cvt(unsafe { libc::symlink(src.as_ptr(), dst.as_ptr()) })?; cvt(unsafe { libc::symlink(original.as_ptr(), link.as_ptr()) })?;
Ok(()) Ok(())
} }
pub fn link(src: &Path, dst: &Path) -> io::Result<()> { pub fn link(original: &Path, link: &Path) -> io::Result<()> {
let src = cstr(src)?; let original = cstr(original)?;
let dst = cstr(dst)?; let link = cstr(link)?;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android"))] { if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android"))] {
// VxWorks, Redox, and old versions of Android lack `linkat`, so use // VxWorks, Redox, and old versions of Android lack `linkat`, so use
// `link` instead. POSIX leaves it implementation-defined whether // `link` instead. POSIX leaves it implementation-defined whether
// `link` follows symlinks, so rely on the `symlink_hard_link` test // `link` follows symlinks, so rely on the `symlink_hard_link` test
// in library/std/src/fs/tests.rs to check the behavior. // in library/std/src/fs/tests.rs to check the behavior.
cvt(unsafe { libc::link(src.as_ptr(), dst.as_ptr()) })?; cvt(unsafe { libc::link(original.as_ptr(), link.as_ptr()) })?;
} else { } else {
// Use `linkat` with `AT_FDCWD` instead of `link` as `linkat` gives // Use `linkat` with `AT_FDCWD` instead of `link` as `linkat` gives
// us a flag to specify how symlinks should be handled. Pass 0 as // us a flag to specify how symlinks should be handled. Pass 0 as
// the flags argument, meaning don't follow symlinks. // the flags argument, meaning don't follow symlinks.
cvt(unsafe { libc::linkat(libc::AT_FDCWD, src.as_ptr(), libc::AT_FDCWD, dst.as_ptr(), 0) })?; cvt(unsafe { libc::linkat(libc::AT_FDCWD, original.as_ptr(), libc::AT_FDCWD, link.as_ptr(), 0) })?;
} }
} }
Ok(()) Ok(())

View file

@ -279,7 +279,7 @@ pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
unsupported() unsupported()
} }
pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
unsupported() unsupported()
} }

View file

@ -549,19 +549,19 @@ fn read_link(fd: &WasiFd, file: &Path) -> io::Result<PathBuf> {
} }
} }
pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
let (dst, dst_file) = open_parent(dst)?; let (link, link_file) = open_parent(link)?;
dst.symlink(osstr2str(src.as_ref())?, osstr2str(dst_file.as_ref())?) link.symlink(osstr2str(original.as_ref())?, osstr2str(link_file.as_ref())?)
} }
pub fn link(src: &Path, dst: &Path) -> io::Result<()> { pub fn link(original: &Path, link: &Path) -> io::Result<()> {
let (src, src_file) = open_parent(src)?; let (original, original_file) = open_parent(original)?;
let (dst, dst_file) = open_parent(dst)?; let (link, link_file) = open_parent(link)?;
src.link( original.link(
wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, wasi::LOOKUPFLAGS_SYMLINK_FOLLOW,
osstr2str(src_file.as_ref())?, osstr2str(original_file.as_ref())?,
&dst, &link,
osstr2str(dst_file.as_ref())?, osstr2str(link_file.as_ref())?,
) )
} }

View file

@ -519,7 +519,7 @@ impl FileTypeExt for fs::FileType {
/// Creates a new file symbolic link on the filesystem. /// Creates a new file symbolic link on the filesystem.
/// ///
/// The `dst` path will be a file symbolic link pointing to the `src` /// The `link` path will be a file symbolic link pointing to the `original`
/// path. /// path.
/// ///
/// # Examples /// # Examples
@ -533,13 +533,13 @@ impl FileTypeExt for fs::FileType {
/// } /// }
/// ``` /// ```
#[stable(feature = "symlink", since = "1.1.0")] #[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), false) sys::fs::symlink_inner(original.as_ref(), link.as_ref(), false)
} }
/// Creates a new directory symlink on the filesystem. /// Creates a new directory symlink on the filesystem.
/// ///
/// The `dst` path will be a directory symbolic link pointing to the `src` /// The `link` path will be a directory symbolic link pointing to the `original`
/// path. /// path.
/// ///
/// # Examples /// # Examples
@ -553,6 +553,6 @@ pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Resul
/// } /// }
/// ``` /// ```
#[stable(feature = "symlink", since = "1.1.0")] #[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), true) sys::fs::symlink_inner(original.as_ref(), link.as_ref(), true)
} }

View file

@ -759,13 +759,13 @@ pub fn readlink(path: &Path) -> io::Result<PathBuf> {
file.readlink() file.readlink()
} }
pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
symlink_inner(src, dst, false) symlink_inner(original, link, false)
} }
pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> { pub fn symlink_inner(original: &Path, link: &Path, dir: bool) -> io::Result<()> {
let src = to_u16s(src)?; let original = to_u16s(original)?;
let dst = to_u16s(dst)?; let link = to_u16s(link)?;
let flags = if dir { c::SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 }; let flags = if dir { c::SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 };
// Formerly, symlink creation required the SeCreateSymbolicLink privilege. For the Windows 10 // Formerly, symlink creation required the SeCreateSymbolicLink privilege. For the Windows 10
// Creators Update, Microsoft loosened this to allow unprivileged symlink creation if the // Creators Update, Microsoft loosened this to allow unprivileged symlink creation if the
@ -773,8 +773,8 @@ pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> {
// added to dwFlags to opt into this behaviour. // added to dwFlags to opt into this behaviour.
let result = cvt(unsafe { let result = cvt(unsafe {
c::CreateSymbolicLinkW( c::CreateSymbolicLinkW(
dst.as_ptr(), link.as_ptr(),
src.as_ptr(), original.as_ptr(),
flags | c::SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, flags | c::SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
) as c::BOOL ) as c::BOOL
}); });
@ -782,7 +782,9 @@ pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> {
if err.raw_os_error() == Some(c::ERROR_INVALID_PARAMETER as i32) { if err.raw_os_error() == Some(c::ERROR_INVALID_PARAMETER as i32) {
// Older Windows objects to SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, // Older Windows objects to SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
// so if we encounter ERROR_INVALID_PARAMETER, retry without that flag. // so if we encounter ERROR_INVALID_PARAMETER, retry without that flag.
cvt(unsafe { c::CreateSymbolicLinkW(dst.as_ptr(), src.as_ptr(), flags) as c::BOOL })?; cvt(unsafe {
c::CreateSymbolicLinkW(link.as_ptr(), original.as_ptr(), flags) as c::BOOL
})?;
} else { } else {
return Err(err); return Err(err);
} }
@ -791,15 +793,15 @@ pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> {
} }
#[cfg(not(target_vendor = "uwp"))] #[cfg(not(target_vendor = "uwp"))]
pub fn link(src: &Path, dst: &Path) -> io::Result<()> { pub fn link(original: &Path, link: &Path) -> io::Result<()> {
let src = to_u16s(src)?; let original = to_u16s(original)?;
let dst = to_u16s(dst)?; let link = to_u16s(link)?;
cvt(unsafe { c::CreateHardLinkW(dst.as_ptr(), src.as_ptr(), ptr::null_mut()) })?; cvt(unsafe { c::CreateHardLinkW(link.as_ptr(), original.as_ptr(), ptr::null_mut()) })?;
Ok(()) Ok(())
} }
#[cfg(target_vendor = "uwp")] #[cfg(target_vendor = "uwp")]
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> { pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
return Err(io::Error::new(io::ErrorKind::Other, "hard link are not supported on UWP")); return Err(io::Error::new(io::ErrorKind::Other, "hard link are not supported on UWP"));
} }
@ -883,8 +885,11 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(
symlink_junction_inner(src.as_ref(), dst.as_ref()) original: P,
junction: Q,
) -> io::Result<()> {
symlink_junction_inner(original.as_ref(), junction.as_ref())
} }
// Creating a directory junction on windows involves dealing with reparse // Creating a directory junction on windows involves dealing with reparse
@ -893,7 +898,7 @@ pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::R
// //
// http://www.flexhex.com/docs/articles/hard-links.phtml // http://www.flexhex.com/docs/articles/hard-links.phtml
#[allow(dead_code)] #[allow(dead_code)]
fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { fn symlink_junction_inner(original: &Path, junction: &Path) -> io::Result<()> {
let d = DirBuilder::new(); let d = DirBuilder::new();
d.mkdir(&junction)?; d.mkdir(&junction)?;
@ -911,7 +916,7 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
// FIXME: this conversion is very hacky // FIXME: this conversion is very hacky
let v = br"\??\"; let v = br"\??\";
let v = v.iter().map(|x| *x as u16); let v = v.iter().map(|x| *x as u16);
for c in v.chain(target.as_os_str().encode_wide()) { for c in v.chain(original.as_os_str().encode_wide()) {
*buf.offset(i) = c; *buf.offset(i) = c;
i += 1; i += 1;
} }