本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system.FileSystem.RemoveAll方法的典型用法代码示例。如果您正苦于以下问题:Golang FileSystem.RemoveAll方法的具体用法?Golang FileSystem.RemoveAll怎么用?Golang FileSystem.RemoveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-utils/system.FileSystem
的用法示例。
在下文中一共展示了FileSystem.RemoveAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteFiles
func deleteFiles(fs boshsys.FileSystem, path string, filenamePrefix string) (int, error) {
var deletedFilesCount int
files, err := fs.Glob(fmt.Sprintf("%s%s*", path, filenamePrefix))
if err != nil {
return deletedFilesCount, bosherr.WrapError(err, "Glob command failed")
}
for _, file := range files {
err = fs.RemoveAll(file)
if err != nil {
return deletedFilesCount, bosherr.WrapErrorf(err, "deleting %s failed", file)
}
deletedFilesCount++
}
return deletedFilesCount, err
}
示例2:
toWrite = bytes.NewReader([]byte("new data"))
})
readFile := func(fileIO boshsys.File) []byte {
fileStat, _ := fileIO.Stat()
fileBytes := make([]byte, fileStat.Size())
fileIO.Read(fileBytes)
return fileBytes
}
It("fetches", func() {
blobManager := NewBlobManager(fs, basePath)
fs.WriteFileString(blobPath, "some data")
readOnlyFile, err, _ := blobManager.Fetch(blobId)
defer fs.RemoveAll(readOnlyFile.Name())
Expect(err).ToNot(HaveOccurred())
fileBytes := readFile(readOnlyFile)
Expect(string(fileBytes)).To(Equal("some data"))
})
It("writes", func() {
blobManager := NewBlobManager(fs, basePath)
fs.WriteFileString(blobPath, "some data")
defer fs.RemoveAll(blobPath)
err := blobManager.Write(blobId, toWrite)
Expect(err).ToNot(HaveOccurred())
示例3:
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
cmdRunner = boshsys.NewExecCmdRunner(logger)
fs = boshsys.NewOsFileSystem(logger)
tmpDir, err := fs.TempDir("tarballCompressor-test")
Expect(err).NotTo(HaveOccurred())
dstDir = filepath.Join(tmpDir, "TestCompressor")
compressor = NewTarballCompressor(cmdRunner, fs)
})
BeforeEach(func() {
fs.MkdirAll(dstDir, os.ModePerm)
})
AfterEach(func() {
fs.RemoveAll(dstDir)
})
Describe("CompressFilesInDir", func() {
It("compresses the files in the given directory", func() {
srcDir := fixtureSrcDir()
symlinkPath, err := createTestSymlink()
Expect(err).To(Succeed())
defer os.Remove(symlinkPath)
tgzName, err := compressor.CompressFilesInDir(srcDir)
Expect(err).ToNot(HaveOccurred())
defer os.Remove(tgzName)
tarballContents, _, _, err := cmdRunner.RunCommand("tar", "-tf", tgzName)
示例4:
AddJob := func(jobName string) (WindowsProcessConfig, error) {
conf, ok := testWindowsConfigs(jobName)
if !ok {
return conf, fmt.Errorf("Invalid Windows Config Process name: %s", jobName)
}
confPath, err := WriteJobConfig(conf)
if err != nil {
return conf, err
}
return conf, jobSupervisor.AddJob(jobName, 0, confPath)
}
AfterEach(func() {
Expect(jobSupervisor.Stop()).To(Succeed())
Expect(jobSupervisor.RemoveAllJobs()).To(Succeed())
Expect(fs.RemoveAll(jobDir)).To(Succeed())
Expect(fs.RemoveAll(logDir)).To(Succeed())
})
Describe("Processes", func() {
It("list the process under vcap description", func() {
conf, err := AddJob("say-hello")
names := make(map[string]bool)
for _, p := range conf.Processes {
names[p.Name] = true
}
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Start()).To(Succeed())
示例5:
Expect(err).ToNot(HaveOccurred())
renderedJob1 := NewRenderedJob(bireljob.Job{Name: "fake-job-name-1"}, renderedJobDir1, fs, logger)
defer func() { err := renderedJob1.Delete(); Expect(err).ToNot(HaveOccurred()) }()
err = fs.WriteFileString(filepath.Join(renderedJobDir1, "script-0"), "fake-rendered-job-1-script-0-content")
Expect(err).ToNot(HaveOccurred())
renderedJobList.Add(renderedJob1)
// compress
archive, err := renderedJobListCompressor.Compress(renderedJobList)
Expect(err).ToNot(HaveOccurred())
defer func() { err := archive.Delete(); Expect(err).ToNot(HaveOccurred()) }()
// decompress
renderedJobListDir, err := fs.TempDir("RenderedJobListCompressorTest")
Expect(err).ToNot(HaveOccurred())
defer func() { err := fs.RemoveAll(renderedJobListDir); Expect(err).ToNot(HaveOccurred()) }()
err = compressor.DecompressFileToDir(archive.Path(), renderedJobListDir, boshcmd.CompressorOptions{})
Expect(err).ToNot(HaveOccurred())
// verify that archive contained rendered scripts from job 0
content, err := fs.ReadFileString(filepath.Join(renderedJobListDir, "fake-job-name-0", "script-0"))
Expect(err).ToNot(HaveOccurred())
Expect(content).To(Equal("fake-rendered-job-0-script-0-content"))
content, err = fs.ReadFileString(filepath.Join(renderedJobListDir, "fake-job-name-0", "script-1"))
Expect(err).ToNot(HaveOccurred())
Expect(content).To(Equal("fake-rendered-job-0-script-1-content"))
// verify that archive contained rendered scripts from job 1
content, err = fs.ReadFileString(filepath.Join(renderedJobListDir, "fake-job-name-1", "script-0"))
Expect(err).ToNot(HaveOccurred())
Expect(content).To(Equal("fake-rendered-job-1-script-0-content"))
示例6:
Expect(err).NotTo(HaveOccurred())
Expect(runStartResponse["value"]).To(Equal("started"))
agentState := natsClient.GetState()
Expect(agentState.JobState).To(Equal("running"))
})
It("can run a drain script", func() {
natsClient.PrepareJob("say-hello")
err := natsClient.RunDrain()
Expect(err).NotTo(HaveOccurred())
logsDir, err := fs.TempDir("windows-agent-drain-test")
Expect(err).NotTo(HaveOccurred())
defer fs.RemoveAll(logsDir)
natsClient.FetchLogs(logsDir)
drainLogContents, err := fs.ReadFileString(filepath.Join(logsDir, "say-hello", "drain.log"))
Expect(err).NotTo(HaveOccurred())
Expect(drainLogContents).To(ContainSubstring("Hello from drain"))
})
It("can unmonitor the job during drain script", func() {
natsClient.PrepareJob("unmonitor-hello")
runStartResponse, err := natsClient.RunStart()
Expect(err).NotTo(HaveOccurred())
Expect(runStartResponse["value"]).To(Equal("started"))
示例7:
index FileIndex
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs = boshsys.NewOsFileSystem(logger)
file, err := fs.TempFile("file-index")
Expect(err).ToNot(HaveOccurred())
indexFilePath = file.Name()
err = file.Close()
Expect(err).ToNot(HaveOccurred())
err = fs.RemoveAll(indexFilePath)
Expect(err).ToNot(HaveOccurred())
index = NewFileIndex(indexFilePath, fs)
})
AfterEach(func() {
err := fs.RemoveAll(indexFilePath)
Expect(err).ToNot(HaveOccurred())
})
Describe("Save/Find", func() {
It("returns true if item is found by key", func() {
k1 := Key{Key: "key-1"}
v1 := Value{Name: "value-1", Count: 1}
err := index.Save(k1, v1)