From 40b82c474c7110e4fcc3ea71c87dcfb045e29336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TD=E5=8C=97=E5=B2=B8=E8=8A=B1=E5=9B=AD?= Date: Wed, 26 Nov 2025 09:20:39 +0800 Subject: [PATCH] clearing concurrency risks for temporary files in fixed paths --- cmd/deploy.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index 48b3fbb2..c8927fdd 100755 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -433,7 +433,14 @@ func applyNetworkPlugin(pluginConfigPath string, isNestOS bool) error { } // Save the modified content to a file in the "/tmp" directory with a fixed name - tmpFilePath := "/tmp/modified-plugin-config.yaml" + tmpFile, err := os.CreateTemp("", "modified-plugin-config-*.yaml") + if err != nil { + logrus.Errorf("Failed to create temp file: %v", err) + } + defer os.Remove(tmpFile.Name()) + defer tmpFile.Close() + + tmpFilePath := tmpFile.Name() err = utils.AtomicWriteFile(tmpFilePath, content, utils.CertFileMode) if err != nil { @@ -447,13 +454,6 @@ func applyNetworkPlugin(pluginConfigPath string, isNestOS bool) error { return err } - // removal of the temporary file - defer func() { - if err := os.Remove(tmpFilePath); err != nil { - logrus.Errorf("Failed to remove temporary file: %v", err) - } - }() - return nil } -- Gitee