本文整理汇总了Golang中github.com/snapcore/snapd/snap.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: installLocalTestSnap
func (ms *mgrsSuite) installLocalTestSnap(c *C, snapYamlContent string) *snap.Info {
st := ms.o.State()
snapPath := makeTestSnap(c, snapYamlContent)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, IsNil)
// store current state
snapName := info.Name()
var snapst snapstate.SnapState
snapstate.Get(st, snapName, &snapst)
ts, err := snapstate.InstallPath(st, &snap.SideInfo{RealName: snapName}, snapPath, "", snapstate.Flags{DevMode: true})
c.Assert(err, IsNil)
chg := st.NewChange("install-snap", "...")
chg.AddAll(ts)
st.Unlock()
err = ms.o.Settle()
st.Lock()
c.Assert(err, IsNil)
c.Assert(chg.Err(), IsNil)
c.Assert(chg.Status(), Equals, state.DoneStatus, Commentf("install-snap change failed with: %v", chg.Err()))
return info
}
开发者ID:chipaca,项目名称:snappy,代码行数:29,代码来源:managers_test.go
示例2: tryDirect
func tryDirect(w io.Writer, path string, verbose bool) bool {
path = norm(path)
snapf, err := snap.Open(path)
if err != nil {
return false
}
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
if err != nil {
return false
}
fmt.Fprintf(w, "path:\t%q\n", path)
fmt.Fprintf(w, "name:\t%s\n", info.Name())
fmt.Fprintf(w, "summary:\t%q\n", info.Summary())
var notes *Notes
if verbose {
fmt.Fprintln(w, "notes:\t")
fmt.Fprintf(w, " confinement:\t%s\n", info.Confinement)
if info.Broken == "" {
fmt.Fprintln(w, " broken:\tfalse")
} else {
fmt.Fprintf(w, " broken:\ttrue (%s)\n", info.Broken)
}
} else {
notes = NotesFromInfo(info)
}
fmt.Fprintf(w, "version:\t%s %s\n", info.Version, notes)
maybePrintType(w, string(info.Type))
return true
}
开发者ID:pedronis,项目名称:snappy,代码行数:34,代码来源:cmd_info.go
示例3: TestExtractKernelAssetsNoUnpacksKernelForGrub
func (s *kernelOSSuite) TestExtractKernelAssetsNoUnpacksKernelForGrub(c *C) {
// pretend to be a grub system
mockGrub := boottest.NewMockBootloader("grub", c.MkDir())
partition.ForceBootloader(mockGrub)
files := [][]string{
{"kernel.img", "I'm a kernel"},
{"initrd.img", "...and I'm an initrd"},
{"meta/kernel.yaml", "version: 4.2"},
}
si := &snap.SideInfo{
RealName: "ubuntu-kernel",
Revision: snap.R(42),
}
fn := snaptest.MakeTestSnapWithFiles(c, packageKernel, files)
snapf, err := snap.Open(fn)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, si)
c.Assert(err, IsNil)
err = boot.ExtractKernelAssets(info, snapf)
c.Assert(err, IsNil)
// kernel is *not* here
kernimg := filepath.Join(mockGrub.Dir(), "ubuntu-kernel_42.snap", "kernel.img")
c.Assert(osutil.FileExists(kernimg), Equals, false)
}
开发者ID:elopio,项目名称:snappy,代码行数:28,代码来源:kernel_os_test.go
示例4: unsafeReadSnapInfoImpl
func unsafeReadSnapInfoImpl(snapPath string) (*snap.Info, error) {
// Condider using DeriveSideInfo before falling back to this!
snapf, err := snap.Open(snapPath)
if err != nil {
return nil, err
}
return snap.ReadInfoFromSnapFile(snapf, nil)
}
开发者ID:clobrano,项目名称:snappy,代码行数:8,代码来源:api.go
示例5: TestReadInfoFromSnapFileCatchesInvalidImplicitHook
func (s *infoSuite) TestReadInfoFromSnapFileCatchesInvalidImplicitHook(c *C) {
yaml := `name: foo
version: 1.0`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, emptyHooks("123abc"))
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
_, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, ErrorMatches, ".*invalid hook name.*")
}
开发者ID:pedronis,项目名称:snappy,代码行数:11,代码来源:info_test.go
示例6: extractKernelAssets
func extractKernelAssets(snapPath string, info *snap.Info) error {
snapf, err := snap.Open(snapPath)
if err != nil {
return err
}
if err := boot.ExtractKernelAssets(info, snapf); err != nil {
return err
}
return nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:11,代码来源:image.go
示例7: TestReadInfoFromSnapFileValidates
func (s *infoSuite) TestReadInfoFromSnapFileValidates(c *C) {
yaml := `name: foo.bar
version: 1.0
type: app`
snapPath := makeTestSnap(c, yaml)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
_, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, ErrorMatches, "invalid snap name.*")
}
开发者ID:pedronis,项目名称:snappy,代码行数:12,代码来源:info_test.go
示例8: TestFileOpenForSnapDir
func (s *FileSuite) TestFileOpenForSnapDir(c *C) {
sd := c.MkDir()
snapYaml := filepath.Join(sd, "meta", "snap.yaml")
err := os.MkdirAll(filepath.Dir(snapYaml), 0755)
c.Assert(err, IsNil)
err = ioutil.WriteFile(snapYaml, []byte(`name: foo`), 0644)
c.Assert(err, IsNil)
f, err := snap.Open(sd)
c.Assert(err, IsNil)
c.Assert(f, FitsTypeOf, &snapdir.SnapDir{})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:12,代码来源:container_test.go
示例9: TestReadInfoFromSnapFileCatchesInvalidConfinement
func (s *infoSuite) TestReadInfoFromSnapFileCatchesInvalidConfinement(c *C) {
yaml := `name: foo
version: 1.0
confinement: foo`
snapPath := makeTestSnap(c, yaml)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
_, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, ErrorMatches, ".*invalid confinement type.*")
}
开发者ID:pedronis,项目名称:snappy,代码行数:12,代码来源:info_test.go
示例10: OpenSnapFile
// OpenSnapFile opens a snap blob returning both a snap.Info completed
// with sideInfo (if not nil) and a corresponding snap.Container.
// Assumes the file was verified beforehand or the user asked for --dangerous.
func OpenSnapFile(snapPath string, sideInfo *snap.SideInfo) (*snap.Info, snap.Container, error) {
snapf, err := snap.Open(snapPath)
if err != nil {
return nil, nil, err
}
info, err := snap.ReadInfoFromSnapFile(snapf, sideInfo)
if err != nil {
return nil, nil, err
}
return info, snapf, nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:16,代码来源:backend.go
示例11: TestReadInfoFromSnapFileCatchesInvalidHook
func (s *infoSuite) TestReadInfoFromSnapFileCatchesInvalidHook(c *C) {
yaml := `name: foo
version: 1.0
hooks:
123abc:`
snapPath := makeTestSnap(c, yaml)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
_, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, ErrorMatches, ".*invalid hook name.*")
}
开发者ID:pedronis,项目名称:snappy,代码行数:13,代码来源:info_test.go
示例12: serveSnap
func (ms *mgrsSuite) serveSnap(snapPath, revno string) {
snapf, err := snap.Open(snapPath)
if err != nil {
panic(err)
}
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
if err != nil {
panic(err)
}
name := info.Name()
ms.serveIDtoName[fakeSnapID(name)] = name
ms.serveSnapPath[name] = snapPath
ms.serveRevision[name] = revno
}
开发者ID:pedronis,项目名称:snappy,代码行数:14,代码来源:managers_test.go
示例13: snapEssentialInfo
func snapEssentialInfo(w http.ResponseWriter, fn, snapID string, bs asserts.Backstore) (*essentialInfo, error) {
snapFile, err := snap.Open(fn)
if err != nil {
http.Error(w, fmt.Sprintf("cannot read: %v: %v", fn, err), http.StatusBadRequest)
return nil, errInfo
}
info, err := snap.ReadInfoFromSnapFile(snapFile, nil)
if err != nil {
http.Error(w, fmt.Sprintf("can get info for: %v: %v", fn, err), http.StatusBadRequest)
return nil, errInfo
}
snapDigest, size, err := asserts.SnapFileSHA3_384(fn)
if err != nil {
http.Error(w, fmt.Sprintf("can get digest for: %v: %v", fn, err), http.StatusBadRequest)
return nil, errInfo
}
snapRev, devAcct, err := findSnapRevision(snapDigest, bs)
if err != nil && err != asserts.ErrNotFound {
http.Error(w, fmt.Sprintf("can get info for: %v: %v", fn, err), http.StatusBadRequest)
return nil, errInfo
}
var devel, develID string
var revision int
if snapRev != nil {
snapID = snapRev.SnapID()
develID = snapRev.DeveloperID()
devel = devAcct.Username()
revision = snapRev.SnapRevision()
} else {
// XXX: fallback until we are always assertion based
develID = defaultDeveloperID
devel = defaultDeveloper
revision = makeRevision(info)
}
return &essentialInfo{
Name: info.Name(),
SnapID: snapID,
DeveloperID: develID,
DevelName: devel,
Revision: revision,
Version: info.Version,
Digest: snapDigest,
Size: size,
}, nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:50,代码来源:store.go
示例14: TestExtractKernelAssetsAndRemove
func (s *kernelOSSuite) TestExtractKernelAssetsAndRemove(c *C) {
files := [][]string{
{"kernel.img", "I'm a kernel"},
{"initrd.img", "...and I'm an initrd"},
{"dtbs/foo.dtb", "g'day, I'm foo.dtb"},
{"dtbs/bar.dtb", "hello, I'm bar.dtb"},
// must be last
{"meta/kernel.yaml", "version: 4.2"},
}
si := &snap.SideInfo{
RealName: "ubuntu-kernel",
Revision: snap.R(42),
}
fn := snaptest.MakeTestSnapWithFiles(c, packageKernel, files)
snapf, err := snap.Open(fn)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, si)
c.Assert(err, IsNil)
err = boot.ExtractKernelAssets(info, snapf)
c.Assert(err, IsNil)
// this is where the kernel/initrd is unpacked
bootdir := s.bootloader.Dir()
kernelAssetsDir := filepath.Join(bootdir, "ubuntu-kernel_42.snap")
for _, def := range files {
if def[0] == "meta/kernel.yaml" {
break
}
fullFn := filepath.Join(kernelAssetsDir, def[0])
content, err := ioutil.ReadFile(fullFn)
c.Assert(err, IsNil)
c.Assert(string(content), Equals, def[1])
}
// remove
err = boot.RemoveKernelAssets(info)
c.Assert(err, IsNil)
c.Check(osutil.FileExists(kernelAssetsDir), Equals, false)
}
开发者ID:elopio,项目名称:snappy,代码行数:46,代码来源:kernel_os_test.go
示例15: TestReadInfoFromSnapFileMissingEpoch
func (s *infoSuite) TestReadInfoFromSnapFileMissingEpoch(c *C) {
yaml := `name: foo
version: 1.0
type: app`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, nil)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, IsNil)
c.Check(info.Name(), Equals, "foo")
c.Check(info.Version, Equals, "1.0")
c.Check(info.Type, Equals, snap.TypeApp)
c.Check(info.Revision, Equals, snap.R(0))
c.Check(info.Epoch, Equals, "0") // Defaults to 0
}
开发者ID:pedronis,项目名称:snappy,代码行数:17,代码来源:info_test.go
示例16: checkInstalledSnapAndSnapFile
func (s *infoSuite) checkInstalledSnapAndSnapFile(c *C, yaml string, contents string, hooks []string, checker func(c *C, info *snap.Info)) {
// First check installed snap
sideInfo := &snap.SideInfo{Revision: snap.R(42)}
info0 := snaptest.MockSnap(c, yaml, contents, sideInfo)
snaptest.PopulateDir(info0.MountDir(), emptyHooks(hooks...))
info, err := snap.ReadInfo(info0.Name(), sideInfo)
c.Check(err, IsNil)
checker(c, info)
// Now check snap file
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, emptyHooks(hooks...))
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Check(err, IsNil)
checker(c, info)
}
开发者ID:pedronis,项目名称:snappy,代码行数:17,代码来源:info_test.go
示例17: TestReadInfoFromSnapFileWithSideInfo
func (s *infoSuite) TestReadInfoFromSnapFileWithSideInfo(c *C) {
yaml := `name: foo
version: 1.0
type: app`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, nil)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, &snap.SideInfo{
RealName: "baz",
Revision: snap.R(42),
})
c.Assert(err, IsNil)
c.Check(info.Name(), Equals, "baz")
c.Check(info.Version, Equals, "1.0")
c.Check(info.Type, Equals, snap.TypeApp)
c.Check(info.Revision, Equals, snap.R(42))
}
开发者ID:pedronis,项目名称:snappy,代码行数:19,代码来源:info_test.go
示例18: TestReadInfoFromSnapFile
func (s *infoSuite) TestReadInfoFromSnapFile(c *C) {
yaml := `name: foo
version: 1.0
type: app
epoch: 1*
confinement: devmode`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, nil)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, IsNil)
c.Check(info.Name(), Equals, "foo")
c.Check(info.Version, Equals, "1.0")
c.Check(info.Type, Equals, snap.TypeApp)
c.Check(info.Revision, Equals, snap.R(0))
c.Check(info.Epoch, Equals, "1*")
c.Check(info.Confinement, Equals, snap.DevModeConfinement)
}
开发者ID:pedronis,项目名称:snappy,代码行数:20,代码来源:info_test.go
示例19: collectSnaps
func (s *Store) collectSnaps() (map[string]string, error) {
snapFns, err := filepath.Glob(filepath.Join(s.blobDir, "*.snap"))
if err != nil {
return nil, err
}
snaps := map[string]string{}
for _, fn := range snapFns {
snapFile, err := snap.Open(fn)
if err != nil {
return nil, err
}
info, err := snap.ReadInfoFromSnapFile(snapFile, nil)
if err != nil {
return nil, err
}
snaps[info.Name()] = fn
}
return snaps, err
}
开发者ID:pedronis,项目名称:snappy,代码行数:22,代码来源:store.go
示例20: localSnaps
func localSnaps(opts *Options) (*localInfos, error) {
local := make(map[string]*snap.Info)
nameToPath := make(map[string]string)
for _, snapName := range opts.Snaps {
if strings.HasSuffix(snapName, ".snap") && osutil.FileExists(snapName) {
snapFile, err := snap.Open(snapName)
if err != nil {
return nil, err
}
info, err := snap.ReadInfoFromSnapFile(snapFile, nil)
if err != nil {
return nil, err
}
// local snap gets local revision
info.Revision = snap.R(-1)
nameToPath[info.Name()] = snapName
local[snapName] = info
}
}
return &localInfos{
pathToInfo: local,
nameToPath: nameToPath,
}, nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:24,代码来源:image.go
注:本文中的github.com/snapcore/snapd/snap.Open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论