Skip to content

Commit 084fe6d

Browse files
committed
fix bug on checking hostpath type file
1 parent 3f5e09b commit 084fe6d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pkg/volume/hostpath/host_path.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ func (ftc *fileTypeChecker) IsFile() bool {
370370
if !ftc.Exists() {
371371
return false
372372
}
373-
return !ftc.IsDir()
373+
pathType, err := ftc.hu.GetFileType(ftc.path)
374+
if err != nil {
375+
return false
376+
}
377+
return string(pathType) == string(v1.HostPathFile)
374378
}
375379

376380
func (ftc *fileTypeChecker) MakeFile() error {

pkg/volume/hostpath/host_path_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func TestOSFileTypeChecker(t *testing.T) {
447447
if oftc.IsDir() {
448448
t.Errorf("[%d: %q] expected socket file, got unexpected folder: %s", i, tc.name, path)
449449
}
450-
if !oftc.IsFile() {
450+
if oftc.IsFile() {
451451
t.Errorf("[%d: %q] expected socket file, got unexpected file: %s", i, tc.name, path)
452452
}
453453
if oftc.IsBlock() {
@@ -465,7 +465,7 @@ func TestOSFileTypeChecker(t *testing.T) {
465465
if oftc.IsDir() {
466466
t.Errorf("[%d: %q] expected character device, got unexpected folder: %s", i, tc.name, path)
467467
}
468-
if !oftc.IsFile() {
468+
if oftc.IsFile() {
469469
t.Errorf("[%d: %q] expected character device, got unexpected file: %s", i, tc.name, path)
470470
}
471471
if oftc.IsSocket() {
@@ -483,7 +483,7 @@ func TestOSFileTypeChecker(t *testing.T) {
483483
if oftc.IsDir() {
484484
t.Errorf("[%d: %q] expected block device, got unexpected folder: %s", i, tc.name, path)
485485
}
486-
if !oftc.IsFile() {
486+
if oftc.IsFile() {
487487
t.Errorf("[%d: %q] expected block device, got unexpected file: %s", i, tc.name, path)
488488
}
489489
if oftc.IsSocket() {

0 commit comments

Comments
 (0)