@@ -237,8 +237,11 @@ func (vm *VM) evaluateSnippet(diagnosticFileName ast.DiagnosticFileName, filenam
237
237
return output , nil
238
238
}
239
239
240
- func getAbsPath (path string ) (string , error ) {
240
+ func getAbsPath (path string , followSymlinks bool ) (string , error ) {
241
241
var absPath string
242
+
243
+ var err error
244
+
242
245
if filepath .IsAbs (path ) {
243
246
absPath = path
244
247
} else {
@@ -248,14 +251,18 @@ func getAbsPath(path string) (string, error) {
248
251
}
249
252
absPath = strings .Join ([]string {wd , path }, string (filepath .Separator ))
250
253
}
251
- cleanedAbsPath , err := filepath .EvalSymlinks (absPath )
252
- if err != nil {
253
- return "" , err
254
+
255
+ if followSymlinks {
256
+ absPath , err = filepath .EvalSymlinks (absPath )
257
+ if err != nil {
258
+ return "" , err
259
+ }
254
260
}
255
- return cleanedAbsPath , nil
261
+
262
+ return absPath , nil
256
263
}
257
264
258
- func (vm * VM ) findDependencies (filePath string , node * ast.Node , dependencies map [string ]struct {}, stackTrace * []TraceFrame ) (err error ) {
265
+ func (vm * VM ) findDependencies (filePath string , node * ast.Node , dependencies map [string ]struct {}, stackTrace * []TraceFrame , followSymlinks bool ) (err error ) {
259
266
var cleanedAbsPath string
260
267
switch i := (* node ).(type ) {
261
268
case * ast.Import :
@@ -266,7 +273,7 @@ func (vm *VM) findDependencies(filePath string, node *ast.Node, dependencies map
266
273
}
267
274
cleanedAbsPath = foundAt
268
275
if _ , isFileImporter := vm .importer .(* FileImporter ); isFileImporter {
269
- cleanedAbsPath , err = getAbsPath (foundAt )
276
+ cleanedAbsPath , err = getAbsPath (foundAt , followSymlinks )
270
277
if err != nil {
271
278
* stackTrace = append ([]TraceFrame {{Loc : * i .Loc ()}}, * stackTrace ... )
272
279
return err
@@ -277,7 +284,7 @@ func (vm *VM) findDependencies(filePath string, node *ast.Node, dependencies map
277
284
return nil
278
285
}
279
286
dependencies [cleanedAbsPath ] = struct {}{}
280
- err = vm .findDependencies (foundAt , & node , dependencies , stackTrace )
287
+ err = vm .findDependencies (foundAt , & node , dependencies , stackTrace , followSymlinks )
281
288
if err != nil {
282
289
* stackTrace = append ([]TraceFrame {{Loc : * i .Loc ()}}, * stackTrace ... )
283
290
return err
@@ -290,7 +297,7 @@ func (vm *VM) findDependencies(filePath string, node *ast.Node, dependencies map
290
297
}
291
298
cleanedAbsPath = foundAt
292
299
if _ , isFileImporter := vm .importer .(* FileImporter ); isFileImporter {
293
- cleanedAbsPath , err = getAbsPath (foundAt )
300
+ cleanedAbsPath , err = getAbsPath (foundAt , followSymlinks )
294
301
if err != nil {
295
302
* stackTrace = append ([]TraceFrame {{Loc : * i .Loc ()}}, * stackTrace ... )
296
303
return err
@@ -305,7 +312,7 @@ func (vm *VM) findDependencies(filePath string, node *ast.Node, dependencies map
305
312
}
306
313
cleanedAbsPath = foundAt
307
314
if _ , isFileImporter := vm .importer .(* FileImporter ); isFileImporter {
308
- cleanedAbsPath , err = getAbsPath (foundAt )
315
+ cleanedAbsPath , err = getAbsPath (foundAt , followSymlinks )
309
316
if err != nil {
310
317
* stackTrace = append ([]TraceFrame {{Loc : * i .Loc ()}}, * stackTrace ... )
311
318
return err
@@ -314,7 +321,7 @@ func (vm *VM) findDependencies(filePath string, node *ast.Node, dependencies map
314
321
dependencies [cleanedAbsPath ] = struct {}{}
315
322
default :
316
323
for _ , node := range parser .Children (i ) {
317
- err = vm .findDependencies (filePath , & node , dependencies , stackTrace )
324
+ err = vm .findDependencies (filePath , & node , dependencies , stackTrace , followSymlinks )
318
325
if err != nil {
319
326
return err
320
327
}
@@ -458,7 +465,7 @@ func (vm *VM) EvaluateFileMulti(filename string) (files map[string]string, forma
458
465
// FindDependencies returns a sorted array of unique transitive dependencies (via import/importstr/importbin)
459
466
// from all the given `importedPaths` which are themselves excluded from the returned array.
460
467
// The `importedPaths` are parsed as if they were imported from a Jsonnet file located at `importedFrom`.
461
- func (vm * VM ) FindDependencies (importedFrom string , importedPaths []string ) ([]string , error ) {
468
+ func (vm * VM ) FindDependencies (importedFrom string , importedPaths []string , followSymlinks bool ) ([]string , error ) {
462
469
var nodes []* ast.Node
463
470
var stackTrace []TraceFrame
464
471
filePaths := make ([]string , len (importedPaths ))
@@ -472,7 +479,7 @@ func (vm *VM) FindDependencies(importedFrom string, importedPaths []string) ([]s
472
479
}
473
480
cleanedAbsPath := foundAt
474
481
if _ , isFileImporter := vm .importer .(* FileImporter ); isFileImporter {
475
- cleanedAbsPath , err = getAbsPath (foundAt )
482
+ cleanedAbsPath , err = getAbsPath (foundAt , followSymlinks )
476
483
if err != nil {
477
484
return nil , err
478
485
}
@@ -487,7 +494,7 @@ func (vm *VM) FindDependencies(importedFrom string, importedPaths []string) ([]s
487
494
}
488
495
489
496
for i , filePath := range filePaths {
490
- err := vm .findDependencies (filePath , nodes [i ], deps , & stackTrace )
497
+ err := vm .findDependencies (filePath , nodes [i ], deps , & stackTrace , followSymlinks )
491
498
if err != nil {
492
499
err = makeRuntimeError (err .Error (), stackTrace )
493
500
return nil , errors .New (vm .ErrorFormatter .Format (err ))
0 commit comments