github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/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 "github.com/snapcore/snapd/snap/snapfile" 26 ) 27 28 // Backend exposes all the low-level primitives to manage snaps and their installation on disk. 29 type Backend struct { 30 preseed bool 31 } 32 33 // Candidate is a test hook. 34 func (b Backend) Candidate(*snap.SideInfo) {} 35 36 // CurrentInfo is a test hook. 37 func (b Backend) CurrentInfo(*snap.Info) {} 38 39 // OpenSnapFile opens a snap blob returning both a snap.Info completed 40 // with sideInfo (if not nil) and a corresponding snap.Container. 41 // Assumes the file was verified beforehand or the user asked for --dangerous. 42 func OpenSnapFile(snapPath string, sideInfo *snap.SideInfo) (*snap.Info, snap.Container, error) { 43 snapf, err := snapfile.Open(snapPath) 44 if err != nil { 45 return nil, nil, err 46 } 47 48 info, err := snap.ReadInfoFromSnapFile(snapf, sideInfo) 49 if err != nil { 50 return nil, nil, err 51 } 52 53 return info, snapf, nil 54 } 55 56 func NewForPreseedMode() Backend { 57 return Backend{preseed: true} 58 }