File tree 2 files changed +15
-6
lines changed
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -420,12 +420,19 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
420
420
}
421
421
422
422
pub fn readlink ( p : & Path ) -> io:: Result < PathBuf > {
423
- canonicalize ( p)
424
- }
425
-
426
- pub fn symlink ( _src : & Path , _dst : & Path ) -> io:: Result < ( ) > {
427
- :: sys_common:: util:: dumb_print ( format_args ! ( "Symlink\n " ) ) ;
428
- unimplemented ! ( ) ;
423
+ let fd = cvt ( syscall:: open ( p. to_str ( ) . unwrap ( ) , syscall:: O_SYMLINK | syscall:: O_RDONLY ) ) ?;
424
+ let mut buf: [ u8 ; 4096 ] = [ 0 ; 4096 ] ;
425
+ let count = cvt ( syscall:: read ( fd, & mut buf) ) ?;
426
+ cvt ( syscall:: close ( fd) ) ?;
427
+ Ok ( PathBuf :: from ( unsafe { String :: from_utf8_unchecked ( Vec :: from ( & buf[ ..count] ) ) } ) )
428
+ }
429
+
430
+ pub fn symlink ( src : & Path , dst : & Path ) -> io:: Result < ( ) > {
431
+ let fd = cvt ( syscall:: open ( dst. to_str ( ) . unwrap ( ) ,
432
+ syscall:: O_SYMLINK | syscall:: O_CREAT | syscall:: O_WRONLY | 0o777 ) ) ?;
433
+ cvt ( syscall:: write ( fd, src. to_str ( ) . unwrap ( ) . as_bytes ( ) ) ) ?;
434
+ cvt ( syscall:: close ( fd) ) ?;
435
+ Ok ( ( ) )
429
436
}
430
437
431
438
pub fn link ( _src : & Path , _dst : & Path ) -> io:: Result < ( ) > {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ pub const MAP_WRITE_COMBINE: usize = 2;
33
33
pub const MODE_TYPE : u16 = 0xF000 ;
34
34
pub const MODE_DIR : u16 = 0x4000 ;
35
35
pub const MODE_FILE : u16 = 0x8000 ;
36
+ pub const MODE_SYMLINK : u16 = 0xA000 ;
36
37
37
38
pub const MODE_PERM : u16 = 0x0FFF ;
38
39
pub const MODE_SETUID : u16 = 0o4000 ;
@@ -53,6 +54,7 @@ pub const O_TRUNC: usize = 0x0400_0000;
53
54
pub const O_EXCL : usize = 0x0800_0000 ;
54
55
pub const O_DIRECTORY : usize = 0x1000_0000 ;
55
56
pub const O_STAT : usize = 0x2000_0000 ;
57
+ pub const O_SYMLINK : usize = 0x4000_0000 ;
56
58
pub const O_ACCMODE : usize = O_RDONLY | O_WRONLY | O_RDWR ;
57
59
58
60
pub const SEEK_SET : usize = 0 ;
You can’t perform that action at this time.
0 commit comments