mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.14k stars 338 forks source link

interp: use custom handler for os.stat/os.Lstat operations #848

Closed ihar-orca closed 2 years ago

ihar-orca commented 2 years ago

This feature allows intercepting the os.stat/os.Lstat operations in the interp to provide more flexible usage.

mvdan commented 2 years ago

FYI @alecthomas given https://github.com/mvdan/sh/pull/799.

mvdan commented 2 years ago

Out of curiosity, what are you using the interpreter for? I assume you want some form of sandboxing, given this PR? :)

ihar-orca commented 2 years ago

@mvdan in general, yes. I have a couple of shell scripts that run on a target Linux machine. this script checks some system integrity. the idea is to run these scripts on the target machine but on mounted volume without any chrooted environment. to achieve this I should mock some apps (I can do it using execHandler), mock dirs and files functions (stat, opendirhandler, substitute any paths in variables/arguments using the parser).

ihar-orca commented 2 years ago

Now the StatHandlerFunc contains a Context. cwd argument removed and replaced with the absPath constructor in the parent function.