From c8f44c5e17c82cf141cb1320f31224b2186859d2 Mon Sep 17 00:00:00 2001 From: Ridai Govinda Pombo Date: Mon, 6 Jul 2020 14:02:01 -0300 Subject: [PATCH] Use WriteFileContents to write license agreements So it works in a container or in Metal --- buildpacks/android_sdk.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/buildpacks/android_sdk.go b/buildpacks/android_sdk.go index b6a5c485..220b6f05 100644 --- a/buildpacks/android_sdk.go +++ b/buildpacks/android_sdk.go @@ -3,7 +3,6 @@ package buildpacks import ( "context" "fmt" - "os" "path/filepath" "strings" @@ -71,7 +70,7 @@ func (bt AndroidBuildTool) Version() string { return bt.version } -func (bt AndroidBuildTool) WriteAgreements(ctx context.Context, androidDir string) bool { +func (bt AndroidBuildTool) writeAgreements(ctx context.Context, androidDir string) bool { agreements := map[string]string{ "android-googletv-license": "601085b94cd77f0b54ff86406957099ebe79c4d6", "android-sdk-license": "24333f8a63b6825ea9c5514f83c2829b004d1fee", @@ -87,23 +86,11 @@ func (bt AndroidBuildTool) WriteAgreements(ctx context.Context, androidDir strin for filename, hash := range agreements { agreementFile := filepath.Join(licensesDir, filename) - // TODO add as a Runtime/Target method: CreateFile - f, err := os.Create(agreementFile) + err := t.WriteFileContents(ctx, hash, agreementFile) if err != nil { log.Errorf("Can't create agreement file %s: %v", agreementFile, err) return false } - - defer f.Close() - _, err = f.WriteString(hash) - - if err != nil { - log.Errorf("Can't write agreement file %s: %v", agreementFile, err) - return false - } - - f.Sync() - log.Infof("Wrote hash for agreement: %s", agreementFile) } @@ -119,8 +106,8 @@ func (bt AndroidBuildTool) Setup(ctx context.Context, androidDir string) error { t.SetEnv("ANDROID_HOME", androidDir) log.Infof("Writing agreement hashes...") - if !bt.WriteAgreements(ctx, androidDir) { - return fmt.Errorf("Unable to auto write the agreements") + if !bt.writeAgreements(ctx, androidDir) { + return fmt.Errorf("auto write the agreements") } t.PrependToPath(ctx, filepath.Join(androidDir, "tools"))