Merge pull request #81739 from codenrhoden/clarify-mkdir-mkfile-behavior

Move MakeFile/Dir from HostUtil to host_path vol
This commit is contained in:
Kubernetes Prow Robot
2019-08-27 00:53:24 -07:00
committed by GitHub
5 changed files with 28 additions and 62 deletions

View File

@@ -377,7 +377,7 @@ func (ftc *fileTypeChecker) IsFile() bool {
}
func (ftc *fileTypeChecker) MakeFile() error {
return ftc.hu.MakeFile(ftc.path)
return makeFile(ftc.path)
}
func (ftc *fileTypeChecker) IsDir() bool {
@@ -392,7 +392,7 @@ func (ftc *fileTypeChecker) IsDir() bool {
}
func (ftc *fileTypeChecker) MakeDir() error {
return ftc.hu.MakeDir(ftc.path)
return makeDir(ftc.path)
}
func (ftc *fileTypeChecker) IsBlock() bool {
@@ -470,3 +470,29 @@ func checkTypeInternal(ftc hostPathTypeChecker, pathType *v1.HostPathType) error
return nil
}
// makeDir creates a new directory.
// If pathname already exists as a directory, no error is returned.
// If pathname already exists as a file, an error is returned.
func makeDir(pathname string) error {
err := os.MkdirAll(pathname, os.FileMode(0755))
if err != nil {
if !os.IsExist(err) {
return err
}
}
return nil
}
// makeFile creates an empty file.
// If pathname already exists, whether a file or directory, no error is returned.
func makeFile(pathname string) error {
f, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0644))
defer f.Close()
if err != nil {
if !os.IsExist(err) {
return err
}
}
return nil
}