From 7a13368dea5905bd0b5d9ab600f2bc221d89cf6b Mon Sep 17 00:00:00 2001 From: Atanas Dinov Date: Fri, 17 Nov 2023 17:50:47 +0200 Subject: [PATCH] Resolve conflicts Signed-off-by: Atanas Dinov --- pkg/build/rpm.go | 14 ++++++++------ pkg/build/rpm_test.go | 4 ++-- pkg/build/users.go | 14 +++++++++----- pkg/build/users_test.go | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pkg/build/rpm.go b/pkg/build/rpm.go index b30e02fe..d332fe95 100644 --- a/pkg/build/rpm.go +++ b/pkg/build/rpm.go @@ -5,10 +5,10 @@ import ( "fmt" "os" "path/filepath" - "strings" "github.com/suse-edge/edge-image-builder/pkg/fileio" + "github.com/suse-edge/edge-image-builder/pkg/template" ) const ( @@ -75,7 +75,7 @@ func copyRPMs(rpmSourceDir string, rpmDestDir string, rpmFileNames []string) err sourcePath := filepath.Join(rpmSourceDir, rpm) destPath := filepath.Join(rpmDestDir, rpm) - err := fileio.CopyFile(sourcePath, destPath, fileio.NonExecutablePerms)) + err := fileio.CopyFile(sourcePath, destPath, fileio.NonExecutablePerms) if err != nil { return fmt.Errorf("copying file %s: %w", sourcePath, err) } @@ -91,13 +91,15 @@ func (b *Builder) writeRPMScript(rpmFileNames []string) error { RPMs: strings.Join(rpmFileNames, " "), } - writtenFilename, err := b.writeCombustionFile(modifyRPMScriptName, modifyRPMScript, &values) + data, err := template.Parse(modifyRPMScriptName, modifyRPMScript, &values) if err != nil { - return fmt.Errorf("writing RPM script: %w", err) + return fmt.Errorf("parsing RPM script template: %w", err) } - err = os.Chmod(writtenFilename, modifyScriptMode) + + filename := b.generateCombustionDirFilename(modifyRPMScriptName) + err = os.WriteFile(filename, []byte(data), fileio.ExecutablePerms) if err != nil { - return fmt.Errorf("adjusting permissions: %w", err) + return fmt.Errorf("writing RPM script: %w", err) } b.registerCombustionScript(modifyRPMScriptName) diff --git a/pkg/build/rpm_test.go b/pkg/build/rpm_test.go index 9c1f860a..38cfe1c4 100644 --- a/pkg/build/rpm_test.go +++ b/pkg/build/rpm_test.go @@ -1,13 +1,13 @@ package build import ( - "io/fs" "os" "path/filepath" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/suse-edge/edge-image-builder/pkg/fileio" ) func setupRPMSourceDir(t *testing.T, addFiles bool) (tmpDir string, rpmSourceDir string, teardown func()) { @@ -136,7 +136,7 @@ func TestWriteRPMScript(t *testing.T) { stats, err := os.Stat(expectedFilename) require.NoError(t, err) - assert.Equal(t, fs.FileMode(modifyScriptMode), stats.Mode()) + assert.Equal(t, fileio.ExecutablePerms, stats.Mode()) foundContents := string(foundBytes) assert.Contains(t, foundContents, "rpm1.rpm") diff --git a/pkg/build/users.go b/pkg/build/users.go index 7294c5b0..0d71f4e9 100644 --- a/pkg/build/users.go +++ b/pkg/build/users.go @@ -4,11 +4,13 @@ import ( _ "embed" "fmt" "os" + + "github.com/suse-edge/edge-image-builder/pkg/fileio" + "github.com/suse-edge/edge-image-builder/pkg/template" ) const ( usersScriptName = "add-users.sh" - userScriptMode = 0o744 ) //go:embed scripts/users/add-users.sh.tpl @@ -20,13 +22,15 @@ func (b *Builder) configureUsers() error { return nil } - filename, err := b.writeCombustionFile(usersScriptName, usersScript, b.imageConfig.OperatingSystem.Users) + data, err := template.Parse(usersScriptName, usersScript, b.imageConfig.OperatingSystem.Users) if err != nil { - return fmt.Errorf("writing %s to the combustion directory: %w", usersScriptName, err) + return fmt.Errorf("parsing users script template: %w", err) } - err = os.Chmod(filename, userScriptMode) + + filename := b.generateCombustionDirFilename(usersScriptName) + err = os.WriteFile(filename, []byte(data), fileio.ExecutablePerms) if err != nil { - return fmt.Errorf("modifying permissions for script %s: %w", filename, err) + return fmt.Errorf("writing %s to the combustion directory: %w", usersScriptName, err) } b.registerCombustionScript(usersScriptName) diff --git a/pkg/build/users_test.go b/pkg/build/users_test.go index 0c4097eb..dfeb8297 100644 --- a/pkg/build/users_test.go +++ b/pkg/build/users_test.go @@ -1,7 +1,6 @@ package build import ( - "io/fs" "os" "path/filepath" "testing" @@ -9,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/suse-edge/edge-image-builder/pkg/config" + "github.com/suse-edge/edge-image-builder/pkg/fileio" ) func TestConfigureUsers(t *testing.T) { @@ -61,7 +61,7 @@ func TestConfigureUsers(t *testing.T) { stats, err := os.Stat(expectedFilename) require.NoError(t, err) - assert.Equal(t, fs.FileMode(userScriptMode), stats.Mode()) + assert.Equal(t, fileio.ExecutablePerms, stats.Mode()) foundContents := string(foundBytes)