File tree Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change
1
+ use std:: io;
2
+ use std:: path:: { Path , PathBuf } ;
3
+
4
+ /// https://github.com/oxc-project/oxc-resolver/blob/42a1e3eb50e9a1365c422c41d51f287fe5fb8244/src/file_system.rs#L93-L122
5
+ pub fn canonicalize < P : AsRef < Path > > ( path : P ) -> io:: Result < PathBuf > {
6
+ #[ cfg( not( target_os = "wasi" ) ) ]
7
+ {
8
+ dunce:: canonicalize ( path)
9
+ }
10
+ #[ cfg( target_os = "wasi" ) ]
11
+ {
12
+ use std:: fs;
13
+ let path = path. as_ref ( ) ;
14
+ let meta = fs:: symlink_metadata ( path) ?;
15
+ if meta. file_type ( ) . is_symlink ( ) {
16
+ let link = fs:: read_link ( path) ?;
17
+ let mut path_buf = path. to_path_buf ( ) ;
18
+ path_buf. pop ( ) ;
19
+ for segment in link. iter ( ) {
20
+ match segment. to_str ( ) {
21
+ Some ( ".." ) => {
22
+ path_buf. pop ( ) ;
23
+ }
24
+ Some ( "." ) | None => { }
25
+ Some ( seg) => {
26
+ // Need to trim the extra \0 introduces by rust std rust-lang/rust#123727
27
+ path_buf. push ( seg. trim_end_matches ( '\0' ) ) ;
28
+ }
29
+ }
30
+ }
31
+ Ok ( path_buf)
32
+ } else {
33
+ Ok ( path. to_path_buf ( ) )
34
+ }
35
+ }
36
+ }
Original file line number Diff line number Diff line change 1
1
pub mod auto_source_detection;
2
2
pub mod detect_sources;
3
3
pub mod sources;
4
+ mod fsops;
4
5
5
6
use crate :: extractor:: { Extracted , Extractor } ;
6
7
use crate :: glob:: optimize_patterns;
@@ -63,7 +64,7 @@ fn init_tracing() {
63
64
. unwrap_or_else ( |_| panic ! ( "Failed to open {file_path}" ) ) ;
64
65
65
66
let file_path = Path :: new ( & file_path) ;
66
- let absolute_file_path = dunce :: canonicalize ( file_path)
67
+ let absolute_file_path = fsops :: canonicalize ( file_path)
67
68
. unwrap_or_else ( |_| panic ! ( "Failed to canonicalize {file_path:?}" ) ) ;
68
69
eprintln ! (
69
70
"{} Writing debug info to: {}\n " ,
@@ -215,7 +216,7 @@ impl Scanner {
215
216
. into_iter ( )
216
217
. filter_map ( |changed_content| match changed_content {
217
218
ChangedContent :: File ( file, extension) => {
218
- let Ok ( file) = dunce :: canonicalize ( file) else {
219
+ let Ok ( file) = fsops :: canonicalize ( file) else {
219
220
return None ;
220
221
} ;
221
222
Some ( ChangedContent :: File ( file, extension) )
Original file line number Diff line number Diff line change 1
- use crate :: glob:: split_pattern;
1
+ use crate :: { glob:: split_pattern, scanner :: fsops } ;
2
2
use crate :: GlobEntry ;
3
3
use bexpand:: Expression ;
4
4
use std:: path:: PathBuf ;
@@ -102,7 +102,7 @@ impl PublicSourceEntry {
102
102
/// resolved path.
103
103
pub fn optimize ( & mut self ) {
104
104
// Resolve base path immediately
105
- let Ok ( base) = dunce :: canonicalize ( & self . base ) else {
105
+ let Ok ( base) = fsops :: canonicalize ( & self . base ) else {
106
106
event ! ( Level :: ERROR , "Failed to resolve base: {:?}" , self . base) ;
107
107
return ;
108
108
} ;
@@ -116,7 +116,7 @@ impl PublicSourceEntry {
116
116
PathBuf :: from ( & self . base ) . join ( & self . pattern )
117
117
} ;
118
118
119
- match dunce :: canonicalize ( combined_path) {
119
+ match fsops :: canonicalize ( combined_path) {
120
120
Ok ( resolved_path) if resolved_path. is_dir ( ) => {
121
121
self . base = resolved_path. to_string_lossy ( ) . to_string ( ) ;
122
122
self . pattern = "**/*" . to_owned ( ) ;
@@ -144,7 +144,7 @@ impl PublicSourceEntry {
144
144
Some ( static_part) => {
145
145
// TODO: If the base does not exist on disk, try removing the last slash and try
146
146
// again.
147
- match dunce :: canonicalize ( base. join ( static_part) ) {
147
+ match fsops :: canonicalize ( base. join ( static_part) ) {
148
148
Ok ( base) => base,
149
149
Err ( err) => {
150
150
event ! ( tracing:: Level :: ERROR , "Failed to resolve glob: {:?}" , err) ;
You can’t perform that action at this time.
0 commit comments