From 084fe6de9395f043700573dc3b8f490e9d02ee78 Mon Sep 17 00:00:00 2001 From: Di Xu Date: Fri, 31 Aug 2018 19:20:20 +0800 Subject: [PATCH] fix bug on checking hostpath type file --- pkg/volume/hostpath/host_path.go | 6 +++++- pkg/volume/hostpath/host_path_test.go | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/volume/hostpath/host_path.go b/pkg/volume/hostpath/host_path.go index 40dfcaabe7a..3fa56d5c8c2 100644 --- a/pkg/volume/hostpath/host_path.go +++ b/pkg/volume/hostpath/host_path.go @@ -370,7 +370,11 @@ func (ftc *fileTypeChecker) IsFile() bool { if !ftc.Exists() { return false } - return !ftc.IsDir() + pathType, err := ftc.hu.GetFileType(ftc.path) + if err != nil { + return false + } + return string(pathType) == string(v1.HostPathFile) } func (ftc *fileTypeChecker) MakeFile() error { diff --git a/pkg/volume/hostpath/host_path_test.go b/pkg/volume/hostpath/host_path_test.go index 86b5a69a19c..f1b96efd53d 100644 --- a/pkg/volume/hostpath/host_path_test.go +++ b/pkg/volume/hostpath/host_path_test.go @@ -447,7 +447,7 @@ func TestOSFileTypeChecker(t *testing.T) { if oftc.IsDir() { t.Errorf("[%d: %q] expected socket file, got unexpected folder: %s", i, tc.name, path) } - if !oftc.IsFile() { + if oftc.IsFile() { t.Errorf("[%d: %q] expected socket file, got unexpected file: %s", i, tc.name, path) } if oftc.IsBlock() { @@ -465,7 +465,7 @@ func TestOSFileTypeChecker(t *testing.T) { if oftc.IsDir() { t.Errorf("[%d: %q] expected character device, got unexpected folder: %s", i, tc.name, path) } - if !oftc.IsFile() { + if oftc.IsFile() { t.Errorf("[%d: %q] expected character device, got unexpected file: %s", i, tc.name, path) } if oftc.IsSocket() { @@ -483,7 +483,7 @@ func TestOSFileTypeChecker(t *testing.T) { if oftc.IsDir() { t.Errorf("[%d: %q] expected block device, got unexpected folder: %s", i, tc.name, path) } - if !oftc.IsFile() { + if oftc.IsFile() { t.Errorf("[%d: %q] expected block device, got unexpected file: %s", i, tc.name, path) } if oftc.IsSocket() {