本文整理匯總了Golang中bosh/system.NewOsFileSystem函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewOsFileSystem函數的具體用法?Golang NewOsFileSystem怎麽用?Golang NewOsFileSystem使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewOsFileSystem函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewProvider
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger, runner)
sigarCollector := boshstats.NewSigarStatsCollector()
linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs)
udev := boshudev.NewConcreteUdevDevice(runner)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs)
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
centosNetManager := boshnet.NewCentosNetManager(fs, runner, 10*time.Second)
ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, 10*time.Second)
centos := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
centosNetManager,
500*time.Millisecond,
logger,
)
ubuntu := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
ubuntuNetManager,
500*time.Millisecond,
logger,
)
p.platforms = map[string]Platform{
"ubuntu": ubuntu,
"centos": centos,
"dummy": NewDummyPlatform(sigarCollector, fs, runner, dirProvider, linuxDiskManager),
}
return
}
示例2: basicDeps
func basicDeps() (boshlog.Logger, boshsys.FileSystem, boshsys.CmdRunner, boshuuid.Generator) {
logger := boshlog.NewWriterLogger(boshlog.LevelDebug, os.Stderr, os.Stderr)
fs := boshsys.NewOsFileSystem(logger)
runner := boshsys.NewExecCmdRunner(logger)
uuidGen := boshuuid.NewGenerator()
return logger, fs, runner, uuidGen
}
示例3: NewProvider
// There is a reason the runner is not injected.
// Other entities should not use a runner, they should go through the platform
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger, runner)
sigarStatsCollector := boshstats.NewSigarStatsCollector()
ubuntuDiskManager := boshdisk.NewUbuntuDiskManager(logger, runner, fs)
compressor := boshcmd.NewTarballCompressor(runner, fs)
p.platforms = map[string]Platform{
"ubuntu": newUbuntuPlatform(sigarStatsCollector, fs, runner, ubuntuDiskManager, compressor, dirProvider),
"dummy": newDummyPlatform(),
}
return
}
示例4: TestDecompressFileToDirReturnsError
func TestDecompressFileToDirReturnsError(t *testing.T) {
nonExistentDstDir := filepath.Join(os.TempDir(), "TestDecompressFileToDirReturnsError")
cmdRunner := boshsys.NewExecCmdRunner()
fs := boshsys.NewOsFileSystem()
dc := NewCompressor(cmdRunner, fs)
// propagates errors raised when untarring
err := dc.DecompressFileToDir(fixtureSrcTgz(t), nonExistentDstDir)
assert.Error(t, err)
// path is in the error message
assert.Contains(t, err.Error(), nonExistentDstDir)
}
示例5: NewProvider
// There is a reason the runner is not injected.
// Other entities should not use a runner, they should go through the platform
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger, runner)
sigarStatsCollector := boshstats.NewSigarStatsCollector()
ubuntuDiskManager := boshdisk.NewUbuntuDiskManager(logger, runner, fs)
centosDiskManager := boshdisk.NewCentosDiskManager(logger, runner, fs)
p.platforms = map[string]Platform{
"ubuntu": NewUbuntuPlatform(sigarStatsCollector, fs, runner, ubuntuDiskManager, dirProvider, 500*time.Millisecond, 10*time.Second, 3*time.Minute),
"centos": NewCentosPlatform(sigarStatsCollector, fs, runner, centosDiskManager, dirProvider, 500*time.Millisecond, 10*time.Second, 3*time.Minute),
"dummy": NewDummyPlatform(sigarStatsCollector, fs, runner, dirProvider),
}
return
}
示例6: NewProvider
func NewProvider() (p provider) {
fs := boshsys.NewOsFileSystem()
// There is a reason the runner is not injected.
// Other entities should not use a runner, they should go through the platform
runner := boshsys.NewExecCmdRunner()
ubuntuDiskManager := boshdisk.NewUbuntuDiskManager(runner, fs)
sigarStatsCollector := boshstats.NewSigarStatsCollector()
p.platforms = map[string]Platform{
"ubuntu": newUbuntuPlatform(sigarStatsCollector, fs, runner, ubuntuDiskManager),
"dummy": newDummyPlatform(),
}
return
}
示例7: TestCompressFilesInDir
func TestCompressFilesInDir(t *testing.T) {
fakeStats, _, _, fakeDiskManager := getUbuntuDependencies()
osFs := boshsys.NewOsFileSystem()
execCmdRunner := boshsys.NewExecCmdRunner()
tmpDir := filepath.Join(os.TempDir(), "TestCompressFilesInDir")
err := osFs.MkdirAll(tmpDir, os.ModePerm)
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)
ubuntu := newUbuntuPlatform(fakeStats, osFs, execCmdRunner, fakeDiskManager)
pwd, err := os.Getwd()
assert.NoError(t, err)
fixturesDir := filepath.Join(pwd, "..", "..", "..", "fixtures", "test_get_files_in_dir")
tgz, err := ubuntu.CompressFilesInDir(fixturesDir, []string{"**/*.stdout.log", "*.stderr.log", "../some.config"})
assert.NoError(t, err)
defer os.Remove(tgz.Name())
_, _, err = execCmdRunner.RunCommand("tar", "xzf", tgz.Name(), "-C", tmpDir)
assert.NoError(t, err)
content, err := osFs.ReadFile(tmpDir + "/app.stdout.log")
assert.NoError(t, err)
assert.Contains(t, content, "this is app stdout")
content, err = osFs.ReadFile(tmpDir + "/app.stderr.log")
assert.NoError(t, err)
assert.Contains(t, content, "this is app stderr")
content, err = osFs.ReadFile(tmpDir + "/other_logs/other_app.stdout.log")
assert.NoError(t, err)
assert.Contains(t, content, "this is other app stdout")
content, err = osFs.ReadFile(tmpDir + "/other_logs/other_app.stderr.log")
assert.Error(t, err)
content, err = osFs.ReadFile(tmpDir + "/../some.config")
assert.Error(t, err)
}
示例8: TestCompressFilesInDir
func TestCompressFilesInDir(t *testing.T) {
cmdRunner := boshsys.NewExecCmdRunner()
fs := boshsys.NewOsFileSystem()
dc := NewCompressor(cmdRunner, fs)
srcDir := fixtureSrcDir(t)
tgz, err := dc.CompressFilesInDir(srcDir, []string{"**/*.stdout.log", "*.stderr.log", "../some.config"})
assert.NoError(t, err)
defer os.Remove(tgz.Name())
dstDir := createdTmpDir(t, fs)
defer os.RemoveAll(dstDir)
_, _, err = cmdRunner.RunCommand("tar", "xzf", tgz.Name(), "-C", dstDir)
assert.NoError(t, err)
// regular files
content, err := fs.ReadFile(dstDir + "/app.stdout.log")
assert.NoError(t, err)
assert.Contains(t, content, "this is app stdout")
content, err = fs.ReadFile(dstDir + "/app.stderr.log")
assert.NoError(t, err)
assert.Contains(t, content, "this is app stderr")
// file in a directory
content, err = fs.ReadFile(dstDir + "/other_logs/other_app.stdout.log")
assert.NoError(t, err)
assert.Contains(t, content, "this is other app stdout")
// file that is not matching filter
content, err = fs.ReadFile(dstDir + "/other_logs/other_app.stderr.log")
assert.Error(t, err)
content, err = fs.ReadFile(dstDir + "/../some.config")
assert.Error(t, err)
}
示例9: TestDecompressFileToDir
func TestDecompressFileToDir(t *testing.T) {
fs := boshsys.NewOsFileSystem()
dstDir := createdTmpDir(t, fs)
defer os.RemoveAll(dstDir)
cmdRunner := boshsys.NewExecCmdRunner()
dc := NewCompressor(cmdRunner, fs)
err := dc.DecompressFileToDir(fixtureSrcTgz(t), dstDir)
assert.NoError(t, err)
// regular files
content, err := fs.ReadFile(dstDir + "/not-nested-file")
assert.NoError(t, err)
assert.Contains(t, content, "not-nested-file")
// nested directory with a file
content, err = fs.ReadFile(dstDir + "/dir/nested-file")
assert.NoError(t, err)
assert.Contains(t, content, "nested-file")
// nested directory with a file inside another directory
content, err = fs.ReadFile(dstDir + "/dir/nested-dir/double-nested-file")
assert.NoError(t, err)
assert.Contains(t, content, "double-nested-file")
// directory without a file (empty)
content, err = fs.ReadFile(dstDir + "/empty-dir")
assert.Error(t, err)
assert.Contains(t, err.Error(), "is a directory")
// nested directory without a file (empty) inside another directory
content, err = fs.ReadFile(dstDir + "/dir/empty-nested-dir")
assert.Error(t, err)
assert.Contains(t, err.Error(), "is a directory")
}
示例10: getCompressorDependencies
func getCompressorDependencies() (boshsys.FileSystem, boshsys.CmdRunner) {
logger := boshlog.NewLogger(boshlog.LEVEL_NONE)
fs := boshsys.NewOsFileSystem(logger)
cmdRunner := boshsys.NewExecCmdRunner(logger)
return fs, cmdRunner
}
示例11: loadConfig
func (app *app) loadConfig(path string) (Config, error) {
// Use one off copy of file system to read configuration file
fs := boshsys.NewOsFileSystem(app.logger)
return LoadConfigFromPath(fs, path)
}
示例12:
type StructValue struct{ Name Name }
type Name struct {
First string
Last string
}
var _ = Describe("FileIndex", func() {
var (
index FileIndex
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs := boshsys.NewOsFileSystem(logger)
file, err := fs.TempFile("file-index")
Expect(err).ToNot(HaveOccurred())
err = fs.RemoveAll(file.Name())
Expect(err).ToNot(HaveOccurred())
index = NewFileIndex(file.Name(), fs)
})
Describe("Save/List", func() {
It("returns list of saved items", func() {
k1 := Key{Key: "key-1"}
v1 := Value{Name: "value-1", Count: 1}
err := index.Save(k1, v1)
示例13: NewProvider
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider, options ProviderOptions) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger)
linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs, options.Linux.BindMountPersistentDisk)
udev := boshudev.NewConcreteUdevDevice(runner)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs, logger)
sigarCollector := boshstats.NewSigarStatsCollector(&sigar.ConcreteSigar{})
// Kick of stats collection as soon as possible
go sigarCollector.StartCollecting(SigarStatsCollectionInterval, nil)
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
routesSearcher := boshnet.NewCmdRoutesSearcher(runner)
ipResolver := boship.NewIPResolver(boship.NetworkInterfaceToAddrsFunc)
defaultNetworkResolver := boshnet.NewDefaultNetworkResolver(routesSearcher, ipResolver)
arping := bosharp.NewArping(runner, fs, logger, ArpIterations, ArpIterationDelay, ArpInterfaceCheckDelay)
centosNetManager := boshnet.NewCentosNetManager(fs, runner, defaultNetworkResolver, ipResolver, arping, logger)
ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, defaultNetworkResolver, ipResolver, arping, logger)
centos := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
centosNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
ubuntu := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
ubuntuNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
p.platforms = map[string]Platform{
"ubuntu": ubuntu,
"centos": centos,
"dummy": NewDummyPlatform(sigarCollector, fs, runner, dirProvider, logger),
}
return
}
示例14: getCopierDependencies
func getCopierDependencies() (boshsys.FileSystem, boshsys.CmdRunner) {
logger := boshlog.NewLogger(boshlog.LevelNone)
cmdRunner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger, cmdRunner)
return fs, cmdRunner
}
示例15: NewProvider
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider, options ProviderOptions) (p provider) {
runner := boshsys.NewExecCmdRunner(logger)
fs := boshsys.NewOsFileSystem(logger)
linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs, options.Linux.BindMountPersistentDisk)
udev := boshudev.NewConcreteUdevDevice(runner)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs, logger)
sigarCollector := boshstats.NewSigarStatsCollector()
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
routesSearcher := boshnet.NewCmdRoutesSearcher(runner)
defaultNetworkResolver := boshnet.NewDefaultNetworkResolver(
routesSearcher,
boshnet.DefaultInterfaceToAddrsFunc,
)
centosNetManager := boshnet.NewCentosNetManager(fs, runner, defaultNetworkResolver, 10*time.Second, logger)
ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, defaultNetworkResolver, 10*time.Second, logger)
centos := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
centosNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
ubuntu := NewLinuxPlatform(
fs,
runner,
sigarCollector,
compressor,
copier,
dirProvider,
vitalsService,
linuxCdutil,
linuxDiskManager,
ubuntuNetManager,
500*time.Millisecond,
options.Linux,
logger,
)
p.platforms = map[string]Platform{
"ubuntu": ubuntu,
"centos": centos,
"dummy": NewDummyPlatform(sigarCollector, fs, runner, dirProvider, linuxDiskManager, logger),
}
return
}