@@ -26,10 +26,17 @@ const (
2626 sessionDirPrefix = "Session"
2727)
2828
29- func Session (parent , sessionID string ) Layout {
30- return Layout (filepath .Join (parent , sessionDirPrefix + sessionID ))
29+ // Session creates a directory structure layout for terraform execution. The
30+ // SessionID is a unique value for creating an ephemeral working directory inside
31+ // the parentDirPath. All helper functions will return paths for various
32+ // terraform asserts inside this working directory.
33+ func Session (parentDirPath , sessionID string ) Layout {
34+ return Layout (filepath .Join (parentDirPath , sessionDirPrefix + sessionID ))
3135}
3236
37+ // Layout is the terraform execution working directory structure.
38+ // It also contains some methods for common file operations within that layout.
39+ // Such as "Cleanup" and "ExtractArchive".
3340// TODO: Maybe we should include the afero.FS here as well, then all operations
3441// would be on the same FS?
3542type Layout string
@@ -96,7 +103,7 @@ func (l Layout) ExtractArchive(ctx context.Context, logger slog.Logger, fs afero
96103 if ! filepath .IsLocal (header .Name ) {
97104 return xerrors .Errorf ("refusing to extract to non-local path" )
98105 }
99- // nolint: gosec
106+
100107 headerPath := filepath .Join (l .WorkDirectory (), header .Name )
101108 if ! strings .HasPrefix (headerPath , filepath .Clean (l .WorkDirectory ())) {
102109 return xerrors .New ("tar attempts to target relative upper directory" )
0 commit comments