Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Dinov <[email protected]>
  • Loading branch information
atanasdinov committed Nov 17, 2023
1 parent 9c9c26c commit 7a13368
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
14 changes: 8 additions & 6 deletions pkg/build/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/rpm_test.go
Original file line number Diff line number Diff line change
@@ -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()) {
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 9 additions & 5 deletions pkg/build/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/users_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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/config"
"github.com/suse-edge/edge-image-builder/pkg/fileio"
)

func TestConfigureUsers(t *testing.T) {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7a13368

Please sign in to comment.