Skip to content

Commit 107039a

Browse files
committed
Move MakeFile/Dir from HostUtil to host_path vol
The MakeFile and MakeDir methods in the HostUtil interface only had one caller -- the Host Path volume plugin. This patch relocates MakeFile and MakeDir to the Host Path plugin itself.
1 parent 038e5fa commit 107039a

File tree

5 files changed

+28
-62
lines changed

5 files changed

+28
-62
lines changed

pkg/util/mount/fake_hostutil.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ func (hu *FakeHostUtil) GetFileType(pathname string) (FileType, error) {
7171
return FileType("Directory"), nil
7272
}
7373

74-
// MakeDir creates a new directory.
75-
// No-op for testing
76-
func (hu *FakeHostUtil) MakeDir(pathname string) error {
77-
return nil
78-
}
79-
80-
// MakeFile creates a new file.
81-
// No-op for testing
82-
func (hu *FakeHostUtil) MakeFile(pathname string) error {
83-
return nil
84-
}
85-
8674
// PathExists checks if pathname exists.
8775
func (hu *FakeHostUtil) PathExists(pathname string) (bool, error) {
8876
if _, ok := hu.Filesystem[pathname]; ok {

pkg/util/mount/hostutil.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ type HostUtils interface {
5757
MakeRShared(path string) error
5858
// GetFileType checks for file/directory/socket/block/character devices.
5959
GetFileType(pathname string) (FileType, error)
60-
// MakeFile creates an empty file.
61-
MakeFile(pathname string) error
62-
// MakeDir creates a new directory.
63-
MakeDir(pathname string) error
6460
// PathExists tests if the given path already exists
6561
// Error is returned on any other error than "file not found".
6662
PathExists(pathname string) (bool, error)

pkg/util/mount/hostutil_linux.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,6 @@ func (hu *hostUtil) GetFileType(pathname string) (FileType, error) {
140140
return getFileType(pathname)
141141
}
142142

143-
func (hu *hostUtil) MakeDir(pathname string) error {
144-
err := os.MkdirAll(pathname, os.FileMode(0755))
145-
if err != nil {
146-
if !os.IsExist(err) {
147-
return err
148-
}
149-
}
150-
return nil
151-
}
152-
153-
func (hu *hostUtil) MakeFile(pathname string) error {
154-
f, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0644))
155-
defer f.Close()
156-
if err != nil {
157-
if !os.IsExist(err) {
158-
return err
159-
}
160-
}
161-
return nil
162-
}
163-
164143
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
165144
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
166145
}

pkg/util/mount/hostutil_windows.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,6 @@ func (hu *(hostUtil)) GetFileType(pathname string) (FileType, error) {
9191
return getFileType(pathname)
9292
}
9393

94-
// MakeFile creates a new directory
95-
func (hu *hostUtil) MakeDir(pathname string) error {
96-
err := os.MkdirAll(pathname, os.FileMode(0755))
97-
if err != nil {
98-
if !os.IsExist(err) {
99-
return err
100-
}
101-
}
102-
return nil
103-
}
104-
105-
// MakeFile creates an empty file
106-
func (hu *hostUtil) MakeFile(pathname string) error {
107-
f, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0644))
108-
defer f.Close()
109-
if err != nil {
110-
if !os.IsExist(err) {
111-
return err
112-
}
113-
}
114-
return nil
115-
}
116-
11794
// PathExists checks whether the path exists
11895
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
11996
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)

pkg/volume/hostpath/host_path.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (ftc *fileTypeChecker) IsFile() bool {
377377
}
378378

379379
func (ftc *fileTypeChecker) MakeFile() error {
380-
return ftc.hu.MakeFile(ftc.path)
380+
return makeFile(ftc.path)
381381
}
382382

383383
func (ftc *fileTypeChecker) IsDir() bool {
@@ -392,7 +392,7 @@ func (ftc *fileTypeChecker) IsDir() bool {
392392
}
393393

394394
func (ftc *fileTypeChecker) MakeDir() error {
395-
return ftc.hu.MakeDir(ftc.path)
395+
return makeDir(ftc.path)
396396
}
397397

398398
func (ftc *fileTypeChecker) IsBlock() bool {
@@ -470,3 +470,29 @@ func checkTypeInternal(ftc hostPathTypeChecker, pathType *v1.HostPathType) error
470470

471471
return nil
472472
}
473+
474+
// makeDir creates a new directory.
475+
// If pathname already exists as a directory, no error is returned.
476+
// If pathname already exists as a file, an error is returned.
477+
func makeDir(pathname string) error {
478+
err := os.MkdirAll(pathname, os.FileMode(0755))
479+
if err != nil {
480+
if !os.IsExist(err) {
481+
return err
482+
}
483+
}
484+
return nil
485+
}
486+
487+
// makeFile creates an empty file.
488+
// If pathname already exists, whether a file or directory, no error is returned.
489+
func makeFile(pathname string) error {
490+
f, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0644))
491+
defer f.Close()
492+
if err != nil {
493+
if !os.IsExist(err) {
494+
return err
495+
}
496+
}
497+
return nil
498+
}

0 commit comments

Comments
 (0)