@@ -759,30 +759,32 @@ pub fn readlink(path: &Path) -> io::Result<PathBuf> {
759
759
file. readlink ( )
760
760
}
761
761
762
- pub fn symlink ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
763
- symlink_inner ( src , dst , false )
762
+ pub fn symlink ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
763
+ symlink_inner ( original , link , false )
764
764
}
765
765
766
- pub fn symlink_inner ( src : & Path , dst : & Path , dir : bool ) -> io:: Result < ( ) > {
767
- let src = to_u16s ( src ) ?;
768
- let dst = to_u16s ( dst ) ?;
766
+ pub fn symlink_inner ( original : & Path , link : & Path , dir : bool ) -> io:: Result < ( ) > {
767
+ let original = to_u16s ( original ) ?;
768
+ let link = to_u16s ( link ) ?;
769
769
let flags = if dir { c:: SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 } ;
770
770
// Formerly, symlink creation required the SeCreateSymbolicLink privilege. For the Windows 10
771
771
// Creators Update, Microsoft loosened this to allow unprivileged symlink creation if the
772
772
// computer is in Developer Mode, but SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE must be
773
773
// added to dwFlags to opt into this behaviour.
774
774
let result = cvt ( unsafe {
775
775
c:: CreateSymbolicLinkW (
776
- dst . as_ptr ( ) ,
777
- src . as_ptr ( ) ,
776
+ link . as_ptr ( ) ,
777
+ original . as_ptr ( ) ,
778
778
flags | c:: SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE ,
779
779
) as c:: BOOL
780
780
} ) ;
781
781
if let Err ( err) = result {
782
782
if err. raw_os_error ( ) == Some ( c:: ERROR_INVALID_PARAMETER as i32 ) {
783
783
// Older Windows objects to SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
784
784
// so if we encounter ERROR_INVALID_PARAMETER, retry without that flag.
785
- cvt ( unsafe { c:: CreateSymbolicLinkW ( dst. as_ptr ( ) , src. as_ptr ( ) , flags) as c:: BOOL } ) ?;
785
+ cvt ( unsafe {
786
+ c:: CreateSymbolicLinkW ( link. as_ptr ( ) , original. as_ptr ( ) , flags) as c:: BOOL
787
+ } ) ?;
786
788
} else {
787
789
return Err ( err) ;
788
790
}
@@ -791,15 +793,15 @@ pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> {
791
793
}
792
794
793
795
#[ cfg( not( target_vendor = "uwp" ) ) ]
794
- pub fn link ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
795
- let src = to_u16s ( src ) ?;
796
- let dst = to_u16s ( dst ) ?;
797
- cvt ( unsafe { c:: CreateHardLinkW ( dst . as_ptr ( ) , src . as_ptr ( ) , ptr:: null_mut ( ) ) } ) ?;
796
+ pub fn link ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
797
+ let original = to_u16s ( original ) ?;
798
+ let link = to_u16s ( link ) ?;
799
+ cvt ( unsafe { c:: CreateHardLinkW ( link . as_ptr ( ) , original . as_ptr ( ) , ptr:: null_mut ( ) ) } ) ?;
798
800
Ok ( ( ) )
799
801
}
800
802
801
803
#[ cfg( target_vendor = "uwp" ) ]
802
- pub fn link ( _src : & Path , _dst : & Path ) -> io:: Result < ( ) > {
804
+ pub fn link ( _original : & Path , _link : & Path ) -> io:: Result < ( ) > {
803
805
return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "hard link are not supported on UWP" ) ) ;
804
806
}
805
807
@@ -883,8 +885,11 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
883
885
}
884
886
885
887
#[ allow( dead_code) ]
886
- pub fn symlink_junction < P : AsRef < Path > , Q : AsRef < Path > > ( src : P , dst : Q ) -> io:: Result < ( ) > {
887
- symlink_junction_inner ( src. as_ref ( ) , dst. as_ref ( ) )
888
+ pub fn symlink_junction < P : AsRef < Path > , Q : AsRef < Path > > (
889
+ original : P ,
890
+ junction : Q ,
891
+ ) -> io:: Result < ( ) > {
892
+ symlink_junction_inner ( original. as_ref ( ) , junction. as_ref ( ) )
888
893
}
889
894
890
895
// 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
893
898
//
894
899
// http://www.flexhex.com/docs/articles/hard-links.phtml
895
900
#[ allow( dead_code) ]
896
- fn symlink_junction_inner ( target : & Path , junction : & Path ) -> io:: Result < ( ) > {
901
+ fn symlink_junction_inner ( original : & Path , junction : & Path ) -> io:: Result < ( ) > {
897
902
let d = DirBuilder :: new ( ) ;
898
903
d. mkdir ( & junction) ?;
899
904
@@ -911,7 +916,7 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
911
916
// FIXME: this conversion is very hacky
912
917
let v = br"\??\" ;
913
918
let v = v. iter ( ) . map ( |x| * x as u16 ) ;
914
- for c in v. chain ( target . as_os_str ( ) . encode_wide ( ) ) {
919
+ for c in v. chain ( original . as_os_str ( ) . encode_wide ( ) ) {
915
920
* buf. offset ( i) = c;
916
921
i += 1 ;
917
922
}
0 commit comments