Skip to content

Commit 1578f2e

Browse files
authored
Keep old symlink; expose new symlink_path
1 parent 5882cce commit 1578f2e

File tree

1 file changed

+14
-4
lines changed
  • library/std/src/sys/wasi/ext

1 file changed

+14
-4
lines changed

library/std/src/sys/wasi/ext/fs.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,21 @@ pub fn rename<P: AsRef<Path>, U: AsRef<Path>>(
502502
)
503503
}
504504

505+
/// This corresponds to the `path_symlink` syscall.
506+
pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(
507+
old_path: P,
508+
fd: &File,
509+
new_path: U,
510+
) -> io::Result<()> {
511+
fd.as_inner()
512+
.fd()
513+
.symlink(osstr2str(old_path.as_ref().as_ref())?, osstr2str(new_path.as_ref().as_ref())?)
514+
}
515+
505516
/// Create a symbolic link.
506517
///
507-
/// This is similar to [`std::os::unix::fs::symlink`] and
508-
/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir)
509-
/// counterparts.
510-
pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) -> io::Result<()> {
518+
/// This is a convenience API similar to [`std::os::unix::fs::symlink`] and
519+
/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir).
520+
pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) -> io::Result<()> {
511521
crate::sys::fs::symlink(old_path.as_ref(), new_path.as_ref())
512522
}

0 commit comments

Comments
 (0)