@@ -189,11 +189,11 @@ type SBOMScanOptions struct {
189189// TempDirForURL checks if the passed-in string looks like a URL or "-". If it
190190// is, TempDirForURL creates a temporary directory, arranges for its contents
191191// to be the contents of that URL, and returns the temporary directory's path
192- // (for cleanup) and the absolute path to the build context within it.
192+ // (for cleanup) and a relative subdirectory to the build context within it.
193193// Removal of the temporary directory is the responsibility of the caller.
194194// If the string doesn't look like a URL or "-", TempDirForURL returns empty
195195// strings and a nil error code.
196- func TempDirForURL (dir , prefix , url string ) (tempDir string , contextDir string , err error ) {
196+ func TempDirForURL (dir , prefix , url string ) (tempDir string , relativeContextDir string , err error ) {
197197 if ! urlsource .IsHTTPOrHTTPS (url ) &&
198198 ! strings .HasPrefix (url , "git://" ) &&
199199 ! strings .HasPrefix (url , "github.com/" ) &&
@@ -250,13 +250,17 @@ func TempDirForURL(dir, prefix, url string) (tempDir string, contextDir string,
250250 }
251251 }
252252
253- contextDir , err = securejoin .SecureJoin (downloadDir , contentSubdir )
253+ contextDir , err : = securejoin .SecureJoin (downloadDir , contentSubdir )
254254 if err != nil {
255255 return "" , "" , fmt .Errorf ("resolving subdirectory %q in %q: %w" , contentSubdir , downloadDir , err )
256256 }
257+ relativeContextDir , err = filepath .Rel (tempDir , contextDir )
258+ if err != nil {
259+ return "" , "" , err
260+ }
257261 logrus .Debugf ("Build context is at %q" , contextDir )
258262 succeeded = true
259- return tempDir , contextDir , nil
263+ return tempDir , relativeContextDir , nil
260264}
261265
262266// parseGitBuildContext parses git build context to `repo`, `sub-dir`
@@ -372,7 +376,12 @@ func stdinToDirectory(dir string) error {
372376
373377// writeFileInRoot safely writes data to a file inside root, without following
374378// symlinks that escape the root directory.
375- func writeFileInRoot (root , name string , data []byte , perm os.FileMode ) error {
379+ func writeFileInRoot (root , name string , data []byte , perm os.FileMode ) error { //nolint:unparam,nolintlint
380+ // Above:
381+ // unparam: 'name' currently only receives "Dockerfile" but will potentially support other files later
382+ // nolintlint: the unparam linter only triggers if there are ≥ 4 instances; we do have that
383+ // with --tests defaulting to true, but not with --tests=false.
384+
376385 rootHandle , err := os .OpenRoot (root )
377386 if err != nil {
378387 return err
0 commit comments