1010
1111#include "../include/appling.h"
1212
13+ static void
14+ appling__bootstrap_log (const char * tag , const char * detail ) {
15+ const char * log_path = getenv ("PEAR_BOOTSTRAP_LOG" );
16+ if (!log_path || !log_path [0 ]) return ;
17+
18+ FILE * fp = fopen (log_path , "a" );
19+ if (!fp ) return ;
20+
21+ fprintf (fp , "[%llu] %s: %s\n" ,
22+ (unsigned long long ) uv_hrtime (),
23+ tag ? tag : "(null)" ,
24+ detail ? detail : ""
25+ );
26+
27+ fclose (fp );
28+ }
29+
1330static void
1431appling_resolve__realpath (appling_resolve_t * req );
1532
1633static void
1734appling_resolve__on_close (fs_close_t * fs_req , int status ) {
1835 appling_resolve_t * req = (appling_resolve_t * ) fs_req -> data ;
1936
37+ if (!req ) {
38+ appling__bootstrap_log ("resolve-close" , "req-null" );
39+ return ;
40+ }
41+
42+ {
43+ char buf [128 ];
44+ snprintf (buf , sizeof (buf ), "status=%d" , status );
45+ appling__bootstrap_log ("resolve-close" , buf );
46+ }
47+
2048 if (req -> status < 0 ) status = req -> status ;
2149
2250 if (status >= 0 ) {
@@ -35,6 +63,11 @@ appling_resolve__on_read(fs_read_t *fs_req, int status, size_t read) {
3563
3664 appling_resolve_t * req = (appling_resolve_t * ) fs_req -> data ;
3765
66+ if (!req ) {
67+ appling__bootstrap_log ("resolve-read" , "req-null" );
68+ return ;
69+ }
70+
3871 if (status >= 0 ) {
3972 compact_state_t state = {
4073 0 ,
@@ -106,6 +139,11 @@ appling_resolve__on_read(fs_read_t *fs_req, int status, size_t read) {
106139
107140 req -> status = 0 ; // Reset
108141 } else {
142+ {
143+ char buf [128 ];
144+ snprintf (buf , sizeof (buf ), "status=%d" , status );
145+ appling__bootstrap_log ("resolve-read" , buf );
146+ }
109147 req -> status = status ; // Propagate
110148 }
111149
@@ -119,13 +157,23 @@ static void
119157appling_resolve__on_stat (fs_stat_t * fs_req , int status , const uv_stat_t * stat ) {
120158 appling_resolve_t * req = (appling_resolve_t * ) fs_req -> data ;
121159
160+ if (!req ) {
161+ appling__bootstrap_log ("resolve-stat" , "req-null" );
162+ return ;
163+ }
164+
122165 if (status >= 0 ) {
123166 size_t len = stat -> st_size ;
124167
125168 req -> buf = uv_buf_init (malloc (len ), len );
126169
127170 fs_read (req -> loop , & req -> read , req -> file , & req -> buf , 1 , 0 , appling_resolve__on_read );
128171 } else {
172+ {
173+ char buf [128 ];
174+ snprintf (buf , sizeof (buf ), "status=%d" , status );
175+ appling__bootstrap_log ("resolve-stat" , buf );
176+ }
129177 req -> status = status ; // Propagate
130178
131179 fs_close (req -> loop , & req -> close , req -> file , appling_resolve__on_close );
@@ -136,11 +184,29 @@ static void
136184appling_resolve__on_open (fs_open_t * fs_req , int status , uv_file file ) {
137185 appling_resolve_t * req = (appling_resolve_t * ) fs_req -> data ;
138186
187+ if (!req ) {
188+ appling__bootstrap_log ("resolve-open" , "req-null" );
189+ return ;
190+ }
191+
139192 if (status >= 0 ) {
140193 req -> file = file ;
141194
142195 fs_stat (req -> loop , & req -> stat , req -> file , appling_resolve__on_stat );
143196 } else {
197+ appling_path_t path ;
198+ size_t path_len = sizeof (appling_path_t );
199+ path_join (
200+ (const char * []) {req -> platform -> path , ".." , ".." , "checkout" , NULL },
201+ path ,
202+ & path_len ,
203+ path_behavior_system
204+ );
205+ {
206+ char buf [256 ];
207+ snprintf (buf , sizeof (buf ), "status=%d path=%s" , status , path );
208+ appling__bootstrap_log ("resolve-open" , buf );
209+ }
144210 if (req -> cb ) req -> cb (req , status );
145211 }
146212}
@@ -166,11 +232,32 @@ static void
166232appling_resolve__on_realpath (fs_realpath_t * fs_req , int status , const char * path ) {
167233 appling_resolve_t * req = (appling_resolve_t * ) fs_req -> data ;
168234
235+ if (!req ) {
236+ appling__bootstrap_log ("resolve-realpath" , "req-null" );
237+ return ;
238+ }
239+
169240 if (status >= 0 ) {
170241 strcpy (req -> platform -> path , path );
171242
172243 appling_resolve__open (req );
173244 } else {
245+ {
246+ appling_path_t candidate_path ;
247+ size_t candidate_len = sizeof (appling_path_t );
248+ size_t i = req -> candidate ;
249+ if (appling_platform_candidates [i ]) {
250+ path_join (
251+ (const char * []) {req -> path , appling_platform_candidates [i ], NULL },
252+ candidate_path ,
253+ & candidate_len ,
254+ path_behavior_system
255+ );
256+ char buf [256 ];
257+ snprintf (buf , sizeof (buf ), "status=%d path=%s" , status , candidate_path );
258+ appling__bootstrap_log ("resolve-realpath" , buf );
259+ }
260+ }
174261 size_t i = ++ req -> candidate ;
175262
176263 if (appling_platform_candidates [i ]) appling_resolve__realpath (req );
@@ -192,6 +279,12 @@ appling_resolve__realpath(appling_resolve_t *req) {
192279 path_behavior_system
193280 );
194281
282+ {
283+ char buf [256 ];
284+ snprintf (buf , sizeof (buf ), "candidate=%zu path=%s" , i , path );
285+ appling__bootstrap_log ("resolve-candidate" , buf );
286+ }
287+
195288 log_debug ("appling_resolve() accessing platform at %s" , path );
196289
197290 fs_realpath (req -> loop , & req -> realpath , path , appling_resolve__on_realpath );
@@ -245,6 +338,8 @@ appling_resolve(uv_loop_t *loop, appling_resolve_t *req, const char *dir, applin
245338 );
246339 }
247340
341+ appling__bootstrap_log ("resolve-root" , req -> path );
342+
248343 appling_resolve__realpath (req );
249344
250345 return 0 ;
0 commit comments