From 8dc9cbce601dff8709f57ed07dac0ad63f7c6445 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 17 Dec 2024 16:03:00 +0000 Subject: [PATCH] actions: filesystem-deploy: Defer Close() call on file handles Make use of defer when closing file handles. Signed-off-by: Christopher Obbard --- actions/filesystem_deploy_action.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/filesystem_deploy_action.go b/actions/filesystem_deploy_action.go index a03879b..bbcf8cd 100644 --- a/actions/filesystem_deploy_action.go +++ b/actions/filesystem_deploy_action.go @@ -68,6 +68,7 @@ func (fd *FilesystemDeployAction) setupFSTab(context *debos.DebosContext) error fstab := path.Join(context.Rootdir, "etc/fstab") f, err := os.OpenFile(fstab, os.O_RDWR|os.O_CREATE, 0755) + defer f.Close() if err != nil { return fmt.Errorf("Couldn't open /etc/fstab: %v", err) @@ -78,7 +79,6 @@ func (fd *FilesystemDeployAction) setupFSTab(context *debos.DebosContext) error if err != nil { return fmt.Errorf("Couldn't write /etc/fstab: %v", err) } - f.Close() return nil } @@ -95,6 +95,7 @@ func (fd *FilesystemDeployAction) setupKernelCmdline(context *debos.DebosContext path := path.Join(context.Rootdir, "etc/kernel/cmdline") current, _ := ioutil.ReadFile(path) f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0755) + defer f.Close() if err != nil { log.Fatalf("Couldn't open /etc/kernel/cmdline: %v", err) @@ -112,7 +113,6 @@ func (fd *FilesystemDeployAction) setupKernelCmdline(context *debos.DebosContext return fmt.Errorf("Couldn't write /etc/kernel/cmdline: %v", err) } - f.Close() return nil }