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 2c000e3 commit 5cd57b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions internal/action/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func (a *ChangeOwnerAction) Success() string {

type ChangePermissionsAction struct {
path string
perms model.Permissions
perms model.FilePermissions
mode config.Mode
fileService service.FileService
}

func NewChangePermissions(p string, perms model.Permissions, fs service.FileService) *ChangePermissionsAction {
func NewChangePermissions(p string, perms model.FilePermissions, fs service.FileService) *ChangePermissionsAction {
return &ChangePermissionsAction{
path: p,
perms: perms,
Expand Down
4 changes: 2 additions & 2 deletions internal/backend/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type FileBackend interface {
CreateDirectory(p string) action.Action
ChangeOwner(p string, uid int, gid int) action.Action
ChangePermissions(p string, perms model.Permissions) action.Action
ChangePermissions(p string, perms model.FilePermissions) action.Action
GetDirectory(p string) (*model.File, error)
IsMount(p string) bool
From(config *config.Config) error
Expand All @@ -40,7 +40,7 @@ func (lfb *LinuxFileBackend) ChangeOwner(p string, uid int, gid int) action.Acti
return action.NewChangeOwnerAction(p, uid, gid, lfb.fileService)
}

func (lfb *LinuxFileBackend) ChangePermissions(p string, perms model.Permissions) action.Action {
func (lfb *LinuxFileBackend) ChangePermissions(p string, perms model.FilePermissions) action.Action {
return action.NewChangePermissions(p, perms, lfb.fileService)
}

Expand Down
22 changes: 11 additions & 11 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ type Flag struct {
}

type Device struct {
Fs model.FileSystem `yaml:"fs"`
MountPoint string `yaml:"mountPoint"`
MountOptions model.MountOptions `yaml:"mountOptions"`
User string `yaml:"user"`
Group string `yaml:"group"`
Label string `yaml:"label"`
Permissions model.Permissions `yaml:"permissions"`
Mode Mode `yaml:"mode"`
Remount bool `yaml:"remount"`
ResizeFs bool `yaml:"resizeFs"`
ResizeThreshold float64 `yaml:"resizeThreshold"`
Fs model.FileSystem `yaml:"fs"`
MountPoint string `yaml:"mountPoint"`
MountOptions model.MountOptions `yaml:"mountOptions"`
User string `yaml:"user"`
Group string `yaml:"group"`
Label string `yaml:"label"`
Permissions model.FilePermissions `yaml:"permissions"`
Mode Mode `yaml:"mode"`
Remount bool `yaml:"remount"`
ResizeFs bool `yaml:"resizeFs"`
ResizeThreshold float64 `yaml:"resizeThreshold"`
}

type Defaults struct {
Expand Down
16 changes: 8 additions & 8 deletions internal/model/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ type File struct {
InodeNo int
Uid int // User ID
Gid int // Group ID
Permissions Permissions
Permissions FilePermissions
}

type Permissions uint32
type FilePermissions uint32

func (p Permissions) Perm() fs.FileMode {
func (p FilePermissions) Perm() fs.FileMode {
return fs.FileMode(p)
}

func (p *Permissions) UnmarshalYAML(unmarshal func(interface{}) error) error {
var ps string;
func (p *FilePermissions) UnmarshalYAML(unmarshal func(interface{}) error) error {
var ps string
if err := unmarshal(&ps); err != nil {
return err
}
if ps == "" {
*p = Permissions(0)
*p = FilePermissions(0)
return nil
}
// Base: 8, Bit Length: 32
Expand All @@ -47,6 +47,6 @@ func (p *Permissions) UnmarshalYAML(unmarshal func(interface{}) error) error {
if mode > 0777 {
return fmt.Errorf("🔴 invalid permission value. '%#o' exceeds the maximum allowed value (0777)", mode)
}
*p = Permissions(mode)
*p = FilePermissions(mode)
return nil
}
}
6 changes: 3 additions & 3 deletions internal/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type FileService interface {
GetFile(file string) (*model.File, error)
CreateDirectory(path string) error
ChangeOwner(file string, uid int, gid int) error
ChangePermissions(file string, perms model.Permissions) error
ChangePermissions(file string, perms model.FilePermissions) error
}

// File Service Interface [END]
Expand Down Expand Up @@ -50,7 +50,7 @@ func (ufs *UnixFileService) GetFile(file string) (*model.File, error) {
InodeNo: int(stat.Ino),
Uid: int(stat.Uid),
Gid: int(stat.Gid),
Permissions: model.Permissions(info.Mode().Perm()),
Permissions: model.FilePermissions(info.Mode().Perm()),
Type: ft,
}, nil
}
Expand All @@ -65,6 +65,6 @@ func (ufs *UnixFileService) ChangeOwner(file string, uid int, gid int) error {
return os.Chown(file, uid, gid)
}

func (ufs *UnixFileService) ChangePermissions(file string, perms model.Permissions) error {
func (ufs *UnixFileService) ChangePermissions(file string, perms model.FilePermissions) error {
return os.Chmod(file, perms.Perm())
}

0 comments on commit 5cd57b2

Please sign in to comment.