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