本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system.FileSystem类的典型用法代码示例。如果您正苦于以下问题:Golang FileSystem类的具体用法?Golang FileSystem怎么用?Golang FileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSystem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: AbsolutifyPath
func AbsolutifyPath(pathToManifest string, pathToFile string, fs boshsys.FileSystem) (string, error) {
if strings.HasPrefix(pathToFile, "http") {
return pathToFile, nil
}
if strings.HasPrefix(pathToFile, "file:///") || strings.HasPrefix(pathToFile, "/") {
return pathToFile, nil
}
if strings.HasPrefix(pathToFile, "file://~") {
return pathToFile, nil
}
if strings.HasPrefix(pathToFile, "~") {
return fs.ExpandPath(pathToFile)
}
var absPath string
if !strings.HasPrefix(pathToFile, "file://") {
absPath = filepath.Join(filepath.Dir(pathToManifest), pathToFile)
} else {
pathToFile = strings.Replace(pathToFile, "file://", "", 1)
absPath = filepath.Join(filepath.Dir(pathToManifest), pathToFile)
absPath = "file://" + absPath
}
return absPath, nil
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:29,代码来源:file_helper.go
示例2: countFiles
func countFiles(fs system.FileSystem, dir string) (count int) {
fs.Walk(dir, func(path string, info os.FileInfo, err error) error {
count++
return nil
})
return
}
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:7,代码来源:cert_manager_test.go
示例3: mustCreateReposDir
func mustCreateReposDir(config Config, fs boshsys.FileSystem, eventLog bpeventlog.Log) {
err := fs.MkdirAll(config.ReposDir, os.ModeDir)
if err != nil {
eventLog.WriteErr(bosherr.WrapError(err, "Creating repos dir"))
os.Exit(1)
}
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:7,代码来源:main.go
示例4: NewConfigFromPath
func NewConfigFromPath(path string, fs boshsys.FileSystem) (Config, error) {
var config Config
bytes, err := fs.ReadFile(path)
if err != nil {
return config, bosherr.WrapErrorf(err, "Reading config %s", path)
}
config = DefaultConfig
err = json.Unmarshal(bytes, &config)
if err != nil {
return config, bosherr.WrapError(err, "Unmarshalling config")
}
if config.VMProvisioner.AgentProvisioner.Configuration == nil {
config.VMProvisioner.AgentProvisioner.Configuration = DefaultAgentConfiguration
}
err = config.validate()
if err != nil {
return config, bosherr.WrapError(err, "Validating config")
}
return config, nil
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:26,代码来源:config.go
示例5: NewManifestFromPath
func NewManifestFromPath(path string, fs boshsys.FileSystem) (Manifest, error) {
bytes, err := fs.ReadFile(path)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Reading manifest %s", path)
}
return NewManifestFromBytes(bytes)
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:8,代码来源:manifest.go
示例6: New
// New returns a new logger (that writes to the specified file) & the open file handle
// All log levels >= the specified level are written to the specified file.
// User is responsible for closing the returned file handle, unless an error is returned.
func New(level boshlog.LogLevel, filePath string, fileMode os.FileMode, fs boshsys.FileSystem) (boshlog.Logger, boshsys.File, error) {
file, err := fs.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, fileMode)
if err != nil {
return nil, file, bosherr.WrapErrorf(err, "Failed to open log file '%s'", filePath)
}
return boshlog.NewWriterLogger(level, file, file), file, nil
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:11,代码来源:file_logger.go
示例7: describeDummyPlatform
func describeDummyPlatform() {
var (
platform Platform
collector boshstats.Collector
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
dirProvider boshdirs.Provider
devicePathResolver boshdpresolv.DevicePathResolver
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/fake-dir")
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
platform = NewDummyPlatform(
collector,
fs,
cmdRunner,
dirProvider,
devicePathResolver,
logger,
)
})
Describe("GetDefaultNetwork", func() {
It("returns the contents of dummy-defaults-network-settings.json since that's what the dummy cpi writes", func() {
settingsFilePath := "/fake-dir/bosh/dummy-default-network-settings.json"
fs.WriteFileString(settingsFilePath, `{"IP": "1.2.3.4"}`)
network, err := platform.GetDefaultNetwork()
Expect(err).NotTo(HaveOccurred())
Expect(network.IP).To(Equal("1.2.3.4"))
})
})
Describe("GetCertManager", func() {
It("returs a dummy cert manager", func() {
certManager := platform.GetCertManager()
Expect(certManager.UpdateCertificates("")).Should(BeNil())
})
})
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:51,代码来源:dummy_platform_test.go
示例8: 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
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:15,代码来源:cert_manager.go
示例9: mustSetTmpDir
func mustSetTmpDir(config Config, fs boshsys.FileSystem, eventLog bpeventlog.Log) {
// todo leaky abstraction?
if len(config.TmpDir) == 0 {
return
}
err := fs.MkdirAll(config.TmpDir, os.ModeDir)
if err != nil {
eventLog.WriteErr(bosherr.WrapError(err, "Creating tmp dir"))
os.Exit(1)
}
err = os.Setenv("TMPDIR", config.TmpDir)
if err != nil {
eventLog.WriteErr(bosherr.WrapError(err, "Setting TMPDIR"))
os.Exit(1)
}
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:18,代码来源:main.go
示例10: LoadConfigFromPath
func LoadConfigFromPath(fs boshsys.FileSystem, path string) (Config, error) {
var config Config
if path == "" {
return config, nil
}
bytes, err := fs.ReadFile(path)
if err != nil {
return config, bosherr.WrapError(err, "Reading file")
}
err = json.Unmarshal(bytes, &config)
if err != nil {
return config, bosherr.WrapError(err, "Loading file")
}
return config, nil
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:19,代码来源:config.go
示例11: NewConfig
func NewConfig(fs boshsys.FileSystem) (*Config, error) {
path := os.Getenv("BOSH_INIT_CONFIG_PATH")
if path == "" {
return &Config{}, errors.New("Must provide config file via BOSH_INIT_CONFIG_PATH environment variable")
}
configContents, err := fs.ReadFile(path)
if err != nil {
return &Config{}, err
}
var config Config
err = json.Unmarshal(configContents, &config)
if err != nil {
return &Config{}, err
}
return &config, nil
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:19,代码来源:config.go
示例12: NewBootstrapState
func NewBootstrapState(fs boshsys.FileSystem, path string) (*BootstrapState, error) {
state := BootstrapState{fs: fs, path: path}
if !fs.FileExists(path) {
return &state, nil
}
bytes, err := fs.ReadFile(path)
if err != nil {
return nil, bosherr.WrapError(err, "Reading bootstrap state file")
}
err = json.Unmarshal(bytes, &state)
if err != nil {
return nil, bosherr.WrapError(err, "Unmarshalling bootstrap state")
}
return &state, nil
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:19,代码来源:bootstrap_state.go
示例13: NewConfigFromPath
func NewConfigFromPath(path string, fs boshsys.FileSystem) (Config, error) {
var config Config
bytes, err := fs.ReadFile(path)
if err != nil {
return config, bosherr.WrapErrorf(err, "Reading config %s", path)
}
err = json.Unmarshal(bytes, &config)
if err != nil {
return config, bosherr.WrapError(err, "Unmarshalling config")
}
err = config.Validate()
if err != nil {
return config, bosherr.WrapError(err, "Validating config")
}
return config, nil
}
开发者ID:digideskweb,项目名称:bosh-softlayer-cpi,代码行数:20,代码来源:config.go
示例14:
package crypto_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-utils/crypto"
boshsys "github.com/cloudfoundry/bosh-utils/system"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("DigestProvider", func() {
var (
factory DigestProvider
fs boshsys.FileSystem
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
factory = NewDigestProvider(fs)
})
Describe("CreateFromFile", func() {
const (
filePath = "/file.txt"
fileContents = "something different"
)
BeforeEach(func() {
fs.WriteFileString(filePath, fileContents)
})
开发者ID:mattcui,项目名称:bosh-agent,代码行数:31,代码来源:digest_provider_test.go
示例15: init
func init() {
Describe("App", func() {
var (
baseDir string
agentConfPath string
agentConfJSON string
app App
)
BeforeEach(func() {
var err error
baseDir, err = ioutil.TempDir("", "go-agent-test")
Expect(err).ToNot(HaveOccurred())
err = os.Mkdir(filepath.Join(baseDir, "bosh"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
})
BeforeEach(func() {
agentConfPath = filepath.Join(baseDir, "bosh", "agent.json")
agentConfJSON = `{
"Infrastructure": { "Settings": { "Sources": [{ "Type": "CDROM", "FileName": "/fake-file-name" }] } }
}`
settingsPath := filepath.Join(baseDir, "bosh", "settings.json")
settingsJSON := `{
"agent_id": "my-agent-id",
"blobstore": {
"options": {
"bucket_name": "george",
"encryption_key": "optional encryption key",
"access_key_id": "optional access key id",
"secret_access_key": "optional secret access key"
},
"provider": "dummy"
},
"disks": {
"ephemeral": "/dev/sdb",
"persistent": {
"vol-xxxxxx": "/dev/sdf"
},
"system": "/dev/sda1"
},
"env": {
"bosh": {
"password": "some encrypted password"
}
},
"networks": {
"netA": {
"default": ["dns", "gateway"],
"ip": "ww.ww.ww.ww",
"dns": [
"xx.xx.xx.xx",
"yy.yy.yy.yy"
]
},
"netB": {
"dns": [
"zz.zz.zz.zz"
]
}
},
"Mbus": "https://vcap:[email protected]:6868",
"ntp": [
"0.north-america.pool.ntp.org",
"1.north-america.pool.ntp.org"
],
"vm": {
"name": "vm-abc-def"
}
}`
err := ioutil.WriteFile(settingsPath, []byte(settingsJSON), 0640)
Expect(err).ToNot(HaveOccurred())
})
JustBeforeEach(func() {
err := ioutil.WriteFile(agentConfPath, []byte(agentConfJSON), 0640)
Expect(err).ToNot(HaveOccurred())
logger := boshlog.NewLogger(boshlog.LevelNone)
fakefs := boshsys.NewOsFileSystem(logger)
app = New(logger, fakefs)
})
AfterEach(func() {
os.RemoveAll(baseDir)
})
It("Sets up device path resolver on platform specific to infrastructure", func() {
err := app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(err).ToNot(HaveOccurred())
Expect(app.GetPlatform().GetDevicePathResolver()).To(Equal(devicepathresolver.NewIdentityDevicePathResolver()))
})
//.........这里部分代码省略.........
开发者ID:mattcui,项目名称:bosh-agent,代码行数:101,代码来源:app_test.go
示例16:
var _ = Describe("WindowsJobSupervisor", func() {
Context("add jobs and control services", func() {
BeforeEach(func() {
if runtime.GOOS != "windows" {
Skip("Pending on non-Windows")
}
})
var (
once sync.Once
fs boshsys.FileSystem
logger boshlog.Logger
basePath string
logDir string
exePath string
jobDir string
processConfigPath string
jobSupervisor JobSupervisor
runner boshsys.CmdRunner
logOut *bytes.Buffer
logErr *bytes.Buffer
)
BeforeEach(func() {
once.Do(func() { Expect(buildPipeExe()).To(Succeed()) })
const testExtPath = "testdata/job-service-wrapper"
logOut = bytes.NewBufferString("")
logErr = bytes.NewBufferString("")
开发者ID:mattcui,项目名称:bosh-agent,代码行数:30,代码来源:windows_job_supervisor_test.go
示例17: GenerateDeploymentManifest
func GenerateDeploymentManifest(deploymentManifestFilePath string, fs boshsys.FileSystem, manifestContents string) error {
return fs.WriteFileString(deploymentManifestFilePath, manifestContents)
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:3,代码来源:generate.go
示例18:
"os"
"path/filepath"
. "github.com/cloudfoundry/bosh-utils/blobstore"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshsysfake "github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Blob Manager", func() {
var (
fs boshsys.FileSystem
logger boshlog.Logger
basePath string
blobPath string
blobId string
toWrite io.Reader
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
fs = boshsys.NewOsFileSystem(logger)
blobId = "105d33ae-655c-493d-bf9f-1df5cf3ca847"
basePath = os.TempDir()
blobPath = filepath.Join(basePath, blobId)
toWrite = bytes.NewReader([]byte("new data"))
})
readFile := func(fileIO boshsys.File) []byte {
fileStat, _ := fileIO.Stat()
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:32,代码来源:blob_manager_test.go
示例19:
)
const (
stageTimePattern = "\\(\\d{2}:\\d{2}:\\d{2}\\)"
stageFinishedPattern = "\\.\\.\\. Finished " + stageTimePattern + "$"
stageCompiledPackageSkippedPattern = "\\.\\.\\. Skipped \\[Package already compiled\\] " + stageTimePattern + "$"
)
var _ = Describe("bosh-init", func() {
var (
logger boshlog.Logger
fileSystem boshsys.FileSystem
sshCmdRunner CmdRunner
cmdEnv map[string]string
quietCmdEnv map[string]string
testEnv Environment
config *Config
instanceSSH InstanceSSH
instanceUsername = "vcap"
instancePassword = "sshpassword" // encrypted value must be in the manifest: resource_pool.env.bosh.password
instanceIP = "10.244.0.42"
)
var readLogFile = func(logPath string) (stdout string) {
stdout, _, exitCode, err := sshCmdRunner.RunCommand(cmdEnv, "cat", logPath)
Expect(err).ToNot(HaveOccurred())
Expect(exitCode).To(Equal(0))
return stdout
}
var deleteLogFile = func(logPath string) {
开发者ID:mattcui,项目名称:bosh-init,代码行数:32,代码来源:lifecycle_test.go
示例20:
"path/filepath"
"runtime"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
. "github.com/cloudfoundry/bosh-utils/fileutil"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
var _ = Describe("cpCopier", func() {
var (
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
cpCopier Copier
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs = boshsys.NewOsFileSystem(logger)
cmdRunner = boshsys.NewExecCmdRunner(logger)
cpCopier = NewCpCopier(cmdRunner, fs, logger)
if runtime.GOOS == "windows" {
Skip("Pending on Windows")
}
})
Describe("FilteredCopyToTemp", func() {
开发者ID:jianqiu,项目名称:bosh-softlayer-cpi,代码行数:31,代码来源:cp_copier_test.go
注:本文中的github.com/cloudfoundry/bosh-utils/system.FileSystem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论