kubelet: remove superfluous function

the ensureDirectory seems to be just a wrapper around MkdirAll.

Since MkdirAll doesn't treat an existing directory as an error, there is no need of the extra stat() syscall that was previously performed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2022-07-18 17:08:27 +02:00
parent 5108b0a3a0
commit 705242e2af
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772

View File

@ -41,7 +41,7 @@ type FileStore struct {
// NewFileStore returns an instance of FileStore.
func NewFileStore(path string, fs utilfs.Filesystem) (Store, error) {
if err := ensureDirectory(fs, path); err != nil {
if err := fs.MkdirAll(path, 0755); err != nil {
return nil, err
}
return &FileStore{directoryPath: path, filesystem: fs}, nil
@ -52,7 +52,7 @@ func (f *FileStore) Write(key string, data []byte) error {
if err := ValidateKey(key); err != nil {
return err
}
if err := ensureDirectory(f.filesystem, f.directoryPath); err != nil {
if err := f.filesystem.MkdirAll(f.directoryPath, 0755); err != nil {
return err
}
@ -99,15 +99,6 @@ func (f *FileStore) getPathByKey(key string) string {
return filepath.Join(f.directoryPath, key)
}
// ensureDirectory creates the directory if it does not exist.
func ensureDirectory(fs utilfs.Filesystem, path string) error {
if _, err := fs.Stat(path); err != nil {
// MkdirAll returns nil if directory already exists.
return fs.MkdirAll(path, 0755)
}
return nil
}
// writeFile writes data to path in a single transaction.
func writeFile(fs utilfs.Filesystem, path string, data []byte) (retErr error) {
// Create a temporary file in the base directory of `path` with a prefix.