File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change 1- use std:: io:: { Write , stdout} ;
1+ use std:: {
2+ io:: { Write , stdout} ,
3+ os:: unix:: ffi:: OsStringExt ,
4+ path:: PathBuf ,
5+ } ;
26
37use puppyutils:: { Result , cli} ;
4- use rustix:: process:: getcwd;
8+ use rustix:: { fs :: stat , process:: getcwd} ;
59fn main ( ) -> Result {
610 let mut stdout = stdout ( ) ;
7- cli ! ( "pwd" , stdout, #error) ;
811
9- let p = getcwd ( Vec :: new ( ) ) ? ;
12+ let mut logical = false ;
1013
11- stdout. write_all ( p. as_bytes ( ) ) ?;
14+ cli ! {
15+ "pwd" , stdout, #error
16+ Short ( 'L' ) | Long ( "logical" ) => logical = true
17+ Short ( 'P' ) | Long ( "physical" ) => logical = false
18+ } ;
19+
20+ let path = if logical
21+ && let Some ( path) = std:: env:: var_os ( "PWD" ) . map ( PathBuf :: from)
22+ && path. has_root ( )
23+ && let ( Ok ( pwd) , Ok ( dot) ) = ( stat ( & path) , stat ( c"." ) )
24+ && pwd. st_dev == dot. st_dev
25+ && pwd. st_ino == dot. st_ino
26+ {
27+ path. into_os_string ( ) . into_vec ( )
28+ } else {
29+ getcwd ( Vec :: new ( ) ) ?. into_bytes ( )
30+ } ;
31+
32+ stdout. write_all ( & path) ?;
1233 stdout. write_all ( b"\n " ) ?;
1334
1435 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments