Skip to content

Commit

Permalink
*: normalize the use of normalize
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen J Day <[email protected]>
  • Loading branch information
stevvooe committed Aug 22, 2017
1 parent f291c95 commit ae8dbea
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion builder/dockerfile/dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func workdir(req dispatchRequest) error {
runConfig := req.state.runConfig
// This is from the Dockerfile and will not necessarily be in platform
// specific semantics, hence ensure it is converted.
runConfig.WorkingDir, err = normaliseWorkdir(req.builder.platform, runConfig.WorkingDir, req.args[0])
runConfig.WorkingDir, err = normalizeWorkdir(req.builder.platform, runConfig.WorkingDir, req.args[0])
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions builder/dockerfile/dispatchers_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"path/filepath"
)

// normaliseWorkdir normalises a user requested working directory in a
// normalizeWorkdir normalizes a user requested working directory in a
// platform semantically consistent way.
func normaliseWorkdir(_ string, current string, requested string) (string, error) {
func normalizeWorkdir(_ string, current string, requested string) (string, error) {
if requested == "" {
return "", errors.New("cannot normalise nothing")
return "", errors.New("cannot normalize nothing")
}
current = filepath.FromSlash(current)
requested = filepath.FromSlash(requested)
Expand Down
14 changes: 7 additions & 7 deletions builder/dockerfile/dispatchers_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import (
"testing"
)

func TestNormaliseWorkdir(t *testing.T) {
func TestNormalizeWorkdir(t *testing.T) {
testCases := []struct{ current, requested, expected, expectedError string }{
{``, ``, ``, `cannot normalise nothing`},
{``, ``, ``, `cannot normalize nothing`},
{``, `foo`, `/foo`, ``},
{``, `/foo`, `/foo`, ``},
{`/foo`, `bar`, `/foo/bar`, ``},
{`/foo`, `/bar`, `/bar`, ``},
}

for _, test := range testCases {
normalised, err := normaliseWorkdir(runtime.GOOS, test.current, test.requested)
normalized, err := normalizeWorkdir(runtime.GOOS, test.current, test.requested)

if test.expectedError != "" && err == nil {
t.Fatalf("NormaliseWorkdir should return an error %s, got nil", test.expectedError)
t.Fatalf("NormalizeWorkdir should return an error %s, got nil", test.expectedError)
}

if test.expectedError != "" && err.Error() != test.expectedError {
t.Fatalf("NormaliseWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error())
t.Fatalf("NormalizeWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error())
}

if normalised != test.expected {
t.Fatalf("NormaliseWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalised)
if normalized != test.expected {
t.Fatalf("NormalizeWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalized)
}
}
}
20 changes: 10 additions & 10 deletions builder/dockerfile/dispatchers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import (

var pattern = regexp.MustCompile(`^[a-zA-Z]:\.$`)

// normaliseWorkdir normalises a user requested working directory in a
// normalizeWorkdir normalizes a user requested working directory in a
// platform semantically consistent way.
func normaliseWorkdir(platform string, current string, requested string) (string, error) {
func normalizeWorkdir(platform string, current string, requested string) (string, error) {
if platform == "" {
platform = "windows"
}
if platform == "windows" {
return normaliseWorkdirWindows(current, requested)
return normalizeWorkdirWindows(current, requested)
}
return normaliseWorkdirUnix(current, requested)
return normalizeWorkdirUnix(current, requested)
}

// normaliseWorkdirUnix normalises a user requested working directory in a
// normalizeWorkdirUnix normalizes a user requested working directory in a
// platform semantically consistent way.
func normaliseWorkdirUnix(current string, requested string) (string, error) {
func normalizeWorkdirUnix(current string, requested string) (string, error) {
if requested == "" {
return "", errors.New("cannot normalise nothing")
return "", errors.New("cannot normalize nothing")
}
current = strings.Replace(current, string(os.PathSeparator), "/", -1)
requested = strings.Replace(requested, string(os.PathSeparator), "/", -1)
Expand All @@ -40,11 +40,11 @@ func normaliseWorkdirUnix(current string, requested string) (string, error) {
return requested, nil
}

// normaliseWorkdirWindows normalises a user requested working directory in a
// normalizeWorkdirWindows normalizes a user requested working directory in a
// platform semantically consistent way.
func normaliseWorkdirWindows(current string, requested string) (string, error) {
func normalizeWorkdirWindows(current string, requested string) (string, error) {
if requested == "" {
return "", errors.New("cannot normalise nothing")
return "", errors.New("cannot normalize nothing")
}

// `filepath.Clean` will replace "" with "." so skip in that case
Expand Down
14 changes: 7 additions & 7 deletions builder/dockerfile/dispatchers_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package dockerfile

import "testing"

func TestNormaliseWorkdir(t *testing.T) {
func TestNormalizeWorkdir(t *testing.T) {
tests := []struct{ platform, current, requested, expected, etext string }{
{"windows", ``, ``, ``, `cannot normalise nothing`},
{"windows", ``, ``, ``, `cannot normalize nothing`},
{"windows", ``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
{"windows", ``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
{"windows", `c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
Expand All @@ -21,26 +21,26 @@ func TestNormaliseWorkdir(t *testing.T) {
{"windows", `C:\foo`, `bar`, `C:\foo\bar`, ``},
{"windows", `C:\foo`, `/bar`, `C:\bar`, ``},
{"windows", `C:\foo`, `\bar`, `C:\bar`, ``},
{"linux", ``, ``, ``, `cannot normalise nothing`},
{"linux", ``, ``, ``, `cannot normalize nothing`},
{"linux", ``, `foo`, `/foo`, ``},
{"linux", ``, `/foo`, `/foo`, ``},
{"linux", `/foo`, `bar`, `/foo/bar`, ``},
{"linux", `/foo`, `/bar`, `/bar`, ``},
{"linux", `\a`, `b\c`, `/a/b/c`, ``},
}
for _, i := range tests {
r, e := normaliseWorkdir(i.platform, i.current, i.requested)
r, e := normalizeWorkdir(i.platform, i.current, i.requested)

if i.etext != "" && e == nil {
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
}

if i.etext != "" && e.Error() != i.etext {
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
}

if r != i.expected {
t.Fatalf("TestNormaliseWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
t.Fatalf("TestNormalizeWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
}
}
}
2 changes: 1 addition & 1 deletion builder/dockerfile/internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (b *Builder) performCopy(state *dispatchState, inst copyInstruction) error
func createDestInfo(workingDir string, inst copyInstruction, imageMount *imageMount) (copyInfo, error) {
// Twiddle the destination when it's a relative path - meaning, make it
// relative to the WORKINGDIR
dest, err := normaliseDest(workingDir, inst.dest)
dest, err := normalizeDest(workingDir, inst.dest)
if err != nil {
return copyInfo{}, errors.Wrapf(err, "invalid %s", inst.cmdName)
}
Expand Down
4 changes: 2 additions & 2 deletions builder/dockerfile/internals_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/docker/docker/pkg/system"
)

// normaliseDest normalises the destination of a COPY/ADD command in a
// normalizeDest normalizes the destination of a COPY/ADD command in a
// platform semantically consistent way.
func normaliseDest(workingDir, requested string) (string, error) {
func normalizeDest(workingDir, requested string) (string, error) {
dest := filepath.FromSlash(requested)
endsInSlash := strings.HasSuffix(requested, string(os.PathSeparator))
if !system.IsAbs(requested) {
Expand Down
4 changes: 2 additions & 2 deletions builder/dockerfile/internals_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/pkg/errors"
)

// normaliseDest normalises the destination of a COPY/ADD command in a
// normalizeDest normalizes the destination of a COPY/ADD command in a
// platform semantically consistent way.
func normaliseDest(workingDir, requested string) (string, error) {
func normalizeDest(workingDir, requested string) (string, error) {
dest := filepath.FromSlash(requested)
endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator))

Expand Down
4 changes: 2 additions & 2 deletions builder/dockerfile/internals_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestNormaliseDest(t *testing.T) {
func TestNormalizeDest(t *testing.T) {
tests := []struct{ current, requested, expected, etext string }{
{``, `D:\`, ``, `Windows does not support destinations not on the system drive (C:)`},
{``, `e:/`, ``, `Windows does not support destinations not on the system drive (C:)`},
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestNormaliseDest(t *testing.T) {
}
for _, testcase := range tests {
msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested)
actual, err := normaliseDest(testcase.current, testcase.requested)
actual, err := normalizeDest(testcase.current, testcase.requested)
if testcase.etext == "" {
if !assert.NoError(t, err, msg) {
continue
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
imageID = strings.TrimSpace(imageID)

prefix, slash := getPrefixAndSlashFromDaemonPlatform()
prefix = strings.ToUpper(prefix) // Force C: as that's how WORKDIR is normalised on Windows
prefix = strings.ToUpper(prefix) // Force C: as that's how WORKDIR is normalized on Windows
expected := map[string]string{
"Config.ExposedPorts": "map[8080/tcp:{}]",
"Config.Env": "[DEBUG=true test=1 PATH=/foo]",
Expand Down
10 changes: 5 additions & 5 deletions volume/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *VolumeStore) List() ([]volume.Volume, []string, error) {
var out []volume.Volume

for _, v := range vols {
name := normaliseVolumeName(v.Name())
name := normalizeVolumeName(v.Name())

s.locks.Lock(name)
storedV, exists := s.getNamed(name)
Expand Down Expand Up @@ -269,7 +269,7 @@ func (s *VolumeStore) list() ([]volume.Volume, []string, error) {
// CreateWithRef creates a volume with the given name and driver and stores the ref
// This ensures there's no race between creating a volume and then storing a reference.
func (s *VolumeStore) CreateWithRef(name, driverName, ref string, opts, labels map[string]string) (volume.Volume, error) {
name = normaliseVolumeName(name)
name = normalizeVolumeName(name)
s.locks.Lock(name)
defer s.locks.Unlock(name)

Expand Down Expand Up @@ -432,7 +432,7 @@ func (s *VolumeStore) create(name, driverName string, opts, labels map[string]st
// This is just like Get(), but we store the reference while holding the lock.
// This makes sure there are no races between checking for the existence of a volume and adding a reference for it
func (s *VolumeStore) GetWithRef(name, driverName, ref string) (volume.Volume, error) {
name = normaliseVolumeName(name)
name = normalizeVolumeName(name)
s.locks.Lock(name)
defer s.locks.Unlock(name)

Expand All @@ -455,7 +455,7 @@ func (s *VolumeStore) GetWithRef(name, driverName, ref string) (volume.Volume, e

// Get looks if a volume with the given name exists and returns it if so
func (s *VolumeStore) Get(name string) (volume.Volume, error) {
name = normaliseVolumeName(name)
name = normalizeVolumeName(name)
s.locks.Lock(name)
defer s.locks.Unlock(name)

Expand Down Expand Up @@ -558,7 +558,7 @@ func lookupVolume(driverName, volumeName string) (volume.Volume, error) {

// Remove removes the requested volume. A volume is not removed if it has any refs
func (s *VolumeStore) Remove(v volume.Volume) error {
name := normaliseVolumeName(v.Name())
name := normalizeVolumeName(v.Name())
s.locks.Lock(name)
defer s.locks.Unlock(name)

Expand Down
4 changes: 2 additions & 2 deletions volume/store/store_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package store

// normaliseVolumeName is a platform specific function to normalise the name
// normalizeVolumeName is a platform specific function to normalize the name
// of a volume. This is a no-op on Unix-like platforms
func normaliseVolumeName(name string) string {
func normalizeVolumeName(name string) string {
return name
}
4 changes: 2 additions & 2 deletions volume/store/store_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package store

import "strings"

// normaliseVolumeName is a platform specific function to normalise the name
// normalizeVolumeName is a platform specific function to normalize the name
// of a volume. On Windows, as NTFS is case insensitive, under
// c:\ProgramData\Docker\Volumes\, the folders John and john would be synonymous.
// Hence we can't allow the volume "John" and "john" to be created as separate
// volumes.
func normaliseVolumeName(name string) string {
func normalizeVolumeName(name string) string {
return strings.ToLower(name)
}

0 comments on commit ae8dbea

Please sign in to comment.