From f7a1c8106dbc70020aa9e9df27efef81ed394139 Mon Sep 17 00:00:00 2001 From: Muhammad Salman <73386616+muhdsalm@users.noreply.github.com> Date: Sat, 10 Aug 2024 17:34:52 +0500 Subject: [PATCH] feat: Add setlabel to the recipe * Add setlabel to the recipe * Fix typo + update recipe doc --------- Co-authored-by: Mateus Melchiades --- RECIPE.md | 8 ++++++++ core/recipe.go | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/RECIPE.md b/RECIPE.md index 3f53fe24..636e6fbe 100644 --- a/RECIPE.md +++ b/RECIPE.md @@ -49,6 +49,14 @@ Rename the specified partition. - *PartNum* (`int`): The partition number on disk (e.g. `/dev/sda3` is partition 3). - *PartNewName* (`string`): The new name for the partition. +### setlabel + +Set the filesystem label of the specified partition. + +**Accepts**: +- *PartNum* ('int'): The partition number on disk (e.g. '/dev/sda3' is partition 3). +- *Label* ('string'): The filesystem label + ### setflag Set the value of a partition flag, from the flags supported by parted. diff --git a/core/recipe.go b/core/recipe.go index ebddcb21..05281ae3 100644 --- a/core/recipe.go +++ b/core/recipe.go @@ -239,6 +239,27 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error { if err != nil { return operationError(operation, err) } + /* !! ### setlabel + * + * Set the filesystem label of the specified partition. + * + * **Accepts**: + * - *PartNum* ('int'): The partition number on disk (e.g. '/dev/sda3' is partition 3). + * - *Label* ('string'): The filesystem label + */ + case "setlabel": + partNum, err := jsonFieldToInt(args[0]) + if err != nil { + return operationError(operation, err) + } + partNewName, ok := args[1].(string) + if !ok { + return operationError(operation, "%v is not a string", partNewName) + } + err = target.GetPartition(partNum).SetLabel(partNewName) + if err != nil { + return operationError(operation, err) + } /* !! ### setflag * * Set the value of a partition flag, from the flags supported by parted.