1
0
mirror of https://github.com/openshift/source-to-image.git synced 2026-02-05 12:44:54 +01:00

issue197: fix gofmt complaints found by verify-gofmt.sh

This commit is contained in:
gabemontero
2015-07-29 14:18:30 -04:00
parent 19442d1ba1
commit 47bb7fb5e0
5 changed files with 35 additions and 44 deletions

View File

@@ -29,7 +29,7 @@ const (
SourceScripts = "upload" + string(os.PathSeparator) + "src" + string(os.PathSeparator) + ".sti" + string(os.PathSeparator) + "bin"
// UploadScripts is the location of scripts that will be uploaded to the image during STI build.
UploadScripts = "upload" + string(os.PathSeparator) + "scripts"
UploadScripts = "upload" + string(os.PathSeparator) + "scripts"
// Source is the location of application sources.
Source = "upload" + string(os.PathSeparator) + "src"
@@ -37,5 +37,5 @@ const (
ContextTmp = "upload" + string(os.PathSeparator) + "tmp"
// Ignorefile is the s2i version for ignore files like we see with .gitignore or .dockerignore .. initial impl mirrors documented .dockerignore capabilities
IgnoreFile = ".s2iignore"
IgnoreFile = ".s2iignore"
)

View File

@@ -10,10 +10,10 @@ import (
"github.com/golang/glog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/build"
"github.com/openshift/source-to-image/pkg/ignore"
"github.com/openshift/source-to-image/pkg/build/strategies/sti"
"github.com/openshift/source-to-image/pkg/docker"
"github.com/openshift/source-to-image/pkg/git"
"github.com/openshift/source-to-image/pkg/ignore"
"github.com/openshift/source-to-image/pkg/scripts"
"github.com/openshift/source-to-image/pkg/tar"
"github.com/openshift/source-to-image/pkg/util"

View File

@@ -76,9 +76,8 @@ func (h *stiGit) Clone(source, target string) error {
// --quiet does not surpress that anyway reduced the frequency of the hang, but it still occurred.
// the pipeToLog method has been left for now for historical purposes, but if this implemenetation
// of git clone holds, we'll want to delete that at some point.
opts := util.CommandOpts{
}
opts := util.CommandOpts{}
return h.runner.RunWithOptions(opts, "git", "clone", "--quiet", "--recursive", source, target)
}

View File

@@ -11,24 +11,20 @@ import (
"github.com/openshift/source-to-image/pkg/api"
)
type DockerIgnorer struct {}
type DockerIgnorer struct{}
func (b *DockerIgnorer) Ignore(config *api.Config) error {
// so, to duplicate the .dockerignore capabilities (https://docs.docker.com/reference/builder/#dockerignore-file)
// we have a flow that follows:
/*
so, to duplicate the .dockerignore capabilities (https://docs.docker.com/reference/builder/#dockerignore-file)
we have a flow that follows:
0) First note, .dockerignore rules are NOT recursive (unlike .gitignore) .. you have to list subdir explicitly
1) Read in the exclusion patterns
2) Skip over comments (noted by #)
3) note overrides (via exclamation sign i.e. !) and reinstate files (don't remove) as needed
4) leverage Glob matching to build list, as .dockerignore is documented as following filepath.Match / filepath.Glob
5) del files
1 to 4 is in getListOfFilesToIgnore
1 to 4 is in getListOfFilesToIgnore
*/
filesToDel, lerr := getListOfFilesToIgnore(config)
if lerr != nil {
return lerr
@@ -38,7 +34,7 @@ func (b *DockerIgnorer) Ignore(config *api.Config) error {
return nil
}
// delete compiled list of files
// delete compiled list of files
for _, fileToDel := range filesToDel {
glog.V(5).Infof("attempting to remove file %s \n", fileToDel)
rerr := os.RemoveAll(fileToDel)
@@ -72,9 +68,9 @@ func getListOfFilesToIgnore(config *api.Config) (map[string]string, error) {
if strings.HasPrefix(filespec, "#") {
continue
}
glog.V(4).Infof(".s2iignore lists a file spec of %s \n", filespec)
if strings.HasPrefix(filespec, "!") {
//remove any existing files to del that the override covers
// and patterns later on that undo this take precedence
@@ -85,7 +81,7 @@ func getListOfFilesToIgnore(config *api.Config) (map[string]string, error) {
// iterate through and determine ones to leave in
dontDel := make([]string, 0)
for candidate, _ := range filesToDel {
for candidate := range filesToDel {
compare := filepath.Join(config.WorkingSourceDir, filespec)
glog.V(5).Infof("For %s and %s see if it matches the spec %s which means that we leave in\n", filespec, candidate, compare)
leaveIn, _ := filepath.Match(compare, candidate)

View File

@@ -5,9 +5,9 @@ import (
"strings"
"testing"
"github.com/golang/glog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/util"
"github.com/golang/glog"
"os"
)
@@ -20,7 +20,6 @@ func getLogLevel() (level int) {
return
}
func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep []string) {
// create working dir
@@ -38,16 +37,15 @@ func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep
}
}()
c := &api.Config{WorkingDir: workingDir}
// create source repo dir for .s2iignore that matches where ignore.go looks
dpath := filepath.Join(c.WorkingDir,"upload","src")
derr := os.MkdirAll(dpath,0777)
dpath := filepath.Join(c.WorkingDir, "upload", "src")
derr := os.MkdirAll(dpath, 0777)
if derr != nil {
t.Errorf("Problem creating source repo dir %s with %v \n", dpath, derr)
}
c.WorkingSourceDir = dpath
t.Logf("working source dir %s \n", dpath)
@@ -56,20 +54,20 @@ func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep
ifile, ierr := os.Create(ipath)
defer ifile.Close()
if ierr != nil {
t.Errorf("Problem creating .s2iignore at %s with %v \n",ipath, ierr)
t.Errorf("Problem creating .s2iignore at %s with %v \n", ipath, ierr)
}
// write patterns to remove into s2ignore, but save ! exclusions
filesToIgnore := make(map[string]string)
for _,pattern := range patterns {
t.Logf("storing pattern %s \n",pattern)
for _, pattern := range patterns {
t.Logf("storing pattern %s \n", pattern)
_, serr := ifile.WriteString(pattern)
if serr != nil {
t.Errorf("Problem setting .s2iignore %v \n", serr)
}
if strings.HasPrefix(pattern, "!") {
pattern = strings.Replace(pattern, "!","",1)
pattern = strings.Replace(pattern, "!", "", 1)
t.Logf("Noting ignore pattern %s \n", pattern)
filesToIgnore[pattern] = pattern
}
@@ -83,19 +81,18 @@ func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep
filesToCreate = append(filesToCreate, fileToDel)
}
filesToKeepCheck := make(map[string]string)
for _,fileToKeep :=range filesToKeep {
for _, fileToKeep := range filesToKeep {
filesToKeepCheck[fileToKeep] = fileToKeep
filesToCreate = append(filesToCreate, fileToKeep)
}
// create files for test
for _, fileToCreate := range filesToCreate {
for _, fileToCreate := range filesToCreate {
fbpath := filepath.Join(dpath, fileToCreate)
// ensure any subdirs off working dir exist
dirpath := filepath.Dir(fbpath)
derr := os.MkdirAll(dirpath,0777)
derr := os.MkdirAll(dirpath, 0777)
if derr != nil && !os.IsExist(derr) {
t.Errorf("Problem creating subdirs %s with %v \n", dirpath, derr)
}
@@ -105,15 +102,14 @@ func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep
if fberr != nil {
t.Errorf("Problem creating test file %v \n", fberr)
}
}
}
// run ignorer algorithm
ignorer := &DockerIgnorer{}
ignorer := &DockerIgnorer{}
ignorer.Ignore(c)
// check if filesToDel, minus ignores, are gone, and filesToKeep are still there
for _,fileToCheck := range filesToCreate {
for _, fileToCheck := range filesToCreate {
fbpath := filepath.Join(dpath, fileToCheck)
t.Logf("Evaluating file %s from dir %s and file to check %s \n", fbpath, dpath, fileToCheck)
@@ -153,10 +149,10 @@ func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep
t.Errorf("file which was cited to be deleted by caller to runTest exists %s \n", fileToCheck)
continue
}
// if here, something unexpected
// if here, something unexpected
t.Errorf("file not in ignore / keep / del list !?!?!?!? %s \n", fileToCheck)
} else {
if dok {
t.Logf("file which should have been deleted is in fact gone %s \n", fileToCheck)
@@ -175,9 +171,9 @@ func baseTest(t *testing.T, patterns []string, filesToDel []string, filesToKeep
// if here, then something unexpected happened
t.Errorf("file not in ignore / keep / del list !?!?!?!? %s \n", fileToCheck)
}
}
}