33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6- #![ cfg_attr( target_os = "wasi" , feature( wasi_ext) ) ]
7-
86// spell-checker:ignore (ToDO) srcpath targetpath EEXIST
97
108use clap:: { Arg , ArgAction , Command } ;
@@ -21,10 +19,12 @@ use std::ffi::OsString;
2119use std:: fs;
2220use thiserror:: Error ;
2321
22+ #[ cfg( target_os = "wasi" ) ]
23+ use std:: ffi:: CString ;
24+ #[ cfg( target_os = "wasi" ) ]
25+ use std:: io;
2426#[ cfg( any( unix, target_os = "redox" ) ) ]
2527use std:: os:: unix:: fs:: symlink;
26- #[ cfg( target_os = "wasi" ) ]
27- use std:: os:: wasi:: fs:: symlink_path as symlink;
2828#[ cfg( windows) ]
2929use std:: os:: windows:: fs:: { symlink_dir, symlink_file} ;
3030use std:: path:: { Path , PathBuf } ;
@@ -492,3 +492,19 @@ pub fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> std::io::R
492492 symlink_file ( src, dst)
493493 }
494494}
495+
496+ #[ cfg( target_os = "wasi" ) ]
497+ pub fn symlink < P1 : AsRef < Path > , P2 : AsRef < Path > > ( src : P1 , dst : P2 ) -> io:: Result < ( ) > {
498+ use std:: os:: wasi:: ffi:: OsStrExt ;
499+
500+ let src_c = CString :: new ( src. as_ref ( ) . as_os_str ( ) . as_bytes ( ) )
501+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
502+ let dst_c = CString :: new ( dst. as_ref ( ) . as_os_str ( ) . as_bytes ( ) )
503+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
504+
505+ if unsafe { libc:: symlink ( src_c. as_ptr ( ) , dst_c. as_ptr ( ) ) } == 0 {
506+ Ok ( ( ) )
507+ } else {
508+ Err ( io:: Error :: last_os_error ( ) )
509+ }
510+ }
0 commit comments