Skip to content

Commit

Permalink
many: fix formatting w/ gofmt 1.19
Browse files Browse the repository at this point in the history
Go 1.19 includes some changes to gofmt which intend to make lists and
heading clearer when rendered (https://go.dev/doc/go1.19). This commit
is the result of running the new gofmt and manually fixing some of it.
This was necessary because the new gofmt assumed lines beginning w/ tabs
to start lists or examples. While this is often true in our codebase,
we occasionally also use tabs to indent the lines after a TODO or FIXME
prefix or in yaml (e.g., excerpts of a snap.yaml). This meant that a lot of the
reformatted comments were broken and had to be fixed manually.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
  • Loading branch information
miguelpires authored and mvo5 committed Jan 16, 2023
1 parent 5725cc7 commit d097436
Show file tree
Hide file tree
Showing 101 changed files with 775 additions and 725 deletions.
12 changes: 6 additions & 6 deletions aspects/aspects.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func newAspect(dir *Directory, name string, aspectPatterns []map[string]string)
}

// validateNamePathPair checks that:
// * names and paths are composed of valid subkeys (see: validateAspectString)
// * all placeholders in a name are in the path and vice-versa
// - names and paths are composed of valid subkeys (see: validateAspectString)
// - all placeholders in a name are in the path and vice-versa
func validateNamePathPair(name, path string) error {
if err := validateAspectDottedPath(name); err != nil {
return fmt.Errorf("invalid access name %q: %w", name, err)
Expand Down Expand Up @@ -202,10 +202,10 @@ var (
)

// validateAspectDottedPath validates that names/paths in an aspect definition are:
// * composed of non-empty, dot-separated subkeys with optional placeholders ("foo.{bar}")
// * non-placeholder subkeys are made up of lowercase alphanumeric ASCII characters,
// optionally with dashes between alphanumeric characters (e.g., "a-b-c")
// * placeholder subkeys are composed of non-placeholder subkeys wrapped in curly brackets
// - composed of non-empty, dot-separated subkeys with optional placeholders ("foo.{bar}")
// - non-placeholder subkeys are made up of lowercase alphanumeric ASCII characters,
// optionally with dashes between alphanumeric characters (e.g., "a-b-c")
// - placeholder subkeys are composed of non-placeholder subkeys wrapped in curly brackets
func validateAspectDottedPath(path string) (err error) {
subkeys := strings.Split(path, ".")

Expand Down
27 changes: 13 additions & 14 deletions asserts/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,60 +665,59 @@ var _ Assertion = (*assertionBase)(nil)
//
// The expected serialisation format looks like:
//
// HEADER ("\n\n" BODY?)? "\n\n" SIGNATURE
// HEADER ("\n\n" BODY?)? "\n\n" SIGNATURE
//
// where:
//
// HEADER is a set of header entries separated by "\n"
// BODY can be arbitrary text,
// SIGNATURE is the signature
// HEADER is a set of header entries separated by "\n"
// BODY can be arbitrary text,
// SIGNATURE is the signature
//
// Both BODY and HEADER must be UTF8.
//
// A header entry for a single line value (no '\n' in it) looks like:
//
// NAME ": " SIMPLEVALUE
// NAME ": " SIMPLEVALUE
//
// The format supports multiline text values (with '\n's in them) and
// lists or maps, possibly nested, with string scalars in them.
//
// For those a header entry looks like:
//
// NAME ":\n" MULTI(baseindent)
// NAME ":\n" MULTI(baseindent)
//
// where MULTI can be
//
// * (baseindent + 4)-space indented value (multiline text)
//
// * entries of a list each of the form:
//
// " "*baseindent " -" ( " " SIMPLEVALUE | "\n" MULTI )
// " "*baseindent " -" ( " " SIMPLEVALUE | "\n" MULTI )
//
// * entries of map each of the form:
//
// " "*baseindent " " NAME ":" ( " " SIMPLEVALUE | "\n" MULTI )
// " "*baseindent " " NAME ":" ( " " SIMPLEVALUE | "\n" MULTI )
//
// baseindent starts at 0 and then grows with nesting matching the
// previous level introduction (e.g. the " "*baseindent " -" bit)
// length minus 1.
//
// In general the following headers are mandatory:
//
// type
// authority-id (except for on the wire/self-signed assertions like serial-request)
// type
// authority-id (except for on the wire/self-signed assertions like serial-request)
//
// Further for a given assertion type all the primary key headers
// must be non empty and must not contain '/'.
//
// The following headers expect string representing integer values and
// if omitted otherwise are assumed to be 0:
//
// revision (a positive int)
// body-length (expected to be equal to the length of BODY)
// format (a positive int for the format iteration of the type used)
// revision (a positive int)
// body-length (expected to be equal to the length of BODY)
// format (a positive int for the format iteration of the type used)
//
// Times are expected to be in the RFC3339 format: "2006-01-02T15:04:05Z07:00".
//
func Decode(serializedAssertion []byte) (Assertion, error) {
// copy to get an independent backstorage that can't be mutated later
assertionSnapshot := make([]byte, len(serializedAssertion))
Expand Down
14 changes: 7 additions & 7 deletions asserts/internal/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
// Labels are implemented as subsets of integers from 0
// up to an excluded maximum, where the integers represent the groups.
// Assumptions:
// - most labels are for one group or very few
// - a few labels are sparse with more groups in them
// - very few comprise the universe of all groups
// - most labels are for one group or very few
// - a few labels are sparse with more groups in them
// - very few comprise the universe of all groups
type Groupings struct {
n uint
maxGroup uint16
Expand Down Expand Up @@ -80,10 +80,10 @@ func (g Grouping) Copy() Grouping {
}

// search locates group among the sorted Grouping elements, it returns:
// * true if found
// * false if not found
// * the index at which group should be inserted to keep the
// elements sorted if not found and the bit-set representation is not in use
// - true if found
// - false if not found
// - the index at which group should be inserted to keep the
// elements sorted if not found and the bit-set representation is not in use
func (gr *Groupings) search(g *Grouping, group uint16) (found bool, j uint16) {
if g.size > gr.bitsetThreshold {
return bitsetContains(g, group), 0
Expand Down
6 changes: 3 additions & 3 deletions asserts/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ var validStorageSafeties = []string{string(StorageSafetyEncrypted), string(Stora
var validModelGrades = []string{string(ModelSecured), string(ModelSigned), string(ModelDangerous)}

// gradeToCode encodes grades into 32 bits, trying to be slightly future-proof:
// * lower 16 bits are reserved
// * in the higher bits use the sequence 1, 8, 16 to have some space
// to possibly add new grades in between
// - lower 16 bits are reserved
// - in the higher bits use the sequence 1, 8, 16 to have some space
// to possibly add new grades in between
var gradeToCode = map[ModelGrade]uint32{
ModelGradeUnset: 0,
ModelDangerous: 0x10000,
Expand Down
30 changes: 15 additions & 15 deletions asserts/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ type Grouping string
// any Add or AddBatch AddUnresolved/AddToUpdate can also be used
// again.
//
// V
// |
// /-> AddUnresolved, AddToUpdate
// | |
// | V
// |------> ToResolve -> empty? done
// | |
// | V
// \ __________ Add
//
// V
// |
// /-> AddUnresolved, AddToUpdate
// | |
// | V
// |------> ToResolve -> empty? done
// | |
// | V
// \ __________ Add
//
// If errors prevent from fulfilling assertions from a ToResolve,
// AddError and AddGroupingError can be used to report the errors so
Expand Down Expand Up @@ -739,11 +738,12 @@ var (

// unresolvedBookkeeping processes any left over unresolved assertions
// since the last ToResolve invocation and intervening calls to Add/AddBatch,
// * they were either marked as in error which will be propagated
// to all groups requiring them
// * simply unresolved, which will be propagated to groups requiring them
// as ErrUnresolved
// * unchanged (update case)
// - they were either marked as in error which will be propagated
// to all groups requiring them
// - simply unresolved, which will be propagated to groups requiring them
// as ErrUnresolved
// - unchanged (update case)
//
// unresolvedBookkeeping will also promote any recorded prerequisites
// into actively unresolved, as long as not all the groups requiring them
// are in error.
Expand Down
30 changes: 15 additions & 15 deletions boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,21 @@ type bootStateUpdate interface {
// target for rollback.
//
// The states that a boot goes through for UC16/18 are the following:
// - By default snap_mode is "" in which case the bootloader loads
// two squashfs'es denoted by variables snap_core and snap_kernel.
// - On a refresh of core/kernel snapd will set snap_mode=try and
// will also set snap_try_{core,kernel} to the core/kernel that
// will be tried next.
// - On reboot the bootloader will inspect the snap_mode and if the
// mode is set to "try" it will set "snap_mode=trying" and then
// try to boot the snap_try_{core,kernel}".
// - On a successful boot snapd resets snap_mode to "" and copies
// snap_try_{core,kernel} to snap_{core,kernel}. The snap_try_*
// values are cleared afterwards.
// - On a failing boot the bootloader will see snap_mode=trying which
// means snapd did not start successfully. In this case the bootloader
// will set snap_mode="" and the system will boot with the known good
// values from snap_{core,kernel}
// - By default snap_mode is "" in which case the bootloader loads
// two squashfs'es denoted by variables snap_core and snap_kernel.
// - On a refresh of core/kernel snapd will set snap_mode=try and
// will also set snap_try_{core,kernel} to the core/kernel that
// will be tried next.
// - On reboot the bootloader will inspect the snap_mode and if the
// mode is set to "try" it will set "snap_mode=trying" and then
// try to boot the snap_try_{core,kernel}".
// - On a successful boot snapd resets snap_mode to "" and copies
// snap_try_{core,kernel} to snap_{core,kernel}. The snap_try_*
// values are cleared afterwards.
// - On a failing boot the bootloader will see snap_mode=trying which
// means snapd did not start successfully. In this case the bootloader
// will set snap_mode="" and the system will boot with the known good
// values from snap_{core,kernel}
func MarkBootSuccessful(dev snap.Device) error {
const errPrefix = "cannot mark boot successful: %s"

Expand Down
8 changes: 4 additions & 4 deletions boot/makebootable.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func MakeBootablePartition(partDir string, opts *bootloader.Options, bootWith *B

// makeBootable16 setups the image filesystem for boot with UC16
// and UC18 models. This entails:
// - installing the bootloader configuration from the gadget
// - creating symlinks for boot snaps from seed to the runtime blob dir
// - setting boot env vars pointing to the revisions of the boot snaps to use
// - extracting kernel assets as needed by the bootloader
// - installing the bootloader configuration from the gadget
// - creating symlinks for boot snaps from seed to the runtime blob dir
// - setting boot env vars pointing to the revisions of the boot snaps to use
// - extracting kernel assets as needed by the bootloader
func makeBootable16(model *asserts.Model, rootdir string, bootWith *BootableSet) error {
opts := &bootloader.Options{
PrepareImageTime: true,
Expand Down
3 changes: 2 additions & 1 deletion bootloader/bootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ var (
//
// The rootdir option is useful for image creation operations. It
// can also be used to find the recovery bootloader, e.g. on uc20:
// bootloader.Find("/run/mnt/ubuntu-seed")
//
// bootloader.Find("/run/mnt/ubuntu-seed")
func Find(rootdir string, opts *Options) (Bootloader, error) {
if err := opts.validate(); err != nil {
return nil, err
Expand Down
24 changes: 11 additions & 13 deletions bootloader/lkenv/lkenv_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ import (
"fmt"
)

/**
* Following structure has to be kept in sync with c structure defined by
* include/lk/snappy-boot_v1.h
* c headerfile is used by bootloader, this ensures sync of the environment
* between snapd and bootloader
* when this structure needs to be updated,
* new version should be introduced instead together with c header file,
* which is to be adopted by bootloader
*
* !!! Support for old version has to be maintained, as it is not guaranteed
* all existing bootloader would adopt new version!
*/
// Following structure has to be kept in sync with c structure defined by
// include/lk/snappy-boot_v1.h
// c headerfile is used by bootloader, this ensures sync of the environment
// between snapd and bootloader
//
// when this structure needs to be updated,
// new version should be introduced instead together with c header file,
// which is to be adopted by bootloader
//
// !!! Support for old version has to be maintained, as it is not guaranteed
// all existing bootloader would adopt new version!
type SnapBootSelect_v1 struct {
/* Contains value BOOTSELECT_SIGNATURE defined above */
Signature uint32
Expand Down
23 changes: 13 additions & 10 deletions bootloader/piboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,20 @@ func (p *piboot) Present() (bool, error) {
}

// Variables stored in ubuntu-seed:
// snapd_recovery_system
// snapd_recovery_mode
// snapd_recovery_kernel
//
// snapd_recovery_system
// snapd_recovery_mode
// snapd_recovery_kernel
//
// Variables stored in ubuntu-boot:
// kernel_status
// snap_kernel
// snap_try_kernel
// snapd_extra_cmdline_args
// snapd_full_cmdline_args
// recovery_system_status
// try_recovery_system
//
// kernel_status
// snap_kernel
// snap_try_kernel
// snapd_extra_cmdline_args
// snapd_full_cmdline_args
// recovery_system_status
// try_recovery_system
func (p *piboot) SetBootVars(values map[string]string) error {
env, err := ubootenv.OpenWithFlags(p.envFile(), ubootenv.OpenBestEffort)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bootloader/ubootenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"strings"
)

// FIXME: add config option for that so that the user can select if
// he/she wants env with or without flags
// FIXME: add config option for that so that the user can select if he/she
// wants env with or without flags
var headerSize = 5

// Env contains the data of the uboot environment
Expand Down
2 changes: 1 addition & 1 deletion client/snapctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type SnapCtlOptions struct {

// SnapCtlPostData is the data posted to the daemon /v2/snapctl endpoint
// TODO: this can be removed again once we no longer need to pass stdin data
// but instead use a real stdin stream
// but instead use a real stdin stream
type SnapCtlPostData struct {
SnapCtlOptions

Expand Down
17 changes: 9 additions & 8 deletions cmd/snap-bootstrap/cmd_initramfs_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func copyNetworkConfig(src, dst string) error {

// copyUbuntuDataMisc copies miscellaneous other files from the run mode system
// to the recover system such as:
// - timesync clock to keep the same time setting in recover as in run mode
// - timesync clock to keep the same time setting in recover as in run mode
func copyUbuntuDataMisc(src, dst string) error {
for _, globEx := range []string{
// systemd's timesync clock file so that the time in recover mode moves
Expand All @@ -273,9 +273,10 @@ func copyUbuntuDataMisc(src, dst string) error {
}

// copyUbuntuDataAuth copies the authentication files like
// - extrausers passwd,shadow etc
// - sshd host configuration
// - user .ssh dir
// - extrausers passwd,shadow etc
// - sshd host configuration
// - user .ssh dir
//
// to the target directory. This is used to copy the authentication
// data from a real uc20 ubuntu-data partition into a ephemeral one.
func copyUbuntuDataAuth(src, dst string) error {
Expand Down Expand Up @@ -825,10 +826,10 @@ func (m *recoverModeStateMachine) trustData() bool {

// mountBoot is the first state to execute in the state machine, it can
// transition to the following states:
// - if ubuntu-boot is mounted successfully, execute unlockDataRunKey
// - if ubuntu-boot can't be mounted, execute unlockDataFallbackKey
// - if we mounted the wrong ubuntu-boot (or otherwise can't verify which one we
// mounted), return fatal error
// - if ubuntu-boot is mounted successfully, execute unlockDataRunKey
// - if ubuntu-boot can't be mounted, execute unlockDataFallbackKey
// - if we mounted the wrong ubuntu-boot (or otherwise can't verify which one we
// mounted), return fatal error
func (m *recoverModeStateMachine) mountBoot() (stateFunc, error) {
part := m.degradedState.partition("ubuntu-boot")
// use the disk we mounted ubuntu-seed from as a reference to find
Expand Down
10 changes: 5 additions & 5 deletions cmd/snap-recovery-chooser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
//
// The JSON object carrying the list of systems is the client.ChooserSystems
// structure. The response is defined as follows:
// {
// "label": "<system-label",
// "action": {} // client.SystemAction object
// }
//
// {
// "label": "<system-label",
// "action": {} // client.SystemAction object
// }
//
// No action is forwarded to snapd if the chooser UI exits with an error code or
// the response structure is invalid.
//
package main

import (
Expand Down
Loading

0 comments on commit d097436

Please sign in to comment.