本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/util.NewFileSystem函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFileSystem函数的具体用法?Golang NewFileSystem怎么用?Golang NewFileSystem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFileSystem函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string, forceCopy bool) (build.Downloader, string, error) {
glog.V(4).Infof("DownloadForSource %s", s)
details, mods := git.ParseFile(s)
glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
if details.FileExists && details.BadRef {
return nil, s, fmt.Errorf("local location referenced by %s exists but the input after the # is malformed", s)
}
if details.FileExists && mods != nil {
glog.V(4).Infof("new source from parse file %s", mods.Path)
if details.ProtoSpecified {
s = mods.Path
} else {
// prepending with file:// is a precautionary step which previous incarnations of this code did; we
// preserve that behavior (it is more explicit, if not absolutely necessary; but we do it here as was done before
// vs. down in our generic git layer (which is leveraged separately in origin)
s = "file://" + mods.Path
}
}
if details.FileExists && (details.UseCopy || forceCopy) {
return &file.File{util.NewFileSystem()}, s, nil
}
// If the source is valid GIT protocol (file://, ssh://, git://, [email protected], etc..) use GIT
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}
开发者ID:carriercomm,项目名称:origin,代码行数:37,代码来源:scm.go
示例2: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
glog.V(4).Infof("DownloadForSource %s", s)
details, mods := git.ParseFile(s)
glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
if details.FileExists && details.BadRef {
return nil, s, fmt.Errorf("local location referenced by %s exists but the input after the # is malformed", s)
}
if details.FileExists && mods != nil {
glog.V(4).Infof("new path from parse file %s", mods.Path)
s = mods.Path
}
if details.FileExists && details.UseCopy {
return &file.File{util.NewFileSystem()}, s, nil
}
// If the source is valid GIT protocol (file://, ssh://, git://, [email protected], etc..) use GIT
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}
开发者ID:urashidmalik,项目名称:origin,代码行数:30,代码来源:scm.go
示例3: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
details, _ := git.ParseFile(s)
if details.FileExists && details.UseCopy {
if !details.ProtoSpecified {
// since not using git, any resulting URLs need to be explicit with file:// protocol specified
s = "file://" + s
}
return &file.File{util.NewFileSystem()}, s, nil
}
if details.ProtoSpecified && !details.FileExists {
return nil, s, fmt.Errorf("local location: %s does not exist", s)
}
if !details.ProtoSpecified && details.FileExists {
// if local file system, without file://, when using git, should not need file://, but we'll be safe;
// satisfies previous constructed test case in scm_test.go as well
s = "file://" + s
}
// If the source is valid GIT remote protocol (ssh://, git://, [email protected], etc..) use GIT
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}
开发者ID:jhjeong-kr,项目名称:source-to-image,代码行数:32,代码来源:scm.go
示例4: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) build.Downloader {
// If the source starts with file:// and there is no GIT binary, use 'file'
// SCM plugin
if (strings.HasPrefix(s, "file://") || strings.HasPrefix(s, "/")) && !hasGitBinary() {
return &file.File{util.NewFileSystem()}
}
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}
}
glog.Errorf("No downloader defined for %q source URL", s)
return nil
}
开发者ID:nitintutlani,项目名称:origin,代码行数:17,代码来源:scm.go
示例5: StreamDirAsTar
// StreamFileAsTar streams the source file as a tar archive.
// The permissions of the file is changed to 0666.
func (t *stiTar) StreamDirAsTar(source, dest string, writer io.Writer) error {
f, err := os.Open(source)
if err != nil {
return err
}
if info, _ := f.Stat(); !info.IsDir() {
return fmt.Errorf("the source %q has to be directory, not a file", source)
}
defer f.Close()
fs := util.NewFileSystem()
tmpDir, err := ioutil.TempDir("", "s2i-")
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
if err := fs.Copy(source, tmpDir); err != nil {
return err
}
// Skip chmod if on windows OS
if runtime.GOOS != "windows" {
err = filepath.Walk(tmpDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return os.Chmod(path, 0777)
}
return os.Chmod(path, 0666)
})
if err != nil {
return err
}
}
return t.CreateTarStream(tmpDir, false, writer)
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:37,代码来源:tar.go
示例6: StreamDirAsTarWithCallback
// StreamDirAsTarWithCallback streams the source directory as a tar archive.
func (t *stiTar) StreamDirAsTarWithCallback(source string, writer io.Writer, walkFn filepath.WalkFunc, modifyInplace bool) error {
f, err := os.Open(source)
if err != nil {
return err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return err
}
if !info.IsDir() {
return fmt.Errorf("the source %q has to be directory, not a file", source)
}
destDir := source
if !modifyInplace {
fs := util.NewFileSystem()
tmpDir, err := ioutil.TempDir("", "s2i-")
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
if err = fs.Copy(source, tmpDir); err != nil {
return err
}
destDir = tmpDir
}
if err := filepath.Walk(destDir, walkFn); err != nil {
return err
}
return t.CreateTarStream(destDir, false, writer)
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:32,代码来源:tar.go
示例7: StreamFileAsTarWithCallback
// StreamFileAsTarWithCallback streams the source file as a tar archive.
func (t *stiTar) StreamFileAsTarWithCallback(source, name string, writer io.Writer, walkFn filepath.WalkFunc, modifyInplace bool) error {
f, err := os.Open(source)
if err != nil {
return err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return err
}
if info.IsDir() {
return fmt.Errorf("the source %q has to be regular file, not directory", source)
}
fs := util.NewFileSystem()
tmpDir, err := ioutil.TempDir("", "s2i-")
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
dst := filepath.Join(tmpDir, name)
if err := fs.Copy(source, dst); err != nil {
return err
}
fileInfo, fileErr := os.Stat(dst)
if err := walkFn(dst, fileInfo, fileErr); err != nil {
return err
}
return t.CreateTarStream(tmpDir, false, writer)
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:30,代码来源:tar.go
示例8: New
// New returns the instance of STI builder strategy for the given config.
// If the layeredBuilder parameter is specified, then the builder provided will
// be used for the case that the base Docker image does not have 'tar' or 'bash'
// installed.
func New(req *api.Config) (*STI, error) {
docker, err := docker.New(req.DockerConfig, req.PullAuthentication)
if err != nil {
return nil, err
}
inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication)
b := &STI{
installer: inst,
config: req,
docker: docker,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
callbackInvoker: util.NewCallbackInvoker(),
requiredScripts: []string{api.Assemble, api.Run},
optionalScripts: []string{api.SaveArtifacts},
externalScripts: map[string]bool{},
installedScripts: map[string]bool{},
scriptsURL: map[string]string{},
}
// The sources are downloaded using the GIT downloader.
// TODO: Add more SCM in future.
b.source = &git.Clone{b.git, b.fs}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
b.layered, err = layered.New(req, b)
// Set interfaces
b.preparer = b
b.artifacts = b
b.scripts = b
b.postExecutor = b
return b, err
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:39,代码来源:sti.go
示例9: NewInstaller
// NewInstaller returns a new instance of the default Installer implementation
func NewInstaller(image string, scriptsURL string, proxyConfig *api.ProxyConfig, docker docker.Docker, auth dockerClient.AuthConfiguration) Installer {
m := DefaultScriptSourceManager{
Image: image,
ScriptsURL: scriptsURL,
dockerAuth: auth,
docker: docker,
fs: util.NewFileSystem(),
download: NewDownloader(proxyConfig),
}
// Order is important here, first we try to get the scripts from provided URL,
// then we look into sources and check for .s2i/bin scripts.
if len(m.ScriptsURL) > 0 {
m.Add(&URLScriptHandler{URL: m.ScriptsURL, download: m.download, fs: m.fs, name: ScriptURLHandler})
}
m.Add(&SourceScriptHandler{fs: m.fs})
// If the detection handlers above fail, try to get the script url from the
// docker image itself.
defaultURL, err := m.docker.GetScriptsURL(m.Image)
if err == nil && defaultURL != "" {
m.Add(&URLScriptHandler{URL: defaultURL, download: m.download, fs: m.fs, name: ImageURLHandler})
}
return &m
}
开发者ID:sgallagher,项目名称:origin,代码行数:26,代码来源:install.go
示例10: New
// New returns a new instance of OnBuild builder
func New(config *api.Config, overrides build.Overrides) (*OnBuild, error) {
dockerHandler, err := docker.New(config.DockerConfig, config.PullAuthentication)
if err != nil {
return nil, err
}
b := &OnBuild{
docker: dockerHandler,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
}
// Use STI Prepare() and download the 'run' script optionally.
s, err := sti.New(config, overrides)
s.SetScripts([]string{}, []string{api.Assemble, api.Run})
downloader := overrides.Downloader
if downloader == nil {
d, sourceURL, err := scm.DownloaderForSource(config.Source)
if err != nil {
return nil, err
}
downloader = d
config.Source = sourceURL
}
b.source = onBuildSourceHandler{
Downloader: downloader,
Preparer: s,
Ignorer: &ignore.DockerIgnorer{},
}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
return b, nil
}
开发者ID:johnmccawley,项目名称:origin,代码行数:35,代码来源:onbuild.go
示例11: copyNetworkPodInfo
func (d *NetworkDiagnostic) copyNetworkPodInfo(pod *kapi.Pod) error {
tmp, err := ioutil.TempFile("", "network-diags")
if err != nil {
return fmt.Errorf("Can not create local temporary file for tar: %v", err)
}
defer os.Remove(tmp.Name())
// Tar logdir on the remote node and copy to a local temporary file
errBuf := &bytes.Buffer{}
nodeLogDir := filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, pod.Spec.NodeName)
cmd := []string{"chroot", util.NetworkDiagContainerMountPath, "tar", "-C", nodeLogDir, "-c", "."}
if err = util.Execute(d.Factory, cmd, pod, nil, tmp, errBuf); err != nil {
return fmt.Errorf("Creating remote tar locally failed: %v, %s", err, errBuf.String())
}
if err := tmp.Close(); err != nil {
return fmt.Errorf("Closing temporary tar file %s failed: %v", tmp.Name(), err)
}
// Extract copied temporary file locally
tmp, err = os.Open(tmp.Name())
if err != nil {
return fmt.Errorf("Can not open temporary tar file %s: %v", tmp.Name(), err)
}
defer tmp.Close()
tarHelper := tar.New(s2iutil.NewFileSystem())
tarHelper.SetExclusionPattern(nil)
logdir := filepath.Join(d.LogDir, util.NetworkDiagNodeLogDirPrefix, pod.Spec.NodeName)
err = tarHelper.ExtractTarStream(logdir, tmp)
if err != nil {
return fmt.Errorf("Untar local directory failed: %v, %s", err, errBuf.String())
}
return nil
}
开发者ID:php-coder,项目名称:origin,代码行数:34,代码来源:results.go
示例12: StreamFileAsTar
// StreamFileAsTar streams the source file as a tar archive.
// The permissions of all files in archive is changed to 0666.
func (t *stiTar) StreamFileAsTar(source, name string, writer io.Writer) error {
f, err := os.Open(source)
if err != nil {
return err
}
if info, _ := f.Stat(); info.IsDir() {
return fmt.Errorf("the source %q has to be regular file, not directory", source)
}
defer f.Close()
fs := util.NewFileSystem()
tmpDir, err := ioutil.TempDir("", "s2i-")
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
dst := filepath.Join(tmpDir, name)
if err := fs.Copy(source, dst); err != nil {
return err
}
if runtime.GOOS != "windows" {
if err := os.Chmod(dst, 0666); err != nil {
return err
}
}
return t.CreateTarStream(tmpDir, false, writer)
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:28,代码来源:tar.go
示例13: New
// New returns the instance of STI builder strategy for the given config.
// If the layeredBuilder parameter is specified, then the builder provided will
// be used for the case that the base Docker image does not have 'tar' or 'bash'
// installed.
func New(req *api.Config, overrides build.Overrides) (*STI, error) {
docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication)
if err != nil {
return nil, err
}
var incrementalDocker dockerpkg.Docker
if req.Incremental {
incrementalDocker, err = dockerpkg.New(req.DockerConfig, req.IncrementalAuthentication)
if err != nil {
return nil, err
}
}
inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication)
b := &STI{
installer: inst,
config: req,
docker: docker,
incrementalDocker: incrementalDocker,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
callbackInvoker: util.NewCallbackInvoker(),
requiredScripts: []string{api.Assemble, api.Run},
optionalScripts: []string{api.SaveArtifacts},
externalScripts: map[string]bool{},
installedScripts: map[string]bool{},
scriptsURL: map[string]string{},
}
// The sources are downloaded using the GIT downloader.
// TODO: Add more SCM in future.
// TODO: explicit decision made to customize processing for usage specifically vs.
// leveraging overrides; also, we ultimately want to simplify s2i usage a good bit,
// which would lead to replacing this quick short circuit (so this change is tactical)
b.source = overrides.Downloader
if b.source == nil && !req.Usage {
downloader, sourceURL, err := scm.DownloaderForSource(req.Source, req.ForceCopy)
if err != nil {
return nil, err
}
b.source = downloader
req.Source = sourceURL
}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
b.layered, err = layered.New(req, b, overrides)
// Set interfaces
b.preparer = b
// later on, if we support say .gitignore func in addition to .dockerignore func, setting
// ignorer will be based on config setting
b.ignorer = &ignore.DockerIgnorer{}
b.artifacts = b
b.scripts = b
b.postExecutor = b
return b, err
}
开发者ID:carriercomm,项目名称:origin,代码行数:63,代码来源:sti.go
示例14: DownloadDirFromContainer
// DownloadDirFromContainer downloads an entire directory of files from a remote
// container.
func DownloadDirFromContainer(client *docker.Client, container, src, dst string) error {
downloader := newContainerDownloader(client, container, src)
defer downloader.Close()
tarReader := &removeLeadingDirectoryAdapter{Reader: tar.NewReader(downloader)}
t := s2itar.New(s2iutil.NewFileSystem())
return t.ExtractTarStreamFromTarReader(dst, tarReader, nil)
}
开发者ID:php-coder,项目名称:origin,代码行数:10,代码来源:filetransfer.go
示例15: New
// New returns the instance of STI builder strategy for the given config.
// If the layeredBuilder parameter is specified, then the builder provided will
// be used for the case that the base Docker image does not have 'tar' or 'bash'
// installed.
func New(req *api.Config, overrides build.Overrides) (*STI, error) {
docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication)
if err != nil {
return nil, err
}
var incrementalDocker dockerpkg.Docker
if req.Incremental {
incrementalDocker, err = dockerpkg.New(req.DockerConfig, req.IncrementalAuthentication)
if err != nil {
return nil, err
}
}
inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication)
b := &STI{
installer: inst,
config: req,
docker: docker,
incrementalDocker: incrementalDocker,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
callbackInvoker: util.NewCallbackInvoker(),
requiredScripts: []string{api.Assemble, api.Run},
optionalScripts: []string{api.SaveArtifacts},
externalScripts: map[string]bool{},
installedScripts: map[string]bool{},
scriptsURL: map[string]string{},
}
// The sources are downloaded using the GIT downloader.
// TODO: Add more SCM in future.
b.source = overrides.Downloader
if b.source == nil {
downloader, sourceURL, err := scm.DownloaderForSource(req.Source)
if err != nil {
return nil, err
}
b.source = downloader
req.Source = sourceURL
}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
b.layered, err = layered.New(req, b, overrides)
// Set interfaces
b.preparer = b
// later on, if we support say .gitignore func in addition to .dockerignore func, setting
// ignorer will be based on config setting
b.ignorer = &ignore.DockerIgnorer{}
b.artifacts = b
b.scripts = b
b.postExecutor = b
return b, err
}
开发者ID:4sp1r3,项目名称:source-to-image,代码行数:60,代码来源:sti.go
示例16: NewInstaller
// NewInstaller returns a new instance of the default Installer implementation
func NewInstaller(image string, scriptsURL string, docker docker.Docker, auth dockerClient.AuthConfiguration) Installer {
return &installer{
image: image,
scriptsURL: scriptsURL,
docker: docker,
downloader: NewDownloader(),
pullAuth: auth,
fs: util.NewFileSystem(),
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:11,代码来源:install.go
示例17: NewDockerBuilder
// NewDockerBuilder creates a new instance of DockerBuilder
func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterface, build *api.Build, gitClient GitClient, cgLimits *s2iapi.CGroupLimits) *DockerBuilder {
return &DockerBuilder{
dockerClient: dockerClient,
build: build,
gitClient: gitClient,
tar: tar.New(s2iutil.NewFileSystem()),
client: buildsClient,
cgLimits: cgLimits,
}
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:11,代码来源:docker.go
示例18: NewUsage
// NewUsage creates a new instance of the default Usage implementation
func NewUsage(config *api.Config) (*Usage, error) {
b, err := New(config, util.NewFileSystem(), build.Overrides{})
if err != nil {
return nil, err
}
usage := Usage{
handler: b,
config: config,
garbage: b.garbage,
}
return &usage, nil
}
开发者ID:php-coder,项目名称:origin,代码行数:13,代码来源:usage.go
示例19: New
func New(config *api.Config, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) {
d, err := docker.New(config.DockerConfig, config.PullAuthentication)
if err != nil {
return nil, err
}
return &Layered{
docker: d,
config: config,
fs: util.NewFileSystem(),
tar: tar.New(),
scripts: scripts,
}, nil
}
开发者ID:smacc364,项目名称:origin,代码行数:13,代码来源:layered.go
示例20: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
// If the source is using file:// protocol but it is not a GIT repository,
// trim the prefix and treat it as a file copy.
if strings.HasPrefix(s, "file://") && !isLocalGitRepository(s) {
s = strings.TrimPrefix(s, "file://")
}
// If the source is file:// protocol and it is GIT repository, but we don't
// have GIT binary to fetch it, treat it as file copy.
if strings.HasPrefix(s, "file://") && !hasGitBinary() {
s = strings.TrimPrefix(s, "file://")
}
// If the source is valid GIT protocol (file://, git://, [email protected], etc..) use GIT
// binary to download the sources
if g := git.New(); g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
// Convert relative path to absolute path.
if !strings.HasPrefix(s, "/") {
if absolutePath, err := filepath.Abs(s); err == nil {
s = absolutePath
}
}
if isLocalGitRepository(s) {
return DownloaderForSource("file://" + s)
}
// If we have local directory and that directory exists, use file copy
if _, err := os.Stat(s); err == nil {
return &file.File{util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("No downloader defined for location: %q", s)
}
开发者ID:ncantor,项目名称:origin,代码行数:39,代码来源:scm.go
注:本文中的github.com/openshift/source-to-image/pkg/util.NewFileSystem函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论