mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
util: add MountOptionsAdd() to add mount options
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
75088aa36d
commit
887aab1d72
@ -205,3 +205,35 @@ func Mount(source, target, fstype string, options []string) error {
|
|||||||
dummyMount := mount.New("")
|
dummyMount := mount.New("")
|
||||||
return dummyMount.Mount(source, target, fstype, options)
|
return dummyMount.Mount(source, target, fstype, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MountOptionsAdd adds the `add` mount options to the `options` and returns a
|
||||||
|
// new string. In case `add` is already present in the `options`, `add` is not
|
||||||
|
// added again.
|
||||||
|
func MountOptionsAdd(options string, add ...string) string {
|
||||||
|
opts := strings.Split(options, ",")
|
||||||
|
newOpts := []string{}
|
||||||
|
// clean original options from empty strings
|
||||||
|
for _, opt := range opts {
|
||||||
|
if opt != "" {
|
||||||
|
newOpts = append(newOpts, opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range add {
|
||||||
|
if opt != "" && !contains(newOpts, opt) {
|
||||||
|
newOpts = append(newOpts, opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(newOpts, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
func contains(s []string, key string) bool {
|
||||||
|
for _, v := range s {
|
||||||
|
if v == key {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user