mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #81739 from codenrhoden/clarify-mkdir-mkfile-behavior
Move MakeFile/Dir from HostUtil to host_path vol
This commit is contained in:
commit
bc46e8fc53
@ -71,18 +71,6 @@ func (hu *FakeHostUtil) GetFileType(pathname string) (FileType, error) {
|
|||||||
return FileType("Directory"), nil
|
return FileType("Directory"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeDir creates a new directory.
|
|
||||||
// No-op for testing
|
|
||||||
func (hu *FakeHostUtil) MakeDir(pathname string) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MakeFile creates a new file.
|
|
||||||
// No-op for testing
|
|
||||||
func (hu *FakeHostUtil) MakeFile(pathname string) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// PathExists checks if pathname exists.
|
// PathExists checks if pathname exists.
|
||||||
func (hu *FakeHostUtil) PathExists(pathname string) (bool, error) {
|
func (hu *FakeHostUtil) PathExists(pathname string) (bool, error) {
|
||||||
if _, ok := hu.Filesystem[pathname]; ok {
|
if _, ok := hu.Filesystem[pathname]; ok {
|
||||||
|
@ -57,10 +57,6 @@ type HostUtils interface {
|
|||||||
MakeRShared(path string) error
|
MakeRShared(path string) error
|
||||||
// GetFileType checks for file/directory/socket/block/character devices.
|
// GetFileType checks for file/directory/socket/block/character devices.
|
||||||
GetFileType(pathname string) (FileType, error)
|
GetFileType(pathname string) (FileType, error)
|
||||||
// MakeFile creates an empty file.
|
|
||||||
MakeFile(pathname string) error
|
|
||||||
// MakeDir creates a new directory.
|
|
||||||
MakeDir(pathname string) error
|
|
||||||
// PathExists tests if the given path already exists
|
// PathExists tests if the given path already exists
|
||||||
// Error is returned on any other error than "file not found".
|
// Error is returned on any other error than "file not found".
|
||||||
PathExists(pathname string) (bool, error)
|
PathExists(pathname string) (bool, error)
|
||||||
|
@ -140,27 +140,6 @@ func (hu *hostUtil) GetFileType(pathname string) (FileType, error) {
|
|||||||
return getFileType(pathname)
|
return getFileType(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hu *hostUtil) MakeDir(pathname string) error {
|
|
||||||
err := os.MkdirAll(pathname, os.FileMode(0755))
|
|
||||||
if err != nil {
|
|
||||||
if !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hu *hostUtil) 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
||||||
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
||||||
}
|
}
|
||||||
|
@ -91,29 +91,6 @@ func (hu *(hostUtil)) GetFileType(pathname string) (FileType, error) {
|
|||||||
return getFileType(pathname)
|
return getFileType(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeFile creates a new directory
|
|
||||||
func (hu *hostUtil) 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
|
|
||||||
func (hu *hostUtil) 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// PathExists checks whether the path exists
|
// PathExists checks whether the path exists
|
||||||
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
||||||
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
||||||
|
@ -377,7 +377,7 @@ func (ftc *fileTypeChecker) IsFile() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ftc *fileTypeChecker) MakeFile() error {
|
func (ftc *fileTypeChecker) MakeFile() error {
|
||||||
return ftc.hu.MakeFile(ftc.path)
|
return makeFile(ftc.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ftc *fileTypeChecker) IsDir() bool {
|
func (ftc *fileTypeChecker) IsDir() bool {
|
||||||
@ -392,7 +392,7 @@ func (ftc *fileTypeChecker) IsDir() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ftc *fileTypeChecker) MakeDir() error {
|
func (ftc *fileTypeChecker) MakeDir() error {
|
||||||
return ftc.hu.MakeDir(ftc.path)
|
return makeDir(ftc.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ftc *fileTypeChecker) IsBlock() bool {
|
func (ftc *fileTypeChecker) IsBlock() bool {
|
||||||
@ -470,3 +470,29 @@ func checkTypeInternal(ftc hostPathTypeChecker, pathType *v1.HostPathType) error
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user