• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang osutil.FileExists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ubuntu-core/snappy/osutil.FileExists函数的典型用法代码示例。如果您正苦于以下问题:Golang FileExists函数的具体用法?Golang FileExists怎么用?Golang FileExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了FileExists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:34,代码来源:overlord_test.go


示例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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:26,代码来源:overlord_test.go


示例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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:14,代码来源:gadget_test.go


示例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
}
开发者ID:dholbach,项目名称:snappy,代码行数:29,代码来源:firstboot.go


示例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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:29,代码来源:desktop_test.go


示例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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:7,代码来源:database_test.go


示例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
}
开发者ID:dholbach,项目名称:snappy,代码行数:27,代码来源:overlord.go


示例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
}
开发者ID:dholbach,项目名称:snappy,代码行数:26,代码来源:provisioning.go


示例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"},
	})
}
开发者ID:dholbach,项目名称:snappy,代码行数:31,代码来源:snapp_snapfs_test.go


示例10: newUboot

// newUboot create a new Uboot bootloader object
func newUboot() Bootloader {
	u := &uboot{}
	if !osutil.FileExists(u.envFile()) {
		return nil
	}

	return u
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:uboot.go


示例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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:create_test.go


示例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"
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:info.go


示例13: newGrub

// newGrub create a new Grub bootloader object
func newGrub() Bootloader {
	g := &grub{}
	if !osutil.FileExists(g.configFile()) {
		return nil
	}

	return g
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:grub.go


示例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)
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:snapp_test.go


示例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
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:assertmgr.go


示例16: TestWriteHardwareUdevCleanup

func (s *SnapTestSuite) TestWriteHardwareUdevCleanup(c *C) {
	info, err := snap.InfoFromSnapYaml(hardwareYaml)
	c.Assert(err, IsNil)

	dirs.SnapUdevRulesDir = c.MkDir()
	udevRulesFile := filepath.Join(dirs.SnapUdevRulesDir, "80-snappy_gadget-foo_device-hive-iot-hal.rules")
	c.Assert(ioutil.WriteFile(udevRulesFile, nil, 0644), Equals, nil)
	cleanupGadgetHardwareUdevRules(info)

	c.Assert(osutil.FileExists(udevRulesFile), Equals, false)
}
开发者ID:dholbach,项目名称:snappy,代码行数:11,代码来源:snapp_test.go


示例17: TestRemoveViaSquashfsWorks

func (s *SquashfsTestSuite) TestRemoveViaSquashfsWorks(c *C) {
	snapPath := makeTestSnapPackage(c, packageHello)
	si := &snap.SideInfo{
		OfficialName: "hello-snap",
		Revision:     16,
	}
	snap, err := (&Overlord{}).InstallWithSideInfo(snapPath, si, 0, &MockProgressMeter{})
	c.Assert(err, IsNil)
	installedSnap, err := NewInstalledSnap(filepath.Join(snap.MountDir(), "meta", "snap.yaml"))
	c.Assert(err, IsNil)

	// after install the blob is in the right dir
	c.Assert(osutil.FileExists(filepath.Join(dirs.SnapBlobDir, "hello-snap_16.snap")), Equals, true)

	// now remove and ensure its gone
	err = (&Overlord{}).Uninstall(installedSnap, &MockProgressMeter{})
	c.Assert(err, IsNil)
	c.Assert(osutil.FileExists(filepath.Join(dirs.SnapBlobDir, "hello-snap_16.snap")), Equals, false)

}
开发者ID:dholbach,项目名称:snappy,代码行数:20,代码来源:snapp_snapfs_test.go


示例18: parseSnapYamlFile

func parseSnapYamlFile(yamlPath string) (*snapYaml, error) {

	yamlData, err := ioutil.ReadFile(yamlPath)
	if err != nil {
		return nil, err
	}

	// legacy support sucks :-/
	hasConfig := osutil.FileExists(filepath.Join(filepath.Dir(yamlPath), "hooks", "config"))

	return parseSnapYamlData(yamlData, hasConfig)
}
开发者ID:dholbach,项目名称:snappy,代码行数:12,代码来源:snap_yaml.go


示例19: loadState

func loadState(backend state.Backend) (*state.State, error) {
	if !osutil.FileExists(dirs.SnapStateFile) {
		return state.New(backend), nil
	}

	r, err := os.Open(dirs.SnapStateFile)
	if err != nil {
		return nil, fmt.Errorf("failed to read the state file: %s", err)
	}
	defer r.Close()

	return state.ReadState(backend, r)
}
开发者ID:dholbach,项目名称:snappy,代码行数:13,代码来源:overlord.go


示例20: TestAddPackageDesktopFiles

func (s *SnapTestSuite) TestAddPackageDesktopFiles(c *C) {
	expectedDesktopFilePath := filepath.Join(dirs.SnapDesktopFilesDir, "foo_foobar.desktop")
	c.Assert(osutil.FileExists(expectedDesktopFilePath), Equals, false)

	yamlFile, err := makeInstalledMockSnap(desktopAppYaml, 11)
	c.Assert(err, IsNil)

	snap, err := NewInstalledSnap(yamlFile)
	c.Assert(err, IsNil)

	// generate .desktop file in the package baseDir
	baseDir := snap.Info().MountDir()
	err = os.MkdirAll(filepath.Join(baseDir, "meta", "gui"), 0755)
	c.Assert(err, IsNil)

	err = ioutil.WriteFile(filepath.Join(baseDir, "meta", "gui", "foobar.desktop"), mockDesktopFile, 0644)
	c.Assert(err, IsNil)

	err = addPackageDesktopFiles(snap.Info())
	c.Assert(err, IsNil)
	c.Assert(osutil.FileExists(expectedDesktopFilePath), Equals, true)
}
开发者ID:dholbach,项目名称:snappy,代码行数:22,代码来源:desktop_test.go



注:本文中的github.com/ubuntu-core/snappy/osutil.FileExists函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang snapstate.SnapState类代码示例发布时间:2022-05-28
下一篇:
Golang logger.Panicf函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap