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

Golang helpers.FileExists函数代码示例

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

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



在下文中一共展示了FileExists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: setupSnappyDependentServices

func (s *SnapTestSuite) setupSnappyDependentServices(c *C) (string, *MockProgressMeter) {
	inter := &MockProgressMeter{}
	fmkYaml := `name: fmk
version: 1.0
type: framework
version: `
	fmkFile := makeTestSnapPackage(c, fmkYaml+"1")
	_, err := installClick(fmkFile, AllowUnauthenticated, inter, "")
	c.Assert(err, IsNil)

	packageYaml := `name: foo
icon: foo.svg
frameworks:
 - fmk
services:
 - name: svc1
   start: bin/hello
 - name: svc2
   start: bin/bye
version: `
	snapFile := makeTestSnapPackage(c, packageYaml+"1.0")
	_, err = installClick(snapFile, AllowUnauthenticated, inter, testOrigin)
	c.Assert(err, IsNil)

	c.Assert(helpers.FileExists(filepath.Join(dirs.SnapServicesDir, "foo_svc1_1.0.service")), Equals, true)
	c.Assert(helpers.FileExists(filepath.Join(dirs.SnapServicesDir, "foo_svc2_1.0.service")), Equals, true)

	return fmkYaml, inter
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:29,代码来源:click_test.go


示例2: TestFileLock

func (ts *FileLockTestSuite) TestFileLock(c *C) {
	lockfile := filepath.Join(c.MkDir(), "lock")

	c.Assert(helpers.FileExists(lockfile), Equals, false)

	lock := NewFileLock(lockfile)
	c.Assert(lock, Not(IsNil))
	c.Assert(lock.Filename, Equals, lockfile)
	c.Assert(lock.realFile, IsNil)

	err := lock.Unlock()
	c.Assert(err, Equals, ErrNotLocked)

	// can only test non-blocking in a single process.
	err = lock.Lock(false)
	c.Assert(err, IsNil)

	c.Assert(helpers.FileExists(lockfile), Equals, true)
	c.Assert(lock.Filename, Equals, lockfile)
	c.Assert(lock.realFile, Not(IsNil))

	err = lock.Lock(false)
	c.Assert(err, Equals, ErrAlreadyLocked)

	err = lock.Unlock()
	c.Assert(err, IsNil)

	c.Assert(helpers.FileExists(lockfile), Equals, false)
	c.Assert(lock.Filename, Equals, "")
	c.Assert(lock.realFile, IsNil)
}
开发者ID:pombredanne,项目名称:snappy-1,代码行数:31,代码来源:filelock_test.go


示例3: TestSnappyHandleServicesOnInstall

func (s *SnapTestSuite) TestSnappyHandleServicesOnInstall(c *C) {
	packageYaml := `name: foo
icon: foo.svg
services:
 - name: service
   start: bin/hello
`
	snapFile := makeTestSnapPackage(c, packageYaml+"version: 1.0")
	_, err := installClick(snapFile, AllowUnauthenticated, nil, "mvo")
	c.Assert(err, IsNil)

	servicesFile := filepath.Join(dirs.SnapServicesDir, "foo_service_1.0.service")
	c.Assert(helpers.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.mvo", "1.0")
	yamlPath := filepath.Join(snapDir, "meta", "package.yaml")
	part, err := NewInstalledSnapPart(yamlPath, testOrigin)
	c.Assert(err, IsNil)
	err = part.remove(&progress.NullProgress{})
	c.Assert(err, IsNil)
	c.Assert(helpers.FileExists(servicesFile), Equals, false)
	c.Assert(helpers.FileExists(snapDir), Equals, false)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:28,代码来源:click_test.go


示例4: TestRemoveHWAccess

func (s *SnapTestSuite) TestRemoveHWAccess(c *C) {
	makeInstalledMockSnap(s.tempdir, "")
	err := AddHWAccess("hello-app", "/dev/ttyUSB0")

	// check that the udev rules file got created
	udevRulesFilename := "70-snappy_hwassign_hello-app.rules"
	c.Assert(helpers.FileExists(filepath.Join(dirs.SnapUdevRulesDir, udevRulesFilename)), Equals, true)

	writePaths, err := ListHWAccess("hello-app")
	c.Assert(err, IsNil)
	c.Assert(writePaths, DeepEquals, []string{"/dev/ttyUSB0"})

	regenerateAppArmorRulesWasCalled := mockRegenerateAppArmorRules()
	err = RemoveHWAccess("hello-app", "/dev/ttyUSB0")
	c.Assert(err, IsNil)
	c.Assert(*regenerateAppArmorRulesWasCalled, Equals, true)

	writePaths, err = ListHWAccess("hello-app")
	c.Assert(err, IsNil)
	c.Assert(writePaths, HasLen, 0)

	// check that the udev rules file got removed on unassign
	c.Assert(helpers.FileExists(filepath.Join(dirs.SnapUdevRulesDir, udevRulesFilename)), Equals, false)

	// check the json.additional got cleaned out
	content, err := ioutil.ReadFile(filepath.Join(dirs.SnapAppArmorAdditionalDir, "hello-app.hwaccess.yaml"))
	c.Assert(err, IsNil)
	c.Assert(string(content), Equals, "{}\n")
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:29,代码来源:hwaccess_test.go


示例5: TestHandleAssets

func (s *PartitionTestSuite) TestHandleAssets(c *C) {
	s.makeFakeUbootEnv(c)
	p := New()
	bootloader, err := bootloader(p)
	c.Assert(err, IsNil)

	// mock the hardwareYaml and the cacheDir
	hardwareSpecFile = makeHardwareYaml(c, "")
	cacheDir = c.MkDir()

	// create mock assets/
	makeMockAssetsDir(c)

	// run the handle assets code
	err = bootloader.HandleAssets()
	c.Assert(err, IsNil)

	// ensure the files are where we expect them
	otherBootPath := bootloader.(*uboot).otherBootPath
	for _, f := range []string{"vmlinuz", "initrd.img", "dtbs/foo.dtb", "dtbs/bar.dtb"} {
		content, err := ioutil.ReadFile(filepath.Join(otherBootPath, f))
		c.Assert(err, IsNil)
		// match content
		c.Assert(strings.HasSuffix(string(content), f), Equals, true)
	}

	// ensure nothing left behind
	c.Assert(helpers.FileExists(filepath.Join(cacheDir, "assets")), Equals, false)
	c.Assert(helpers.FileExists(hardwareSpecFile), Equals, false)
}
开发者ID:pombredanne,项目名称:snappy-1,代码行数:30,代码来源:bootloader_uboot_test.go


示例6: TestPurgeMultiContinuesOnFail

func (s *purgeSuite) TestPurgeMultiContinuesOnFail(c *C) {
	inter := &MockProgressMeter{}
	ddirs0, _ := s.mkpkg(c, "v0")
	ddirs1, _ := s.mkpkg(c, "v1")
	ddirs2, _ := s.mkpkg(c, "v2")

	count := 0
	anError := errors.New("fail")
	remove = func(n, v string) error {
		count++

		// Fail to remove v1
		if v == "v1" {
			return anError
		}
		return removeSnapData(n, v)
	}
	defer func() { remove = removeSnapData }()

	err := Purge("hello-app", 0, inter)
	c.Check(err, Equals, anError)
	c.Check(count, Equals, 6)
	for _, ddir := range ddirs0 {
		c.Check(helpers.FileExists(ddir), Equals, false)
	}
	for _, ddir := range ddirs1 {
		c.Check(helpers.FileExists(ddir), Equals, true)
	}
	for _, ddir := range ddirs2 {
		c.Check(helpers.FileExists(ddir), Equals, false)
	}
	c.Assert(inter.notified, HasLen, 2)
	c.Check(inter.notified[0], Matches, `unable to purge.*fail`)
	c.Check(inter.notified[1], Matches, `unable to purge.*fail`)
}
开发者ID:alecu,项目名称:snappy,代码行数:35,代码来源:purge_test.go


示例7: TestPurgeMultiContinuesOnFail

func (s *purgeSuite) TestPurgeMultiContinuesOnFail(c *C) {
	inter := &MockProgressMeter{}
	ddir0, _ := s.mkpkg(c, "v0")
	ddir1, _ := s.mkpkg(c, "v1")
	ddir2, _ := s.mkpkg(c, "v2")

	count := 0
	anError := errors.New("fail")
	remove = func(n, v string) error {
		count++
		if count == 2 {
			return anError
		}
		return removeSnapData(n, v)
	}
	defer func() { remove = removeSnapData }()

	err := Purge("hello-app", 0, inter)
	c.Check(err, Equals, anError)
	c.Check(count, Equals, 3)
	c.Check(helpers.FileExists(ddir0), Equals, false)
	c.Check(helpers.FileExists(ddir1), Equals, true)
	c.Check(helpers.FileExists(ddir2), Equals, false)
	c.Assert(inter.notified, HasLen, 1)
	c.Check(inter.notified[0], Matches, `unable to purge.*fail`)
}
开发者ID:General-Beck,项目名称:snappy,代码行数:26,代码来源:purge_test.go


示例8: TestSnappyHandleServicesOnInstall

func (s *SnapTestSuite) TestSnappyHandleServicesOnInstall(c *C) {
	snapYamlContent := `name: foo
apps:
 service:
   command: bin/hello
   daemon: forking
`
	snapFile := makeTestSnapPackage(c, snapYamlContent+"version: 1.0")
	_, err := installClick(snapFile, AllowUnauthenticated, nil, "mvo")
	c.Assert(err, IsNil)

	servicesFile := filepath.Join(dirs.SnapServicesDir, "foo_service_1.0.service")
	c.Assert(helpers.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.mvo", "1.0")
	yamlPath := filepath.Join(snapDir, "meta", "snap.yaml")
	part, err := NewInstalledSnapPart(yamlPath, testOrigin)
	c.Assert(err, IsNil)
	err = (&Overlord{}).Uninstall(part, &MockProgressMeter{})
	c.Assert(err, IsNil)
	c.Assert(helpers.FileExists(servicesFile), Equals, false)
	c.Assert(helpers.FileExists(snapDir), Equals, false)
}
开发者ID:alecu,项目名称:snappy,代码行数:28,代码来源:click_test.go


示例9: TestSnappyHandleBinariesOnInstall

func (s *SnapTestSuite) TestSnappyHandleBinariesOnInstall(c *C) {
	packageYaml := `name: foo
icon: foo.svg
binaries:
 - name: bin/bar
`
	snapFile := makeTestSnapPackage(c, packageYaml+"version: 1.0")
	_, err := installClick(snapFile, AllowUnauthenticated, nil, "mvo")
	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(helpers.FileExists(binaryWrapper), Equals, true)

	// and that it gets removed on remove
	snapDir := filepath.Join(dirs.SnapSnapsDir, "foo.mvo", "1.0")
	yamlPath := filepath.Join(snapDir, "meta", "package.yaml")
	part, err := NewInstalledSnapPart(yamlPath, testOrigin)
	c.Assert(err, IsNil)
	err = part.remove(&MockProgressMeter{})
	c.Assert(err, IsNil)
	c.Assert(helpers.FileExists(binaryWrapper), Equals, false)
	c.Assert(helpers.FileExists(snapDir), Equals, false)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:25,代码来源:click_test.go


示例10: BootloaderDir

// BootloaderDir returns the full path to the (mounted and writable)
// bootloader-specific boot directory.
func BootloaderDir() string {
	if helpers.FileExists(bootloaderUbootDir()) {
		return bootloaderUbootDir()
	} else if helpers.FileExists(bootloaderGrubDir()) {
		return bootloaderGrubDir()
	}

	return ""
}
开发者ID:General-Beck,项目名称:snappy,代码行数:11,代码来源:bootloader_public.go


示例11: TestPurgeMultiOK

func (s *purgeSuite) TestPurgeMultiOK(c *C) {
	inter := &MockProgressMeter{}
	ddir0, _ := s.mkpkg(c, "v0")
	ddir1, _ := s.mkpkg(c, "v1")

	err := Purge("hello-app", 0, inter)
	c.Check(err, IsNil)
	c.Check(helpers.FileExists(ddir0), Equals, false)
	c.Check(helpers.FileExists(ddir1), Equals, false)
	c.Check(inter.notified, HasLen, 0)
}
开发者ID:General-Beck,项目名称:snappy,代码行数:11,代码来源:purge_test.go


示例12: TestUnpackMeta

func (s *SquashfsTestSuite) TestUnpackMeta(c *C) {
	snap := makeSnap(c, "", "random-data")

	outputDir := c.MkDir()
	err := snap.UnpackMeta(outputDir)
	c.Assert(err, IsNil)

	// we got the meta/ stuff
	c.Assert(helpers.FileExists(filepath.Join(outputDir, "meta/package.yaml")), Equals, true)
	// ... but not the data
	c.Assert(helpers.FileExists(filepath.Join(outputDir, "data.bin")), Equals, false)
}
开发者ID:pombredanne,项目名称:snappy-1,代码行数:12,代码来源:pkg_test.go


示例13: TestPurgeRemovedWorks

func (s *purgeSuite) TestPurgeRemovedWorks(c *C) {
	inter := &MockProgressMeter{}
	ddir, part := s.mkpkg(c)

	err := part.remove(inter)
	c.Assert(err, IsNil)
	c.Check(helpers.FileExists(ddir), Equals, true)

	err = Purge("hello-app", 0, inter)
	c.Check(err, IsNil)
	c.Check(helpers.FileExists(ddir), Equals, false)
}
开发者ID:General-Beck,项目名称:snappy,代码行数:12,代码来源:purge_test.go


示例14: TestFileLock

func (ts *FileLockTestSuite) TestFileLock(c *C) {
	path := filepath.Join(c.MkDir(), "lock")

	c.Assert(helpers.FileExists(path), Equals, false)

	lock, err := lockfile.Lock(path, false)
	c.Assert(err, IsNil)
	c.Check(lock > 0, Equals, true)

	c.Assert(helpers.FileExists(path), Equals, true)

	err = lock.Unlock()
	c.Assert(err, IsNil)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:14,代码来源:lockfile_test.go


示例15: TestRemoveAllHWAccess

func (s *SnapTestSuite) TestRemoveAllHWAccess(c *C) {
	makeInstalledMockSnap(s.tempdir, "")

	err := AddHWAccess("hello-app", "/dev/ttyUSB0")
	c.Assert(err, IsNil)

	regenerateAppArmorRulesWasCalled := mockRegenerateAppArmorRules()
	c.Check(*regenerateAppArmorRulesWasCalled, Equals, false)
	c.Check(RemoveAllHWAccess("hello-app"), IsNil)

	c.Check(helpers.FileExists(filepath.Join(dirs.SnapUdevRulesDir, "70-snappy_hwassign_foo-app.rules")), Equals, false)
	c.Check(helpers.FileExists(filepath.Join(dirs.SnapAppArmorAdditionalDir, "hello-app.hwaccess.yaml")), Equals, false)
	c.Check(*regenerateAppArmorRulesWasCalled, Equals, true)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:14,代码来源:hwaccess_test.go


示例16: TestCleanupOemHardwareRules

func (s *OemSuite) TestCleanupOemHardwareRules(c *C) {
	m, err := parsePackageYamlData(hardwareYaml, false)
	c.Assert(err, IsNil)

	err = writeApparmorAdditionalFile(m)
	c.Assert(err, IsNil)

	additionalFile := filepath.Join(dirs.SnapAppArmorDir, "device-hive-iot-hal.json.additional")
	c.Assert(helpers.FileExists(additionalFile), Equals, true)

	err = cleanupOemHardwareUdevRules(m)
	c.Assert(err, IsNil)
	c.Assert(helpers.FileExists(additionalFile), Equals, false)
}
开发者ID:General-Beck,项目名称:snappy,代码行数:14,代码来源:oem_test.go


示例17: TestWriteCompatManifestJSONNoFollow

func (s *SnapTestSuite) TestWriteCompatManifestJSONNoFollow(c *C) {
	manifest := []byte(`{
    "name": "hello-world"
}
`)
	manifestJSON := filepath.Join(s.tempdir, "hello-world.some-origin.manifest")
	symlinkTarget := filepath.Join(s.tempdir, "symlink-target")
	os.Symlink(symlinkTarget, manifestJSON)
	c.Assert(helpers.FileExists(symlinkTarget), Equals, false)

	err := writeCompatManifestJSON(s.tempdir, manifest, "some-origin")
	c.Assert(err, IsNil)
	c.Check(helpers.FileExists(manifestJSON), Equals, true)
	c.Check(helpers.FileExists(symlinkTarget), Equals, false)
}
开发者ID:General-Beck,项目名称:snappy,代码行数:15,代码来源:click_test.go


示例18: Icon

// Icon returns the path to the icon
func (s *SnapPart) Icon() string {
	if helpers.FileExists(iconPath(s)) {
		return iconPath(s)
	}

	return filepath.Join(s.basedir, s.m.Icon)
}
开发者ID:strukturag,项目名称:snappy,代码行数:8,代码来源:snapp.go


示例19: downloadIcon

func (s *RemoteSnapPart) downloadIcon(pbar progress.Meter) error {
	if err := os.MkdirAll(dirs.SnapIconsDir, 0755); err != nil {
		return err
	}

	iconPath := iconPath(s)
	if helpers.FileExists(iconPath) {
		return nil
	}

	req, err := http.NewRequest("GET", s.Icon(), nil)
	if err != nil {
		return err
	}

	w, err := os.OpenFile(iconPath, os.O_WRONLY|os.O_CREATE, 0644)
	if err != nil {
		return err
	}
	defer w.Close()

	if err := download("icon for package", w, req, pbar); err != nil {
		return err
	}

	return w.Sync()
}
开发者ID:strukturag,项目名称:snappy,代码行数:27,代码来源:snapp.go


示例20: remove

func (s *SnapPart) remove(inter interacter) (err error) {
	// TODO[JRL]: check the logic here. I'm not sure “remove
	// everything if active, and the click hooks if not” makes
	// sense. E.g. are we removing fmk bins on fmk upgrade? Etc.
	if err := removeClickHooks(s.m, s.origin, false); err != nil {
		return err
	}

	if err := s.deactivate(false, inter); err != nil && err != ErrSnapNotActive {
		return err
	}

	err = os.RemoveAll(s.basedir)
	if err != nil {
		return err
	}

	// best effort(?)
	os.Remove(filepath.Dir(s.basedir))

	// don't fail if icon can't be removed
	if helpers.FileExists(iconPath(s)) {
		if err := os.Remove(iconPath(s)); err != nil {
			logger.Noticef("Failed to remove store icon %s: %s", iconPath(s), err)
		}
	}

	return nil
}
开发者ID:strukturag,项目名称:snappy,代码行数:29,代码来源:snapp.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang i18n.G函数代码示例发布时间:2022-05-28
下一篇:
Golang helpers.AtomicWriteFile函数代码示例发布时间: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