github.com/rigado/snapd@v2.42.5-go-mod+incompatible/overlord/snapstate/backend/backend.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2014-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 backend implements the low-level primitives to manage the snaps and their installation on disk.
    21  package backend
    22  
    23  import (
    24  	"github.com/snapcore/snapd/snap"
    25  )
    26  
    27  // Backend exposes all the low-level primitives to manage snaps and their installation on disk.
    28  type Backend struct{}
    29  
    30  // Candidate is a test hook.
    31  func (b Backend) Candidate(*snap.SideInfo) {}
    32  
    33  // CurrentInfo is a test hook.
    34  func (b Backend) CurrentInfo(*snap.Info) {}
    35  
    36  // OpenSnapFile opens a snap blob returning both a snap.Info completed
    37  // with sideInfo (if not nil) and a corresponding snap.Container.
    38  // Assumes the file was verified beforehand or the user asked for --dangerous.
    39  func OpenSnapFile(snapPath string, sideInfo *snap.SideInfo) (*snap.Info, snap.Container, error) {
    40  	snapf, err := snap.Open(snapPath)
    41  	if err != nil {
    42  		return nil, nil, err
    43  	}
    44  
    45  	info, err := snap.ReadInfoFromSnapFile(snapf, sideInfo)
    46  	if err != nil {
    47  		return nil, nil, err
    48  	}
    49  
    50  	return info, snapf, nil
    51  }