本文整理汇总了Golang中github.com/ubuntu-core/snappy/snap.Info类的典型用法代码示例。如果您正苦于以下问题:Golang Info类的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Info类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addPackageDesktopFiles
func addPackageDesktopFiles(s *snap.Info) error {
if err := os.MkdirAll(dirs.SnapDesktopFilesDir, 0755); err != nil {
return err
}
baseDir := s.MountDir()
desktopFiles, err := filepath.Glob(filepath.Join(baseDir, "meta", "gui", "*.desktop"))
if err != nil {
return fmt.Errorf("cannot get desktop files for %v: %s", baseDir, err)
}
for _, df := range desktopFiles {
content, err := ioutil.ReadFile(df)
if err != nil {
return err
}
realBaseDir := stripGlobalRootDir(baseDir)
content = sanitizeDesktopFile(s, realBaseDir, content)
installedDesktopFileName := filepath.Join(dirs.SnapDesktopFilesDir, fmt.Sprintf("%s_%s", s.Name(), filepath.Base(df)))
if err := osutil.AtomicWriteFile(installedDesktopFileName, []byte(content), 0755, 0); err != nil {
return err
}
}
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:29,代码来源:desktop.go
示例2: UnlinkSnap
// UnlinkSnap deactivates the given active snap.
func UnlinkSnap(info *snap.Info, inter interacter) error {
mountDir := info.MountDir()
currentSymlink := filepath.Join(mountDir, "..", "current")
currentActiveDir, err := filepath.EvalSymlinks(currentSymlink)
if err != nil {
if os.IsNotExist(err) {
return ErrSnapNotActive
}
return err
}
if mountDir != currentActiveDir {
return ErrSnapNotActive
}
// remove generated services, binaries, security policy
err1 := RemoveGeneratedWrappers(info, inter)
// removing security setup move here!
// and finally remove current symlink
err2 := removeCurrentSymlink(info, inter)
// FIXME: aggregate errors instead
return firstErr(err1, err2)
}
开发者ID:dholbach,项目名称:snappy,代码行数:27,代码来源:overlord.go
示例3: canInstall
// CanInstall checks whether the Snap passes a series of tests required for installation
func canInstall(s *snap.Info, snapf snap.File, curInfo *snap.Info, allowGadget bool, inter interacter) error {
// verify we have a valid architecture
if !arch.IsSupportedArchitecture(s.Architectures) {
return &ErrArchitectureNotSupported{s.Architectures}
}
if s.Type == snap.TypeGadget {
if !allowGadget {
if currentGadget, err := getGadget(); err == nil {
if currentGadget.Name() != s.Name() {
return ErrGadgetPackageInstall
}
} else {
// there should always be a gadget package now
return ErrGadgetPackageInstall
}
}
}
if err := checkLicenseAgreement(s, snapf, curInfo, inter); err != nil {
return err
}
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:26,代码来源:overlord.go
示例4: addPackageBinaries
func addPackageBinaries(s *snap.Info) error {
if err := os.MkdirAll(dirs.SnapBinariesDir, 0755); err != nil {
return err
}
baseDir := s.MountDir()
for _, app := range s.Apps {
if app.Daemon != "" {
continue
}
// this will remove the global base dir when generating the
// service file, this ensures that /snap/foo/1.0/bin/start
// is in the service file when the SetRoot() option
// is used
realBaseDir := stripGlobalRootDir(baseDir)
content, err := generateSnapBinaryWrapper(app, realBaseDir)
if err != nil {
return err
}
if err := osutil.AtomicWriteFile(app.WrapperPath(), []byte(content), 0755, 0); err != nil {
return err
}
}
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:29,代码来源:binaries.go
示例5: RemoveSnapData
func (f *fakeSnappyBackend) RemoveSnapData(info *snap.Info) error {
f.ops = append(f.ops, fakeOp{
op: "remove-snap-data",
name: info.MountDir(),
})
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:7,代码来源:backend_test.go
示例6: Download
// Download downloads the given snap and returns its filename.
// The file is saved in temporary storage, and should be removed
// after use to prevent the disk from running out of space.
func (s *SnapUbuntuStoreRepository) Download(remoteSnap *snap.Info, pbar progress.Meter, auther Authenticator) (path string, err error) {
w, err := ioutil.TempFile("", remoteSnap.Name())
if err != nil {
return "", err
}
defer func() {
if cerr := w.Close(); cerr != nil && err == nil {
err = cerr
}
if err != nil {
os.Remove(w.Name())
path = ""
}
}()
url := remoteSnap.AnonDownloadURL
if url == "" || auther != nil {
url = remoteSnap.DownloadURL
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}
s.applyUbuntuStoreHeaders(req, "", auther)
if err := download(remoteSnap.Name(), w, req, pbar); err != nil {
return "", err
}
return w.Name(), w.Sync()
}
开发者ID:dholbach,项目名称:snappy,代码行数:35,代码来源:snap_remote_repo.go
示例7: UndoCopySnapData
func (f *fakeSnappyBackend) UndoCopySnapData(newInfo *snap.Info, flags int) error {
f.ops = append(f.ops, fakeOp{
op: "undo-copy-snap-data",
name: newInfo.MountDir(),
})
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:7,代码来源:backend_test.go
示例8: setNextBoot
// setNextBoot will schedule the given os or kernel snap to be used in
// the next boot
func setNextBoot(s *snap.Info) error {
if s.Type != snap.TypeOS && s.Type != snap.TypeKernel {
return nil
}
bootloader, err := findBootloader()
if err != nil {
return fmt.Errorf("can not set next boot: %s", err)
}
var bootvar string
switch s.Type {
case snap.TypeOS:
bootvar = "snappy_os"
case snap.TypeKernel:
bootvar = "snappy_kernel"
}
blobName := filepath.Base(s.MountFile())
if err := bootloader.SetBootVar(bootvar, blobName); err != nil {
return err
}
if err := bootloader.SetBootVar("snappy_mode", "try"); err != nil {
return err
}
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:30,代码来源:kernel_os.go
示例9: UndoCopyData
func UndoCopyData(newInfo *snap.Info, flags InstallFlags, meter progress.Meter) {
// XXX we were copying data, assume InhibitHooks was false
if err := RemoveSnapData(newInfo); err != nil {
logger.Noticef("When cleaning up data for %s %s: %v", newInfo.Name(), newInfo.Version, err)
}
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:overlord.go
示例10: snapDate
// snapDate returns the time of the snap mount directory.
func snapDate(info *snap.Info) time.Time {
st, err := os.Stat(info.MountDir())
if err != nil {
return time.Time{}
}
return st.ModTime()
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:snap.go
示例11: UnlinkSnap
func (f *fakeSnappyBackend) UnlinkSnap(info *snap.Info, meter progress.Meter) error {
meter.Notify("unlink")
f.ops = append(f.ops, fakeOp{
op: "unlink-snap",
name: info.MountDir(),
})
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:backend_test.go
示例12: CanRemove
func (f *fakeSnappyBackend) CanRemove(info *snap.Info, active bool) bool {
f.ops = append(f.ops, fakeOp{
op: "can-remove",
name: info.MountDir(),
active: active,
})
return true
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:backend_test.go
示例13: snapIcon
// snapIcon tries to find the icon inside the snap
func snapIcon(info *snap.Info) string {
// XXX: copy of snap.Snap.Icon which will go away
found, _ := filepath.Glob(filepath.Join(info.MountDir(), "meta", "gui", "icon.*"))
if len(found) == 0 {
return ""
}
return found[0]
}
开发者ID:dholbach,项目名称:snappy,代码行数:10,代码来源:snap.go
示例14: extractKernelAssets
// extractKernelAssets extracts kernel/initrd/dtb data from the given
// Snap to a versionized bootloader directory so that the bootloader
// can use it.
func extractKernelAssets(s *snap.Info, snapf snap.File, flags InstallFlags, inter progress.Meter) error {
if s.Type != snap.TypeKernel {
return fmt.Errorf("can not extract kernel assets from snap type %q", s.Type)
}
bootloader, err := findBootloader()
if err != nil {
return fmt.Errorf("can not extract kernel assets: %s", err)
}
// check if we are on a "grub" system. if so, no need to unpack
// the kernel
if oem, err := getGadget(); err == nil {
if oem.Legacy.Gadget.Hardware.Bootloader == "grub" {
return nil
}
}
// now do the kernel specific bits
blobName := filepath.Base(s.MountFile())
dstDir := filepath.Join(bootloader.Dir(), blobName)
if err := os.MkdirAll(dstDir, 0755); err != nil {
return err
}
dir, err := os.Open(dstDir)
if err != nil {
return err
}
defer dir.Close()
for _, src := range []string{s.Legacy.Kernel, s.Legacy.Initrd} {
if src == "" {
continue
}
if err := snapf.Unpack(src, dstDir); err != nil {
return err
}
src = filepath.Join(dstDir, src)
dst := filepath.Join(dstDir, dropVersionSuffix(src))
if err := os.Rename(src, dst); err != nil {
return err
}
if err := dir.Sync(); err != nil {
return err
}
}
if s.Legacy.Dtbs != "" {
src := filepath.Join(s.Legacy.Dtbs, "*")
dst := dstDir
if err := snapf.Unpack(src, dst); err != nil {
return err
}
}
return dir.Sync()
}
开发者ID:dholbach,项目名称:snappy,代码行数:59,代码来源:kernel_os.go
示例15: updateSnap
// updateSnap "updates" an existing snap from YAML.
func (s *backendSuite) updateSnap(c *C, oldSnapInfo *snap.Info, devMode bool, snapYaml string) *snap.Info {
newSnapInfo, err := snap.InfoFromSnapYaml([]byte(snapYaml))
c.Assert(err, IsNil)
c.Assert(newSnapInfo.Name(), Equals, oldSnapInfo.Name())
s.removePlugsSlots(c, oldSnapInfo)
s.addPlugsSlots(c, newSnapInfo)
err = s.backend.Setup(newSnapInfo, devMode, s.repo)
c.Assert(err, IsNil)
return newSnapInfo
}
开发者ID:dholbach,项目名称:snappy,代码行数:11,代码来源:backend_test.go
示例16: removePlugsSlots
func (s *backendSuite) removePlugsSlots(c *C, snapInfo *snap.Info) {
for _, plug := range s.repo.Plugs(snapInfo.Name()) {
err := s.repo.RemovePlug(plug.Snap.Name(), plug.Name)
c.Assert(err, IsNil)
}
for _, slot := range s.repo.Slots(snapInfo.Name()) {
err := s.repo.RemoveSlot(slot.Snap.Name(), slot.Name)
c.Assert(err, IsNil)
}
}
开发者ID:dholbach,项目名称:snappy,代码行数:10,代码来源:backend_test.go
示例17: AddSnap
// AddSnap adds plugs and slots declared by the given snap to the repository.
//
// This function can be used to implement snap install or, when used along with
// RemoveSnap, snap upgrade.
//
// AddSnap doesn't change existing plugs/slots. The caller is responsible for
// ensuring that the snap is not present in the repository in any way prior to
// calling this function. If this constraint is violated then no changes are
// made and an error is returned.
//
// Each added plug/slot is validated according to the corresponding interface.
// Unknown interfaces and plugs/slots that don't validate are not added.
// Information about those failures are returned to the caller.
func (r *Repository) AddSnap(snapInfo *snap.Info) error {
r.m.Lock()
defer r.m.Unlock()
snapName := snapInfo.Name()
if r.plugs[snapName] != nil || r.slots[snapName] != nil {
return fmt.Errorf("cannot register interfaces for snap %q more than once", snapName)
}
bad := BadInterfacesError{
snap: snapName,
issues: make(map[string]string),
}
for plugName, plugInfo := range snapInfo.Plugs {
iface, ok := r.ifaces[plugInfo.Interface]
if !ok {
bad.issues[plugName] = "unknown interface"
continue
}
plug := &Plug{PlugInfo: plugInfo}
if err := iface.SanitizePlug(plug); err != nil {
bad.issues[plugName] = err.Error()
continue
}
if r.plugs[snapName] == nil {
r.plugs[snapName] = make(map[string]*Plug)
}
r.plugs[snapName][plugName] = plug
}
for slotName, slotInfo := range snapInfo.Slots {
iface, ok := r.ifaces[slotInfo.Interface]
if !ok {
bad.issues[slotName] = "unknown interface"
continue
}
slot := &Slot{SlotInfo: slotInfo}
if err := iface.SanitizeSlot(slot); err != nil {
bad.issues[slotName] = err.Error()
continue
}
if r.slots[snapName] == nil {
r.slots[snapName] = make(map[string]*Slot)
}
r.slots[snapName][slotName] = slot
}
if len(bad.issues) > 0 {
return &bad
}
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:67,代码来源:repo.go
示例18: snapDataDirs
// snapDataDirs returns the list of data directories for the given snap version
func snapDataDirs(snap *snap.Info) ([]string, error) {
// collect the directories, homes first
found, err := filepath.Glob(snap.DataHomeDir())
if err != nil {
return nil, err
}
// then system data
found = append(found, snap.DataDir())
return found, nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:12,代码来源:snapdata.go
示例19: removePackageDesktopFiles
func removePackageDesktopFiles(s *snap.Info) error {
glob := filepath.Join(dirs.SnapDesktopFilesDir, s.Name()+"_*.desktop")
activeDesktopFiles, err := filepath.Glob(glob)
if err != nil {
return fmt.Errorf("cannot get desktop files for %v: %s", glob, err)
}
for _, f := range activeDesktopFiles {
os.Remove(f)
}
return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:12,代码来源:desktop.go
示例20: CopyData
func CopyData(newSnap, oldSnap *snap.Info, flags InstallFlags, meter progress.Meter) error {
dataDir := newSnap.DataDir()
// deal with the old data or
// otherwise just create a empty data dir
if oldSnap == nil {
return os.MkdirAll(dataDir, 0755)
}
return copySnapData(oldSnap, newSnap)
}
开发者ID:dholbach,项目名称:snappy,代码行数:12,代码来源:overlord.go
注:本文中的github.com/ubuntu-core/snappy/snap.Info类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论