Skip to content

Commit

Permalink
(feat): Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed Dec 22, 2023
1 parent 9636f7e commit 2c000e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
4 changes: 0 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const (
Force Mode = "force"
)

func (m Mode) String() string {
return string(m)
}

func ParseMode(s string) (Mode, error) {
Modes := map[Mode]struct{}{
Empty: {},
Expand Down
4 changes: 0 additions & 4 deletions internal/model/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const (
Xfs FileSystem = "xfs"
)

func (c FileSystem) String() string {
return string(c)
}

func ParseFileSystem(s string) (FileSystem, error) {
FileSystems := map[FileSystem]struct{}{
Unformatted: {},
Expand Down
22 changes: 8 additions & 14 deletions internal/service/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,14 @@ func NewLinuxFileSystemServiceFactory(rc utils.RunnerFactory) *LinuxFileSystemSe
}

func (fsf *LinuxFileSystemServiceFactory) Select(fs model.FileSystem) (FileSystemService, error) {
// Check if the instance is already in the services cache
fss, exists := fsf.services[fs]
if !exists {
switch fs {
case model.Ext4:
fss = NewExt4Service(fsf.RunnerFactory)
case model.Xfs:
fss = NewXfsService(fsf.RunnerFactory)
case model.Unformatted:
return nil, fmt.Errorf("🔴 An unsupported filesystem was encountered")
}
fsf.services[fs] = fss
}
return fss, nil
switch fs {
case model.Ext4:
return NewExt4Service(fsf.RunnerFactory), nil
case model.Xfs:
return NewXfsService(fsf.RunnerFactory), nil
default:
return nil, fmt.Errorf("🔴 An unsupported filesystem was encountered")
}
}

type Ext4Service struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func NewExecRunnerFactory() *ExecRunnerFactory {
}
}

// Caching behaviour is implemented for ExecRunnerFactory as we
// do not need to validate an ExecRunner more than once
func (rc *ExecRunnerFactory) Select(binary Binary) Runner {
r, exists := rc.runners[binary]
if !exists {
Expand Down

0 comments on commit 2c000e3

Please sign in to comment.