本文整理汇总了Golang中github.com/ubuntu-core/snappy/osutil.FileExists函数的典型用法代码示例。如果您正苦于以下问题:Golang FileExists函数的具体用法?Golang FileExists怎么用?Golang FileExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FileExists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSnappyHandleServicesOnInstall
func (s *SnapTestSuite) TestSnappyHandleServicesOnInstall(c *C) {
snapYamlContent := `name: foo
apps:
service:
command: bin/hello
daemon: forking
`
si := &snap.SideInfo{
OfficialName: "foo",
Revision: 32,
}
snapPath := makeTestSnapPackage(c, snapYamlContent+"version: 1.0")
// revision will be 0
_, err := (&Overlord{}).InstallWithSideInfo(snapPath, si, AllowUnauthenticated, nil)
c.Assert(err, IsNil)
servicesFile := filepath.Join(dirs.SnapServicesDir, "snap.foo.service.service")
c.Assert(osutil.FileExists(servicesFile), Equals, true)
st, err := os.Stat(servicesFile)
c.Assert(err, IsNil)
// should _not_ be executable
c.Assert(st.Mode().String(), Equals, "-rw-r--r--")
// and that it gets removed on remove
snapDir := filepath.Join(dirs.SnapSnapsDir, "foo", "32")
yamlPath := filepath.Join(snapDir, "meta", "snap.yaml")
snap, err := NewInstalledSnap(yamlPath)
c.Assert(err, IsNil)
err = (&Overlord{}).Uninstall(snap, &MockProgressMeter{})
c.Assert(err, IsNil)
c.Assert(osutil.FileExists(servicesFile), Equals, false)
c.Assert(osutil.FileExists(snapDir), Equals, false)
}
示例2: TestSnappyHandleBinariesOnInstall
func (s *SnapTestSuite) TestSnappyHandleBinariesOnInstall(c *C) {
snapYamlContent := `name: foo
apps:
bar:
command: bin/bar
`
snapPath := makeTestSnapPackage(c, snapYamlContent+"version: 1.0")
// revision will be 0
_, err := (&Overlord{}).Install(snapPath, AllowUnauthenticated, nil)
c.Assert(err, IsNil)
// ensure that the binary wrapper file go generated with the right
// name
binaryWrapper := filepath.Join(dirs.SnapBinariesDir, "foo.bar")
c.Assert(osutil.FileExists(binaryWrapper), Equals, true)
// and that it gets removed on remove
snapDir := filepath.Join(dirs.SnapSnapsDir, "foo", "0")
yamlPath := filepath.Join(snapDir, "meta", "snap.yaml")
snap, err := NewInstalledSnap(yamlPath)
c.Assert(err, IsNil)
err = (&Overlord{}).Uninstall(snap, &MockProgressMeter{})
c.Assert(err, IsNil)
c.Assert(osutil.FileExists(binaryWrapper), Equals, false)
c.Assert(osutil.FileExists(snapDir), Equals, false)
}
示例3: TestCleanupGadgetHardwareRules
func (s *GadgetSuite) TestCleanupGadgetHardwareRules(c *C) {
info, err := snap.InfoFromSnapYaml(hardwareYaml)
c.Assert(err, IsNil)
err = writeApparmorAdditionalFile(info)
c.Assert(err, IsNil)
additionalFile := filepath.Join(dirs.SnapAppArmorDir, "device-hive-iot-hal.json.additional")
c.Assert(osutil.FileExists(additionalFile), Equals, true)
err = cleanupGadgetHardwareUdevRules(info)
c.Assert(err, IsNil)
c.Assert(osutil.FileExists(additionalFile), Equals, false)
}
示例4: populateStateFromInstalled
func populateStateFromInstalled() error {
all, err := (&snappy.Overlord{}).Installed()
if err != nil {
return err
}
if osutil.FileExists(dirs.SnapStateFile) {
return fmt.Errorf("cannot create state: state %q already exists", dirs.SnapStateFile)
}
st := state.New(&overlordStateBackend{
path: dirs.SnapStateFile,
})
st.Lock()
defer st.Unlock()
for _, sn := range all {
// no need to do a snapstate.Get() because this is firstboot
info := sn.Info()
var snapst snapstate.SnapState
snapst.Sequence = append(snapst.Sequence, &info.SideInfo)
snapst.Channel = info.Channel
snapst.Active = sn.IsActive()
snapstate.Set(st, sn.Name(), &snapst)
}
return nil
}
示例5: TestDesktopFileIsAddedAndRemoved
func (s *SnapTestSuite) TestDesktopFileIsAddedAndRemoved(c *C) {
yamlFile, err := makeInstalledMockSnap(string(desktopAppYaml), 11)
c.Assert(err, IsNil)
snap, err := NewInstalledSnap(yamlFile)
c.Assert(err, IsNil)
// create a mock desktop file
err = os.MkdirAll(filepath.Join(filepath.Dir(yamlFile), "gui"), 0755)
c.Assert(err, IsNil)
err = ioutil.WriteFile(filepath.Join(filepath.Dir(yamlFile), "gui", "foobar.desktop"), []byte(mockDesktopFile), 0644)
c.Assert(err, IsNil)
// ensure that activate creates the desktop file
err = ActivateSnap(snap, nil)
c.Assert(err, IsNil)
mockDesktopFilePath := filepath.Join(dirs.SnapDesktopFilesDir, "foo_foobar.desktop")
content, err := ioutil.ReadFile(mockDesktopFilePath)
c.Assert(err, IsNil)
c.Assert(string(content), Equals, `
[Desktop Entry]
Name=foo
Icon=/snap/foo/11/foo.png`)
// unlink (deactivate) removes it again
err = UnlinkSnap(snap.Info(), nil)
c.Assert(err, IsNil)
c.Assert(osutil.FileExists(mockDesktopFilePath), Equals, false)
}
示例6: TestGenerateKey
func (dbs *databaseSuite) TestGenerateKey(c *C) {
fingerp, err := dbs.db.GenerateKey("account0")
c.Assert(err, IsNil)
c.Check(fingerp, NotNil)
keyPath := filepath.Join(dbs.topDir, "private-keys-v0/account0", fingerp)
c.Check(osutil.FileExists(keyPath), Equals, true)
}
示例7: UndoSetupSnap
func UndoSetupSnap(s snap.PlaceInfo, meter progress.Meter) {
// SetupSnap did it not made far enough
if !osutil.FileExists(s.MountDir()) {
return
}
if err := RemoveSnapFiles(s, meter); err != nil {
logger.Noticef("cannot remove snap files: %s", err)
}
mountDir := s.MountDir()
snapPath := s.MountFile()
// remove install dir and the snap blob itself
for _, path := range []string{
mountDir,
snapPath,
} {
if err := os.RemoveAll(path); err != nil {
logger.Noticef("cannot remove snap package at %v: %s", mountDir, err)
}
}
// FIXME: do we need to undo installGadgetHardwareUdevRules via
// cleanupGadgetHardwareUdevRules ? it will go away
// and can only be used during install right now
}
示例8: InDeveloperMode
// InDeveloperMode returns true if the image was build with --developer-mode
func InDeveloperMode() bool {
// FIXME: this is a bit terrible, we really need a single
// bootloader dir like /boot or /boot/loader
// instead of having to query the partition code
bootloader, err := findBootloader()
if err != nil {
// can only happy on systems like ubuntu classic
// that are not full snappy systems
return false
}
file := filepath.Join(bootloader.Dir(), InstallYamlFile)
if !osutil.FileExists(file) {
// no idea
return false
}
InstallYaml, err := parseInstallYaml(file)
if err != nil {
// no idea
return false
}
return InstallYaml.InstallOptions.DeveloperMode
}
示例9: TestInstallFailUnmountsSnap
func (s *SquashfsTestSuite) TestInstallFailUnmountsSnap(c *C) {
c.Skip("no easy path to this kind of late verification failure now!")
snapPkg := makeTestSnapPackage(c, `name: hello
version: 1.10
apps:
some-binary:
command: some-binary
plugs: [some-binary]
plugs:
some-binary:
interface: old-security
security-template: not-there
`)
// install but our missing security-template will break the install
// revision will be 0
_, err := (&Overlord{}).Install(snapPkg, 0, &MockProgressMeter{})
c.Assert(err, ErrorMatches, "could not find specified template: not-there.*")
// ensure the mount unit is not there
mup := systemd.MountUnitPath("/snap/hello/1.10", "mount")
c.Assert(osutil.FileExists(mup), Equals, false)
// ensure that the mount gets unmounted and stopped
c.Assert(s.systemdCmds, DeepEquals, [][]string{
{"start", "snap-hello-0.mount"},
{"--root", dirs.GlobalRootDir, "disable", "snap-hello-0.mount"},
{"stop", "snap-hello-0.mount"},
{"show", "--property=ActiveState", "snap-hello-0.mount"},
})
}
示例10: newUboot
// newUboot create a new Uboot bootloader object
func newUboot() Bootloader {
u := &uboot{}
if !osutil.FileExists(u.envFile()) {
return nil
}
return u
}
示例11: TestCreateFailDestroys
func (t *CreateTestSuite) TestCreateFailDestroys(c *C) {
t.makeMockLxdServer(c)
t.imageReader = strings.NewReader("its all broken")
err := Create(&progress.NullProgress{})
c.Assert(err, ErrorMatches, `(?m)failed to unpack .*`)
c.Assert(osutil.FileExists(dirs.ClassicDir), Equals, false)
}
示例12: Release
// Release returns the release of the current snappy image
func Release(c *check.C) string {
// FIXME: use `snap info` once it is available again
if osutil.FileExists(snappyCmd) {
return "15.04"
}
return "rolling"
}
示例13: newGrub
// newGrub create a new Grub bootloader object
func newGrub() Bootloader {
g := &grub{}
if !osutil.FileExists(g.configFile()) {
return nil
}
return g
}
示例14: TestWriteHardwareUdevEtc
func (s *SnapTestSuite) TestWriteHardwareUdevEtc(c *C) {
info, err := snap.InfoFromSnapYaml(hardwareYaml)
c.Assert(err, IsNil)
dirs.SnapUdevRulesDir = c.MkDir()
writeGadgetHardwareUdevRules(info)
c.Assert(osutil.FileExists(filepath.Join(dirs.SnapUdevRulesDir, "80-snappy_gadget-foo_device-hive-iot-hal.rules")), Equals, true)
}
示例15: getTrustedAccountKey
func getTrustedAccountKey() string {
if !osutil.FileExists(dirs.SnapTrustedAccountKey) {
// XXX: allow this fallback here for integration tests,
// until we have a proper trusted public key shared
// with the store and decide possibly for a different strategy
return os.Getenv("SNAPPY_TRUSTED_ACCOUNT_KEY")
}
return dirs.SnapTrustedAccountKey
}