當前位置: 首頁>>代碼示例>>Golang>>正文


Golang system.FileSystem類代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system.FileSystem的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem類的具體用法?Golang FileSystem怎麽用?Golang FileSystem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FileSystem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/cloudfoundry/bosh-utils/system.FileSystem類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。