From 39adc79e6ffa8c6d13d209bfa76698b315e4592a Mon Sep 17 00:00:00 2001 From: lasith-kg Date: Wed, 3 Jan 2024 10:44:04 +0000 Subject: [PATCH] (feat): Add whitespace for clarity --- internal/layer/directory.go | 2 ++ internal/layer/format.go | 13 +++++++------ internal/layer/label.go | 8 +++++--- internal/layer/mount.go | 13 +++++++------ internal/layer/mount_test.go | 3 +++ internal/layer/owner.go | 3 +-- internal/layer/permissions.go | 1 + internal/layer/resize.go | 2 ++ 8 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 internal/layer/mount_test.go diff --git a/internal/layer/directory.go b/internal/layer/directory.go index 7ad4fd2..18c9fa2 100644 --- a/internal/layer/directory.go +++ b/internal/layer/directory.go @@ -29,6 +29,7 @@ func (fdl *CreateDirectoryLayer) Modify(c *config.Config) ([]action.Action, erro if len(cd.MountPoint) == 0 { continue } + d, err := fdl.fileBackend.GetDirectory(cd.MountPoint) if err != nil && !os.IsNotExist(err) { // This layer's responsibility is to create a directory if it doesn't exist. @@ -38,6 +39,7 @@ func (fdl *CreateDirectoryLayer) Modify(c *config.Config) ([]action.Action, erro if d != nil { continue } + mode := c.GetMode(name) a := fdl.fileBackend.CreateDirectory(cd.MountPoint).SetMode(mode) actions = append(actions, a) diff --git a/internal/layer/format.go b/internal/layer/format.go index 687eedf..f5f5d1c 100644 --- a/internal/layer/format.go +++ b/internal/layer/format.go @@ -26,6 +26,10 @@ func (fdl *FormatDeviceLayer) From(c *config.Config) error { func (fdl *FormatDeviceLayer) Modify(c *config.Config) ([]action.Action, error) { actions := make([]action.Action, 0) for name, cd := range c.Devices { + if cd.Fs == model.Unformatted { + return nil, fmt.Errorf("🔴 %s: Can not erase the file system of a device", name) + } + bd, err := fdl.deviceBackend.GetBlockDevice(name) if err != nil { return nil, err @@ -33,19 +37,16 @@ func (fdl *FormatDeviceLayer) Modify(c *config.Config) ([]action.Action, error) if bd.FileSystem == cd.Fs { continue } - if cd.Fs == model.Unformatted { - return nil, fmt.Errorf("🔴 %s: Can not erase the file system of a device", bd.Name) - } if bd.FileSystem != model.Unformatted { return nil, fmt.Errorf("🔴 %s: Can not format a device with an existing %s file system", bd.Name, bd.FileSystem.String()) } + + mode := c.GetMode(name) a, err := fdl.deviceBackend.Format(bd, cd.Fs) if err != nil { return nil, err } - mode := c.GetMode(name) - a = a.SetMode(mode) - actions = append(actions, a) + actions = append(actions, a.SetMode(mode)) } return actions, nil } diff --git a/internal/layer/label.go b/internal/layer/label.go index 44e2401..0c32fd8 100644 --- a/internal/layer/label.go +++ b/internal/layer/label.go @@ -25,16 +25,18 @@ func (fdl *LabelDeviceLayer) From(c *config.Config) error { func (fdl *LabelDeviceLayer) Modify(c *config.Config) ([]action.Action, error) { actions := make([]action.Action, 0) for name, cd := range c.Devices { + if len(cd.Label) == 0 { + continue + } + bd, err := fdl.deviceBackend.GetBlockDevice(name) if err != nil { return nil, err } - if len(cd.Label) == 0 { - continue - } if bd.Label == cd.Label { continue } + mode := c.GetMode(name) las, err := fdl.deviceBackend.Label(bd, cd.Label) if err != nil { diff --git a/internal/layer/mount.go b/internal/layer/mount.go index a4755e8..4431385 100644 --- a/internal/layer/mount.go +++ b/internal/layer/mount.go @@ -32,24 +32,25 @@ func (fdl *MountDeviceLayer) From(c *config.Config) error { func (fdl *MountDeviceLayer) Modify(c *config.Config) ([]action.Action, error) { actions := make([]action.Action, 0) for name, cd := range c.Devices { + if len(cd.MountPoint) == 0 { + continue + } + bd, err := fdl.deviceBackend.GetBlockDevice(name) if err != nil { return nil, err } - if len(cd.MountPoint) == 0 { - continue - } if bd.FileSystem == model.Unformatted { return nil, fmt.Errorf("🔴 %s: Can not mount a device with no file system", bd.Name) } - mode := c.GetMode(name) - mo := c.GetMountOptions(name) - d, err := fdl.fileBackend.GetDirectory(cd.MountPoint) if err != nil { return nil, fmt.Errorf("🔴 %s: %s must exist as a directory before it can be mounted", name, cd.MountPoint) } + + mode := c.GetMode(name) + mo := c.GetMountOptions(name) if bd.MountPoint == d.Path { if c.GetRemount(name) { a := fdl.deviceBackend.Remount(bd, cd.MountPoint, mo).SetMode(mode) diff --git a/internal/layer/mount_test.go b/internal/layer/mount_test.go new file mode 100644 index 0000000..6d1b20c --- /dev/null +++ b/internal/layer/mount_test.go @@ -0,0 +1,3 @@ +package layer + +// TODO diff --git a/internal/layer/owner.go b/internal/layer/owner.go index 9a19c25..43087a7 100644 --- a/internal/layer/owner.go +++ b/internal/layer/owner.go @@ -42,7 +42,6 @@ func (fdl *ChangeOwnerLayer) Modify(c *config.Config) ([]action.Action, error) { if err != nil { return nil, fmt.Errorf("🔴 %s is either not a directory or does not exist", cd.MountPoint) } - uid := d.UserId gid := d.GroupId if len(cd.User) > 0 { @@ -60,10 +59,10 @@ func (fdl *ChangeOwnerLayer) Modify(c *config.Config) ([]action.Action, error) { } gid = g.Id } - if d.UserId == uid && d.GroupId == gid { continue } + mode := c.GetMode(name) a := fdl.fileBackend.ChangeOwner(cd.MountPoint, uid, gid).SetMode(mode) actions = append(actions, a) diff --git a/internal/layer/permissions.go b/internal/layer/permissions.go index 48124a2..89b76f5 100644 --- a/internal/layer/permissions.go +++ b/internal/layer/permissions.go @@ -40,6 +40,7 @@ func (fdl *ChangePermissionsLayer) Modify(c *config.Config) ([]action.Action, er if d.Permissions == cd.Permissions { continue } + mode := c.GetMode(name) a := fdl.fileBackend.ChangePermissions(cd.MountPoint, cd.Permissions).SetMode(mode) actions = append(actions, a) diff --git a/internal/layer/resize.go b/internal/layer/resize.go index 34a947c..8da913d 100644 --- a/internal/layer/resize.go +++ b/internal/layer/resize.go @@ -34,6 +34,7 @@ func (fdl *ResizeDeviceLayer) Modify(c *config.Config) ([]action.Action, error) if !c.GetResizeFs(name) { continue } + bd, err := fdl.deviceBackend.GetBlockDevice(name) if err != nil { return nil, err @@ -42,6 +43,7 @@ func (fdl *ResizeDeviceLayer) Modify(c *config.Config) ([]action.Action, error) if err != nil { return nil, err } + mode := c.GetMode(name) rt := c.GetResizeThreshold(name) // If the resize threshold is set to 0, always attempt to resize the block device.