@@ -161,7 +161,10 @@ func (w *walker) copyDir(cfg *config, srcPaths pathSet, file fileInfo) error {
161
161
// symlink to directories are intentionally never followed by filepath.Walk to avoid infinite recursion
162
162
linkPath , err := common .Realpath (p )
163
163
if err != nil {
164
- return err
164
+ if os .IsNotExist (err ) {
165
+ return fmt .Errorf ("failed to get realpath of dangling symlink %s: %w" , p , err )
166
+ }
167
+ return fmt .Errorf ("failed to get realpath of %s: %w" , p , err )
165
168
}
166
169
if srcPaths [linkPath ] {
167
170
// recursive symlink; silently ignore
@@ -177,9 +180,9 @@ func (w *walker) copyDir(cfg *config, srcPaths pathSet, file fileInfo) error {
177
180
Package : file .Package ,
178
181
Path : linkPath ,
179
182
RootPath : file .RootPath ,
180
- ShortPath : path . Join ( file .ShortPath ) ,
183
+ ShortPath : file .ShortPath ,
181
184
Workspace : file .Workspace ,
182
- WorkspacePath : path . Join ( file .WorkspacePath ) ,
185
+ WorkspacePath : file .WorkspacePath ,
183
186
Hardlink : file .Hardlink ,
184
187
FileInfo : stat ,
185
188
}
@@ -215,7 +218,7 @@ func (w *walker) copyDir(cfg *config, srcPaths pathSet, file fileInfo) error {
215
218
})
216
219
}
217
220
218
- func (w * walker ) copyPath (cfg * config , file fileInfo ) error {
221
+ func (w * walker ) calculateOutputPath (cfg * config , file fileInfo ) ( string , error ) {
219
222
// Apply filters and transformations in the following order:
220
223
//
221
224
// - `include_external_repositories`
@@ -237,35 +240,35 @@ func (w *walker) copyPath(cfg *config, file fileInfo) error {
237
240
if file .Workspace != "" && (cfg .TargetWorkspace == nil || file .Workspace != * cfg .TargetWorkspace ) {
238
241
match , err := anyGlobsMatch (cfg .IncludeExternalRepositories , file .Workspace )
239
242
if err != nil {
240
- return err
243
+ return "" , err
241
244
}
242
245
if ! match {
243
- return nil // external workspace is not included
246
+ return "" , nil // external workspace is not included
244
247
}
245
248
}
246
249
247
250
// apply include_srcs_packages
248
251
match , err := anyGlobsMatch (cfg .IncludeSrcsPackages , file .Package )
249
252
if err != nil {
250
- return err
253
+ return "" , err
251
254
}
252
255
if ! match {
253
- return nil // package is not included
256
+ return "" , nil // package is not included
254
257
}
255
258
256
259
// apply exclude_srcs_packages
257
260
match , err = anyGlobsMatch (cfg .ExcludeSrcsPackages , file .Package )
258
261
if err != nil {
259
- return err
262
+ return "" , err
260
263
}
261
264
if match {
262
- return nil // package is excluded
265
+ return "" , nil // package is excluded
263
266
}
264
267
265
268
// apply root_paths
266
269
rootPathMatch , _ , err := longestGlobsMatch (cfg .RootPaths , outputRoot )
267
270
if err != nil {
268
- return err
271
+ return "" , err
269
272
}
270
273
if rootPathMatch != "" {
271
274
outputPath = strings .TrimPrefix (outputPath [len (rootPathMatch ):], "/" )
@@ -274,32 +277,43 @@ func (w *walker) copyPath(cfg *config, file fileInfo) error {
274
277
// apply include_srcs_patterns
275
278
match , err = anyGlobsMatch (cfg .IncludeSrcsPatterns , outputPath )
276
279
if err != nil {
277
- return err
280
+ return "" , err
278
281
}
279
282
if ! match {
280
- return nil // outputPath is not included
283
+ return "" , nil // outputPath is not included
281
284
}
282
285
283
286
// apply exclude_srcs_patterns
284
287
match , err = anyGlobsMatch (cfg .ExcludeSrcsPatterns , outputPath )
285
288
if err != nil {
286
- return err
289
+ return "" , err
287
290
}
288
291
if match {
289
- return nil // outputPath is excluded
292
+ return "" , nil // outputPath is excluded
290
293
}
291
294
292
295
// apply replace_prefixes
293
296
replacePrefixMatch , replacePrefixIndex , err := longestGlobsMatch (cfg .ReplacePrefixesKeys , outputPath )
294
297
if err != nil {
295
- return err
298
+ return "" , err
296
299
}
297
300
if replacePrefixMatch != "" {
298
301
replaceWith := cfg.ReplacePrefixes [cfg.ReplacePrefixesKeys [replacePrefixIndex ]]
299
302
outputPath = replaceWith + outputPath [len (replacePrefixMatch ):]
300
303
}
301
304
302
- outputPath = path .Join (cfg .Dst , outputPath )
305
+ return path .Join (cfg .Dst , outputPath ), nil
306
+ }
307
+
308
+ func (w * walker ) copyPath (cfg * config , file fileInfo ) error {
309
+ outputPath , err := w .calculateOutputPath (cfg , file )
310
+ if err != nil {
311
+ return fmt .Errorf ("failed to calculate output path %s: %w" , file .WorkspacePath , err )
312
+ }
313
+ if outputPath == "" {
314
+ // this path is excluded
315
+ return nil
316
+ }
303
317
304
318
// add this file to the copy Paths
305
319
dup , exists := copySet [outputPath ]
@@ -345,7 +359,10 @@ func (w *walker) copyPaths(cfg *config) error {
345
359
// call filepath.WalkDir on the realpath
346
360
realpath , err := common .Realpath (file .Path )
347
361
if err != nil {
348
- return err
362
+ if os .IsNotExist (err ) {
363
+ return fmt .Errorf ("failed to get realpath of dangling symlink %s: %w" , file .Path , err )
364
+ }
365
+ return fmt .Errorf ("failed to get realpath of %s: %w" , file .Path , err )
349
366
}
350
367
stat , err := os .Stat (realpath )
351
368
if err != nil {
0 commit comments