Browse code

Merge pull request #39699 from thaJeztah/mkdirall_dropin

Allow system.MkDirAll() to be used as drop-in for os.MkDirAll()

Tibor Vass authored on 2019/08/28 08:27:53
Showing 15 changed files
... ...
@@ -133,7 +133,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
133 133
 		return err
134 134
 	}
135 135
 
136
-	if err := system.MkdirAll(cli.Config.ExecRoot, 0700, ""); err != nil {
136
+	if err := system.MkdirAll(cli.Config.ExecRoot, 0700); err != nil {
137 137
 		return err
138 138
 	}
139 139
 
... ...
@@ -41,7 +41,7 @@ func (container *Container) CreateSecretSymlinks() error {
41 41
 		if err != nil {
42 42
 			return err
43 43
 		}
44
-		if err := system.MkdirAll(filepath.Dir(resolvedPath), 0, ""); err != nil {
44
+		if err := system.MkdirAll(filepath.Dir(resolvedPath), 0); err != nil {
45 45
 			return err
46 46
 		}
47 47
 		if err := os.Symlink(filepath.Join(containerInternalSecretMountPath, r.SecretID), resolvedPath); err != nil {
... ...
@@ -91,7 +91,7 @@ func (container *Container) CreateConfigSymlinks() error {
91 91
 		if err != nil {
92 92
 			return err
93 93
 		}
94
-		if err := system.MkdirAll(filepath.Dir(resolvedPath), 0, ""); err != nil {
94
+		if err := system.MkdirAll(filepath.Dir(resolvedPath), 0); err != nil {
95 95
 			return err
96 96
 		}
97 97
 		if err := os.Symlink(filepath.Join(containerInternalConfigsDirPath, configRef.ConfigID), resolvedPath); err != nil {
... ...
@@ -772,7 +772,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
772 772
 	}
773 773
 	if runtime.GOOS == "windows" {
774 774
 		if _, err := os.Stat(realTmp); err != nil && os.IsNotExist(err) {
775
-			if err := system.MkdirAll(realTmp, 0700, ""); err != nil {
775
+			if err := system.MkdirAll(realTmp, 0700); err != nil {
776 776
 				return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err)
777 777
 			}
778 778
 		}
... ...
@@ -834,7 +834,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
834 834
 	// Create the directory where we'll store the runtime scripts (i.e. in
835 835
 	// order to support runtimeArgs)
836 836
 	daemonRuntimes := filepath.Join(config.Root, "runtimes")
837
-	if err := system.MkdirAll(daemonRuntimes, 0700, ""); err != nil {
837
+	if err := system.MkdirAll(daemonRuntimes, 0700); err != nil {
838 838
 		return nil, err
839 839
 	}
840 840
 	if err := d.loadRuntimes(); err != nil {
... ...
@@ -842,7 +842,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
842 842
 	}
843 843
 
844 844
 	if runtime.GOOS == "windows" {
845
-		if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0, ""); err != nil {
845
+		if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil {
846 846
 			return nil, err
847 847
 		}
848 848
 	}
... ...
@@ -981,7 +981,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
981 981
 
982 982
 	trustDir := filepath.Join(config.Root, "trust")
983 983
 
984
-	if err := system.MkdirAll(trustDir, 0700, ""); err != nil {
984
+	if err := system.MkdirAll(trustDir, 0700); err != nil {
985 985
 		return nil, err
986 986
 	}
987 987
 
... ...
@@ -17,7 +17,7 @@ import (
17 17
 // TODO: this should use more of libtrust.LoadOrCreateTrustKey which may need
18 18
 // a refactor or this function to be moved into libtrust
19 19
 func loadOrCreateTrustKey(trustKeyPath string) (libtrust.PrivateKey, error) {
20
-	err := system.MkdirAll(filepath.Dir(trustKeyPath), 0755, "")
20
+	err := system.MkdirAll(filepath.Dir(trustKeyPath), 0755)
21 21
 	if err != nil {
22 22
 		return nil, err
23 23
 	}
... ...
@@ -83,7 +83,7 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da
83 83
 	}
84 84
 	r.setDefaults()
85 85
 
86
-	if err := system.MkdirAll(stateDir, 0700, ""); err != nil {
86
+	if err := system.MkdirAll(stateDir, 0700); err != nil {
87 87
 		return nil, err
88 88
 	}
89 89
 
... ...
@@ -1134,7 +1134,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
1134 1134
 		dst = filepath.Join(dst, filepath.Base(src))
1135 1135
 	}
1136 1136
 	// Create the holding directory if necessary
1137
-	if err := system.MkdirAll(filepath.Dir(dst), 0700, ""); err != nil {
1137
+	if err := system.MkdirAll(filepath.Dir(dst), 0700); err != nil {
1138 1138
 		return err
1139 1139
 	}
1140 1140
 
... ...
@@ -84,7 +84,7 @@ func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64,
84 84
 			parentPath := filepath.Join(dest, parent)
85 85
 
86 86
 			if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) {
87
-				err = system.MkdirAll(parentPath, 0600, "")
87
+				err = system.MkdirAll(parentPath, 0600)
88 88
 				if err != nil {
89 89
 					return 0, err
90 90
 				}
... ...
@@ -49,7 +49,7 @@ func TestChrootTarUntar(t *testing.T) {
49 49
 	}
50 50
 	defer os.RemoveAll(tmpdir)
51 51
 	src := filepath.Join(tmpdir, "src")
52
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
52
+	if err := system.MkdirAll(src, 0700); err != nil {
53 53
 		t.Fatal(err)
54 54
 	}
55 55
 	if err := ioutil.WriteFile(filepath.Join(src, "toto"), []byte("hello toto"), 0644); err != nil {
... ...
@@ -63,7 +63,7 @@ func TestChrootTarUntar(t *testing.T) {
63 63
 		t.Fatal(err)
64 64
 	}
65 65
 	dest := filepath.Join(tmpdir, "src")
66
-	if err := system.MkdirAll(dest, 0700, ""); err != nil {
66
+	if err := system.MkdirAll(dest, 0700); err != nil {
67 67
 		t.Fatal(err)
68 68
 	}
69 69
 	if err := Untar(stream, dest, &archive.TarOptions{ExcludePatterns: []string{"lolo"}}); err != nil {
... ...
@@ -81,7 +81,7 @@ func TestChrootUntarWithHugeExcludesList(t *testing.T) {
81 81
 	}
82 82
 	defer os.RemoveAll(tmpdir)
83 83
 	src := filepath.Join(tmpdir, "src")
84
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
84
+	if err := system.MkdirAll(src, 0700); err != nil {
85 85
 		t.Fatal(err)
86 86
 	}
87 87
 	if err := ioutil.WriteFile(filepath.Join(src, "toto"), []byte("hello toto"), 0644); err != nil {
... ...
@@ -92,7 +92,7 @@ func TestChrootUntarWithHugeExcludesList(t *testing.T) {
92 92
 		t.Fatal(err)
93 93
 	}
94 94
 	dest := filepath.Join(tmpdir, "dest")
95
-	if err := system.MkdirAll(dest, 0700, ""); err != nil {
95
+	if err := system.MkdirAll(dest, 0700); err != nil {
96 96
 		t.Fatal(err)
97 97
 	}
98 98
 	options := &archive.TarOptions{}
... ...
@@ -181,7 +181,7 @@ func TestChrootTarUntarWithSymlink(t *testing.T) {
181 181
 	}
182 182
 	defer os.RemoveAll(tmpdir)
183 183
 	src := filepath.Join(tmpdir, "src")
184
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
184
+	if err := system.MkdirAll(src, 0700); err != nil {
185 185
 		t.Fatal(err)
186 186
 	}
187 187
 	if _, err := prepareSourceDirectory(10, src, false); err != nil {
... ...
@@ -205,7 +205,7 @@ func TestChrootCopyWithTar(t *testing.T) {
205 205
 	}
206 206
 	defer os.RemoveAll(tmpdir)
207 207
 	src := filepath.Join(tmpdir, "src")
208
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
208
+	if err := system.MkdirAll(src, 0700); err != nil {
209 209
 		t.Fatal(err)
210 210
 	}
211 211
 	if _, err := prepareSourceDirectory(10, src, true); err != nil {
... ...
@@ -252,7 +252,7 @@ func TestChrootCopyFileWithTar(t *testing.T) {
252 252
 	}
253 253
 	defer os.RemoveAll(tmpdir)
254 254
 	src := filepath.Join(tmpdir, "src")
255
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
255
+	if err := system.MkdirAll(src, 0700); err != nil {
256 256
 		t.Fatal(err)
257 257
 	}
258 258
 	if _, err := prepareSourceDirectory(10, src, true); err != nil {
... ...
@@ -297,7 +297,7 @@ func TestChrootUntarPath(t *testing.T) {
297 297
 	}
298 298
 	defer os.RemoveAll(tmpdir)
299 299
 	src := filepath.Join(tmpdir, "src")
300
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
300
+	if err := system.MkdirAll(src, 0700); err != nil {
301 301
 		t.Fatal(err)
302 302
 	}
303 303
 	if _, err := prepareSourceDirectory(10, src, false); err != nil {
... ...
@@ -359,7 +359,7 @@ func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
359 359
 	}
360 360
 	defer os.RemoveAll(tmpdir)
361 361
 	dest := filepath.Join(tmpdir, "dest")
362
-	if err := system.MkdirAll(dest, 0700, ""); err != nil {
362
+	if err := system.MkdirAll(dest, 0700); err != nil {
363 363
 		t.Fatal(err)
364 364
 	}
365 365
 	stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024}
... ...
@@ -376,7 +376,7 @@ func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
376 376
 	}
377 377
 	defer os.RemoveAll(tmpdir)
378 378
 	dest := filepath.Join(tmpdir, "dest")
379
-	if err := system.MkdirAll(dest, 0700, ""); err != nil {
379
+	if err := system.MkdirAll(dest, 0700); err != nil {
380 380
 		t.Fatal(err)
381 381
 	}
382 382
 	stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024}
... ...
@@ -393,7 +393,7 @@ func TestChrootApplyDotDotFile(t *testing.T) {
393 393
 	}
394 394
 	defer os.RemoveAll(tmpdir)
395 395
 	src := filepath.Join(tmpdir, "src")
396
-	if err := system.MkdirAll(src, 0700, ""); err != nil {
396
+	if err := system.MkdirAll(src, 0700); err != nil {
397 397
 		t.Fatal(err)
398 398
 	}
399 399
 	if err := ioutil.WriteFile(filepath.Join(src, "..gitme"), []byte(""), 0644); err != nil {
... ...
@@ -404,7 +404,7 @@ func TestChrootApplyDotDotFile(t *testing.T) {
404 404
 		t.Fatal(err)
405 405
 	}
406 406
 	dest := filepath.Join(tmpdir, "dest")
407
-	if err := system.MkdirAll(dest, 0700, ""); err != nil {
407
+	if err := system.MkdirAll(dest, 0700); err != nil {
408 408
 		t.Fatal(err)
409 409
 	}
410 410
 	if _, err := ApplyLayer(dest, stream); err != nil {
... ...
@@ -113,7 +113,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
113 113
 	// os.MkdirAll on not-Windows and changed for Windows.
114 114
 	if dstDriver.OS() == "windows" {
115 115
 		// Now we are WCOW
116
-		if err := system.MkdirAll(filepath.Dir(dst), 0700, ""); err != nil {
116
+		if err := system.MkdirAll(filepath.Dir(dst), 0700); err != nil {
117 117
 			return err
118 118
 		}
119 119
 	} else {
... ...
@@ -59,7 +59,7 @@ func mkdirAs(path string, mode os.FileMode, owner Identity, mkAll, chownExisting
59 59
 				paths = append(paths, dirPath)
60 60
 			}
61 61
 		}
62
-		if err := system.MkdirAll(path, mode, ""); err != nil {
62
+		if err := system.MkdirAll(path, mode); err != nil {
63 63
 			return err
64 64
 		}
65 65
 	} else {
... ...
@@ -11,7 +11,7 @@ import (
11 11
 // Ownership is handled elsewhere, but in the future could be support here
12 12
 // too.
13 13
 func mkdirAs(path string, mode os.FileMode, owner Identity, mkAll, chownExisting bool) error {
14
-	if err := system.MkdirAll(path, mode, ""); err != nil {
14
+	if err := system.MkdirAll(path, mode); err != nil {
15 15
 		return err
16 16
 	}
17 17
 	return nil
... ...
@@ -37,7 +37,7 @@ func New(path string) (*PIDFile, error) {
37 37
 		return nil, err
38 38
 	}
39 39
 	// Note MkdirAll returns nil if a directory already exists
40
-	if err := system.MkdirAll(filepath.Dir(path), os.FileMode(0755), ""); err != nil {
40
+	if err := system.MkdirAll(filepath.Dir(path), os.FileMode(0755)); err != nil {
41 41
 		return nil, err
42 42
 	}
43 43
 	if err := ioutil.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil {
44 44
deleted file mode 100644
... ...
@@ -1,67 +0,0 @@
1
-// +build !windows
2
-
3
-package system // import "github.com/docker/docker/pkg/system"
4
-
5
-import (
6
-	"io/ioutil"
7
-	"os"
8
-	"path/filepath"
9
-)
10
-
11
-// MkdirAllWithACL is a wrapper for MkdirAll on unix systems.
12
-func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
13
-	return MkdirAll(path, perm, sddl)
14
-}
15
-
16
-// MkdirAll creates a directory named path along with any necessary parents,
17
-// with permission specified by attribute perm for all dir created.
18
-func MkdirAll(path string, perm os.FileMode, sddl string) error {
19
-	return os.MkdirAll(path, perm)
20
-}
21
-
22
-// IsAbs is a platform-specific wrapper for filepath.IsAbs.
23
-func IsAbs(path string) bool {
24
-	return filepath.IsAbs(path)
25
-}
26
-
27
-// The functions below here are wrappers for the equivalents in the os and ioutils packages.
28
-// They are passthrough on Unix platforms, and only relevant on Windows.
29
-
30
-// CreateSequential creates the named file with mode 0666 (before umask), truncating
31
-// it if it already exists. If successful, methods on the returned
32
-// File can be used for I/O; the associated file descriptor has mode
33
-// O_RDWR.
34
-// If there is an error, it will be of type *PathError.
35
-func CreateSequential(name string) (*os.File, error) {
36
-	return os.Create(name)
37
-}
38
-
39
-// OpenSequential opens the named file for reading. If successful, methods on
40
-// the returned file can be used for reading; the associated file
41
-// descriptor has mode O_RDONLY.
42
-// If there is an error, it will be of type *PathError.
43
-func OpenSequential(name string) (*os.File, error) {
44
-	return os.Open(name)
45
-}
46
-
47
-// OpenFileSequential is the generalized open call; most users will use Open
48
-// or Create instead. It opens the named file with specified flag
49
-// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
50
-// methods on the returned File can be used for I/O.
51
-// If there is an error, it will be of type *PathError.
52
-func OpenFileSequential(name string, flag int, perm os.FileMode) (*os.File, error) {
53
-	return os.OpenFile(name, flag, perm)
54
-}
55
-
56
-// TempFileSequential creates a new temporary file in the directory dir
57
-// with a name beginning with prefix, opens the file for reading
58
-// and writing, and returns the resulting *os.File.
59
-// If dir is the empty string, TempFile uses the default directory
60
-// for temporary files (see os.TempDir).
61
-// Multiple programs calling TempFile simultaneously
62
-// will not choose the same file. The caller can use f.Name()
63
-// to find the pathname of the file. It is the caller's responsibility
64
-// to remove the file when no longer needed.
65
-func TempFileSequential(dir, prefix string) (f *os.File, err error) {
66
-	return ioutil.TempFile(dir, prefix)
67
-}
68 1
new file mode 100644
... ...
@@ -0,0 +1,67 @@
0
+// +build !windows
1
+
2
+package system // import "github.com/docker/docker/pkg/system"
3
+
4
+import (
5
+	"io/ioutil"
6
+	"os"
7
+	"path/filepath"
8
+)
9
+
10
+// MkdirAllWithACL is a wrapper for os.MkdirAll on unix systems.
11
+func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
12
+	return os.MkdirAll(path, perm)
13
+}
14
+
15
+// MkdirAll creates a directory named path along with any necessary parents,
16
+// with permission specified by attribute perm for all dir created.
17
+func MkdirAll(path string, perm os.FileMode) error {
18
+	return os.MkdirAll(path, perm)
19
+}
20
+
21
+// IsAbs is a platform-specific wrapper for filepath.IsAbs.
22
+func IsAbs(path string) bool {
23
+	return filepath.IsAbs(path)
24
+}
25
+
26
+// The functions below here are wrappers for the equivalents in the os and ioutils packages.
27
+// They are passthrough on Unix platforms, and only relevant on Windows.
28
+
29
+// CreateSequential creates the named file with mode 0666 (before umask), truncating
30
+// it if it already exists. If successful, methods on the returned
31
+// File can be used for I/O; the associated file descriptor has mode
32
+// O_RDWR.
33
+// If there is an error, it will be of type *PathError.
34
+func CreateSequential(name string) (*os.File, error) {
35
+	return os.Create(name)
36
+}
37
+
38
+// OpenSequential opens the named file for reading. If successful, methods on
39
+// the returned file can be used for reading; the associated file
40
+// descriptor has mode O_RDONLY.
41
+// If there is an error, it will be of type *PathError.
42
+func OpenSequential(name string) (*os.File, error) {
43
+	return os.Open(name)
44
+}
45
+
46
+// OpenFileSequential is the generalized open call; most users will use Open
47
+// or Create instead. It opens the named file with specified flag
48
+// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
49
+// methods on the returned File can be used for I/O.
50
+// If there is an error, it will be of type *PathError.
51
+func OpenFileSequential(name string, flag int, perm os.FileMode) (*os.File, error) {
52
+	return os.OpenFile(name, flag, perm)
53
+}
54
+
55
+// TempFileSequential creates a new temporary file in the directory dir
56
+// with a name beginning with prefix, opens the file for reading
57
+// and writing, and returns the resulting *os.File.
58
+// If dir is the empty string, TempFile uses the default directory
59
+// for temporary files (see os.TempDir).
60
+// Multiple programs calling TempFile simultaneously
61
+// will not choose the same file. The caller can use f.Name()
62
+// to find the pathname of the file. It is the caller's responsibility
63
+// to remove the file when no longer needed.
64
+func TempFileSequential(dir, prefix string) (f *os.File, err error) {
65
+	return ioutil.TempFile(dir, prefix)
66
+}
... ...
@@ -26,9 +26,10 @@ func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
26 26
 	return mkdirall(path, true, sddl)
27 27
 }
28 28
 
29
-// MkdirAll implementation that is volume path aware for Windows.
30
-func MkdirAll(path string, _ os.FileMode, sddl string) error {
31
-	return mkdirall(path, false, sddl)
29
+// MkdirAll implementation that is volume path aware for Windows. It can be used
30
+// as a drop-in replacement for os.MkdirAll()
31
+func MkdirAll(path string, _ os.FileMode) error {
32
+	return mkdirall(path, false, "")
32 33
 }
33 34
 
34 35
 // mkdirall is a custom version of os.MkdirAll modified for use on Windows