github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/overlord/snapstate/flags.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package snapstate
    21  
    22  // Flags are used to pass additional flags to operations and to keep track of snap modes.
    23  type Flags struct {
    24  	// DevMode switches confinement to non-enforcing mode.
    25  	DevMode bool `json:"devmode,omitempty"`
    26  	// JailMode is set when the user has requested confinement
    27  	// always be enforcing, even if the snap requests otherwise.
    28  	JailMode bool `json:"jailmode,omitempty"`
    29  	// Classic is set when the user has consented to install a snap with
    30  	// classic confinement and the snap declares that confinement.
    31  	Classic bool `json:"classic,omitempty"`
    32  	// TryMode is set for snaps installed to try directly from a local directory.
    33  	TryMode bool `json:"trymode,omitempty"`
    34  
    35  	// Revert flags the SnapSetup as coming from a revert
    36  	Revert bool `json:"revert,omitempty"`
    37  
    38  	// RemoveSnapPath is used via InstallPath to flag that the file passed in is temporary and should be removed
    39  	RemoveSnapPath bool `json:"remove-snap-path,omitempty"`
    40  
    41  	// IgnoreValidation is set when the user requested as one-off
    42  	// to ignore refresh control validation.
    43  	IgnoreValidation bool `json:"ignore-validation,omitempty"`
    44  
    45  	// Required is set to mark that a snap is required
    46  	// and cannot be removed
    47  	Required bool `json:"required,omitempty"`
    48  
    49  	// SkipConfigure is used with InstallPath to flag that creating a task
    50  	// running the configure hook should be skipped.
    51  	SkipConfigure bool `json:"skip-configure,omitempty"`
    52  
    53  	// Unaliased is set to request that no automatic aliases are created
    54  	// installing the snap.
    55  	Unaliased bool `json:"unaliased,omitempty"`
    56  
    57  	// Amend allows refreshing out of a snap unknown to the store
    58  	// and into one that is known.
    59  	Amend bool `json:"amend,omitempty"`
    60  
    61  	// IsAutoRefresh is true if the snap is currently auto-refreshed
    62  	IsAutoRefresh bool `json:"is-auto-refresh,omitempty"`
    63  
    64  	// NoReRefresh prevents refresh from adding epoch-hopping
    65  	// re-refresh tasks. This allows refresh to work offline, as
    66  	// long as refresh assets are cached.
    67  	NoReRefresh bool `json:"no-rerefresh,omitempty"`
    68  
    69  	// RequireTypeBase is set to mark that a snap needs to be of type: base, otherwise installation fails.
    70  	RequireTypeBase bool `json:"require-base-type,omitempty"`
    71  }
    72  
    73  // DevModeAllowed returns whether a snap can be installed with devmode confinement (either set or overridden)
    74  func (f Flags) DevModeAllowed() bool {
    75  	return f.DevMode || f.JailMode
    76  }
    77  
    78  // ForSnapSetup returns a copy of the Flags with the flags that we don't need in SnapSetup set to false (so they're not serialized)
    79  func (f Flags) ForSnapSetup() Flags {
    80  	f.SkipConfigure = false
    81  	f.NoReRefresh = false
    82  	f.RequireTypeBase = false
    83  	return f
    84  }