Expand description
§portable-symlink
portable-symlink creates and removes symbolic links on Unix and Windows. Its six functions use the Rust standard library and add no package dependencies.
Removal functions inspect the path with symlink_metadata before deleting it. A regular file or directory returns InvalidInput and stays in place. Removal affects the link. The target and its contents stay intact.
§Usage
use portable_symlink::{remove_symlink_auto, symlink_auto};
symlink_auto("records/current.log", "latest.log")?;
remove_symlink_auto("latest.log")?;The creation functions take (target, link) in that order:
symlink_filecreates a file-kind link on Windows.symlink_dircreates a directory-kind link on Windows.symlink_autoprobes the target on Windows and selects its kind.
Unix links do not carry a file or directory kind, so the three creation functions call the same operating system function there.
§Removal
remove_symlink_fileremoves a file-kind link.remove_symlink_dirremoves a directory-kind link or Windows junction.remove_symlink_autoreads the Windows kind and selects the matching removal function.
On Windows, passing the wrong kind to an explicit removal function returns InvalidInput. The automatic removal function handles either kind. A process still needs the Windows symbolic-link privilege or Developer Mode to create links.
§Relation to the symlink crate
This crate is an independent implementation. It is not affiliated with the author of the symlink crate. It keeps the same six function names and generic argument forms. Three behavior changes protect callers and fix Windows path handling:
- Every removal function refuses a regular file or directory.
- Windows
symlink_autoresolves a relative target from the link’s parent directory. A missing target returns the probe error. - Windows
remove_symlink_autoremoves file-kind and directory-kind links, including dangling links, after inspecting the link itself.
Targets outside Unix and Windows expose all six functions and return Unsupported.
§Rust version
The minimum supported Rust version is 1.63.0.
§License
MIT
Functions§
- remove_
symlink_ auto - Removes a symbolic link after reading its Windows kind.
- remove_
symlink_ dir - Removes a directory-kind symbolic link or Windows junction.
- remove_
symlink_ file - Removes a file-kind symbolic link.
- symlink_
auto - Creates a symbolic link and selects its Windows kind from the target.
- symlink_
dir - Creates a directory-kind symbolic link at
linkthat points totarget. - symlink_
file - Creates a file-kind symbolic link at
linkthat points totarget.