本文整理汇总了Golang中github.com/ubuntu-core/snappy/snap.Info类的典型用法代码示例。如果您正苦于以下问题:Golang Info类的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Info类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例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
}
示例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
}
示例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)
}
}
示例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()
}
示例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
}
示例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
}
示例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]
}
示例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()
}
示例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
}