当前位置: 首页>>代码示例>>Golang>>正文


Golang helpers.FileExists函数代码示例

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


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


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