Skip to content

Commit ee15bc4

Browse files
obbardcsjoerdsimons
authored andcommitted
actions/image_partition: do not allow duplicate partitions or mountpoints
A common user complaint is the result of mounting a filesystem on top of another can be confusing. So do not allow duplicate mountpoints. Also better not allow multiple partitions with the same name. Resolves: #176 Resolves: #178 Signed-off-by: Christopher Obbard <[email protected]>
1 parent 77fd246 commit ee15bc4

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

actions/image_partition_action.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Yaml syntax for partitions:
5252
Mandatory properties:
5353
5454
- name -- is used for referencing named partition for mount points
55-
configuration (below) and label the filesystem located on this partition.
55+
configuration (below) and label the filesystem located on this partition. Must be
56+
unique.
5657
5758
- fs -- filesystem type used for formatting.
5859
@@ -86,17 +87,18 @@ Yaml syntax for mount points:
8687
8788
Mandatory properties:
8889
89-
- partition -- partition name for mounting.
90+
- partition -- partition name for mounting. The partion must exist under `partitions`.
9091
9192
- mountpoint -- path in the target root filesystem where the named partition
92-
should be mounted.
93+
should be mounted. Must be unique, only one partition can be mounted per
94+
mountpoint.
9395
9496
Optional properties:
9597
9698
- options -- list of options to be added to appropriate entry in fstab file.
9799
98100
- buildtime -- if set to true then the mountpoint only used during the debos run.
99-
No entry in `/etc/fstab' will be created.
101+
No entry in `/etc/fstab` will be created.
100102
The mountpoints directory will be removed from the image, so it is recommended
101103
to define a `mountpoint` path which is temporary and unique for the image,
102104
for example: `/mnt/temporary_mount`.
@@ -552,6 +554,14 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
552554
if p.Name == "" {
553555
return fmt.Errorf("Partition without a name")
554556
}
557+
558+
// check for duplicate partition names
559+
for j := idx + 1; j < len(i.Partitions); j++ {
560+
if i.Partitions[j].Name == p.Name {
561+
return fmt.Errorf("Partition %s already exists", p.Name)
562+
}
563+
}
564+
555565
if p.Start == "" {
556566
return fmt.Errorf("Partition %s missing start", p.Name)
557567
}
@@ -569,6 +579,14 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
569579

570580
for idx, _ := range i.Mountpoints {
571581
m := &i.Mountpoints[idx]
582+
583+
// check for duplicate mountpoints
584+
for j := idx + 1; j < len(i.Mountpoints); j++ {
585+
if i.Mountpoints[j].Mountpoint == m.Mountpoint {
586+
return fmt.Errorf("Mountpoint %s already exists", m.Mountpoint)
587+
}
588+
}
589+
572590
for pidx, _ := range i.Partitions {
573591
p := &i.Partitions[pidx]
574592
if m.Partition == p.Name {
@@ -577,7 +595,7 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
577595
}
578596
}
579597
if m.part == nil {
580-
return fmt.Errorf("Couldn't fount partition for %s", m.Mountpoint)
598+
return fmt.Errorf("Couldn't find partition for %s", m.Mountpoint)
581599
}
582600
}
583601

0 commit comments

Comments
 (0)