Skip to content

Commit

Permalink
(feat): Add whitespace for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed Jan 3, 2024
1 parent 1a1dd52 commit 39adc79
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
2 changes: 2 additions & 0 deletions internal/layer/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions internal/layer/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,27 @@ 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
}
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
}
Expand Down
8 changes: 5 additions & 3 deletions internal/layer/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions internal/layer/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/layer/mount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package layer

// TODO
3 changes: 1 addition & 2 deletions internal/layer/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/layer/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/layer/resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 39adc79

Please sign in to comment.