Keep old symlink; expose new symlink_path

This commit is contained in:
Ingvar Stepanyan 2021-02-03 15:45:30 +00:00 committed by GitHub
parent 5882cce54e
commit 1578f2e1e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -502,11 +502,21 @@ pub fn rename<P: AsRef<Path>, U: AsRef<Path>>(
)
}
/// This corresponds to the `path_symlink` syscall.
pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(
old_path: P,
fd: &File,
new_path: U,
) -> io::Result<()> {
fd.as_inner()
.fd()
.symlink(osstr2str(old_path.as_ref().as_ref())?, osstr2str(new_path.as_ref().as_ref())?)
}
/// Create a symbolic link.
///
/// This is similar to [`std::os::unix::fs::symlink`] and
/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir)
/// counterparts.
pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) -> io::Result<()> {
/// This is a convenience API similar to [`std::os::unix::fs::symlink`] and
/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir).
pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) -> io::Result<()> {
crate::sys::fs::symlink(old_path.as_ref(), new_path.as_ref())
}