From a2cbc028f4a2b24c06c15558dfabb89d9f6e42f0 Mon Sep 17 00:00:00 2001 From: Masaki Kimura Date: Tue, 12 Nov 2019 15:20:47 +0000 Subject: [PATCH] Remove remaining empty file in unmapBindMountDevice --- .../util/volumepathhandler/volume_path_handler.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/volume/util/volumepathhandler/volume_path_handler.go b/pkg/volume/util/volumepathhandler/volume_path_handler.go index 8dbe1a43acd..8d00deaf27a 100644 --- a/pkg/volume/util/volumepathhandler/volume_path_handler.go +++ b/pkg/volume/util/volumepathhandler/volume_path_handler.go @@ -179,7 +179,19 @@ func unmapBindMountDevice(v VolumePathHandler, mapPath string, linkName string) return checkErr } else if !isMountExist { klog.Warningf("Warning: Unmap skipped because bind mount does not exist on the path: %v", linkPath) - // TODO: consider deleting empty file if it exists + + // Check if linkPath still exists + if _, err := os.Stat(linkPath); err != nil { + if !os.IsNotExist(err) { + return fmt.Errorf("failed to check if path %s exists: %v", linkPath, err) + } + // linkPath has already been removed + return nil + } + // Remove file + if err := os.Remove(linkPath); err != nil && !os.IsNotExist(err) { + return fmt.Errorf("failed to remove file %s: %v", linkPath, err) + } return nil }