summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorSebastiaan van Stijn <thaJeztah@users.noreply.github.com>2022-12-16 15:25:41 +0100
committerGitHub <noreply@github.com>2022-12-16 15:25:41 +0100
commit6371675bf9de2f38735db36ebe73fba5c9078ffb (patch)
treebd444805319ca2ccb431e39338c819c076c0cb64 /pkg
parentb10de9186ced20bed098592b72e7786349281cbf (diff)
parentfb7797320148efb84fc8ddade741a9ba27efd82c (diff)
downloaddocker-6371675bf9de2f38735db36ebe73fba5c9078ffb.tar.gz
Merge pull request #44275 from thaJeztah/move_pkg_system_funcs
pkg/system: move some functions to a new home
Diffstat (limited to 'pkg')
-rw-r--r--pkg/archive/path.go (renamed from pkg/system/path.go)17
-rw-r--r--pkg/archive/path_unix.go10
-rw-r--r--pkg/archive/path_windows.go22
-rw-r--r--pkg/archive/path_windows_test.go (renamed from pkg/system/path_windows_test.go)11
-rw-r--r--pkg/system/path_deprecated.go18
-rw-r--r--pkg/system/path_unix.go17
-rw-r--r--pkg/system/path_windows.go48
7 files changed, 55 insertions, 88 deletions
diff --git a/pkg/system/path.go b/pkg/archive/path.go
index 5c79f60985..888a697581 100644
--- a/pkg/system/path.go
+++ b/pkg/archive/path.go
@@ -1,19 +1,4 @@
-package system // import "github.com/docker/docker/pkg/system"
-
-const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-// DefaultPathEnv is unix style list of directories to search for
-// executables. Each directory is separated from the next by a colon
-// ':' character .
-// For Windows containers, an empty string is returned as the default
-// path will be set by the container, and Docker has no context of what the
-// default path should be.
-func DefaultPathEnv(os string) string {
- if os == "windows" {
- return ""
- }
- return defaultUnixPathEnv
-}
+package archive
// CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter,
// is the system drive.
diff --git a/pkg/archive/path_unix.go b/pkg/archive/path_unix.go
new file mode 100644
index 0000000000..0b135aea75
--- /dev/null
+++ b/pkg/archive/path_unix.go
@@ -0,0 +1,10 @@
+//go:build !windows
+// +build !windows
+
+package archive
+
+// checkSystemDriveAndRemoveDriveLetter is the non-Windows implementation
+// of CheckSystemDriveAndRemoveDriveLetter
+func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
+ return path, nil
+}
diff --git a/pkg/archive/path_windows.go b/pkg/archive/path_windows.go
new file mode 100644
index 0000000000..7e18c8e449
--- /dev/null
+++ b/pkg/archive/path_windows.go
@@ -0,0 +1,22 @@
+package archive
+
+import (
+ "fmt"
+ "path/filepath"
+ "strings"
+)
+
+// checkSystemDriveAndRemoveDriveLetter is the Windows implementation
+// of CheckSystemDriveAndRemoveDriveLetter
+func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
+ if len(path) == 2 && string(path[1]) == ":" {
+ return "", fmt.Errorf("no relative path specified in %q", path)
+ }
+ if !filepath.IsAbs(path) || len(path) < 2 {
+ return filepath.FromSlash(path), nil
+ }
+ if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") {
+ return "", fmt.Errorf("the specified path is not on the system drive (C:)")
+ }
+ return filepath.FromSlash(path[2:]), nil
+}
diff --git a/pkg/system/path_windows_test.go b/pkg/archive/path_windows_test.go
index c7cc902065..27d7c9a8f5 100644
--- a/pkg/system/path_windows_test.go
+++ b/pkg/archive/path_windows_test.go
@@ -1,7 +1,4 @@
-//go:build windows
-// +build windows
-
-package system // import "github.com/docker/docker/pkg/system"
+package archive
import (
"testing"
@@ -11,7 +8,7 @@ import (
func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
// Fails if not C drive.
_, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`)
- if err == nil || err.Error() != "The specified path is not on the system drive (C:)" {
+ if err == nil || err.Error() != "the specified path is not on the system drive (C:)" {
t.Fatalf("Expected error for d:")
}
@@ -68,7 +65,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:`); err == nil {
t.Fatalf("c: should fail")
}
- if err.Error() != `No relative path specified in "c:"` {
+ if err.Error() != `no relative path specified in "c:"` {
t.Fatalf(path, err)
}
@@ -76,7 +73,7 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
if path, err = CheckSystemDriveAndRemoveDriveLetter(`d:`); err == nil {
t.Fatalf("c: should fail")
}
- if err.Error() != `No relative path specified in "d:"` {
+ if err.Error() != `no relative path specified in "d:"` {
t.Fatalf(path, err)
}
}
diff --git a/pkg/system/path_deprecated.go b/pkg/system/path_deprecated.go
new file mode 100644
index 0000000000..5c95026c3d
--- /dev/null
+++ b/pkg/system/path_deprecated.go
@@ -0,0 +1,18 @@
+package system
+
+const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+
+// DefaultPathEnv is unix style list of directories to search for
+// executables. Each directory is separated from the next by a colon
+// ':' character .
+// For Windows containers, an empty string is returned as the default
+// path will be set by the container, and Docker has no context of what the
+// default path should be.
+//
+// Deprecated: use oci.DefaultPathEnv
+func DefaultPathEnv(os string) string {
+ if os == "windows" {
+ return ""
+ }
+ return defaultUnixPathEnv
+}
diff --git a/pkg/system/path_unix.go b/pkg/system/path_unix.go
deleted file mode 100644
index 3778cf06d8..0000000000
--- a/pkg/system/path_unix.go
+++ /dev/null
@@ -1,17 +0,0 @@
-//go:build !windows
-// +build !windows
-
-package system // import "github.com/docker/docker/pkg/system"
-
-// GetLongPathName converts Windows short pathnames to full pathnames.
-// For example C:\Users\ADMIN~1 --> C:\Users\Administrator.
-// It is a no-op on non-Windows platforms
-func GetLongPathName(path string) (string, error) {
- return path, nil
-}
-
-// checkSystemDriveAndRemoveDriveLetter is the non-Windows implementation
-// of CheckSystemDriveAndRemoveDriveLetter
-func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
- return path, nil
-}
diff --git a/pkg/system/path_windows.go b/pkg/system/path_windows.go
deleted file mode 100644
index 708702ee1c..0000000000
--- a/pkg/system/path_windows.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package system // import "github.com/docker/docker/pkg/system"
-
-import (
- "fmt"
- "path/filepath"
- "strings"
-
- "golang.org/x/sys/windows"
-)
-
-// GetLongPathName converts Windows short pathnames to full pathnames.
-// For example C:\Users\ADMIN~1 --> C:\Users\Administrator.
-// It is a no-op on non-Windows platforms
-func GetLongPathName(path string) (string, error) {
- // See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg
- p, err := windows.UTF16FromString(path)
- if err != nil {
- return "", err
- }
- b := p // GetLongPathName says we can reuse buffer
- n, err := windows.GetLongPathName(&p[0], &b[0], uint32(len(b)))
- if err != nil {
- return "", err
- }
- if n > uint32(len(b)) {
- b = make([]uint16, n)
- _, err = windows.GetLongPathName(&p[0], &b[0], uint32(len(b)))
- if err != nil {
- return "", err
- }
- }
- return windows.UTF16ToString(b), nil
-}
-
-// checkSystemDriveAndRemoveDriveLetter is the Windows implementation
-// of CheckSystemDriveAndRemoveDriveLetter
-func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
- if len(path) == 2 && string(path[1]) == ":" {
- return "", fmt.Errorf("No relative path specified in %q", path)
- }
- if !filepath.IsAbs(path) || len(path) < 2 {
- return filepath.FromSlash(path), nil
- }
- if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") {
- return "", fmt.Errorf("The specified path is not on the system drive (C:)")
- }
- return filepath.FromSlash(path[2:]), nil
-}