From 1082a8a38852273e32d9236af0fcd7b2e5c6e1d7 Mon Sep 17 00:00:00 2001 From: Dineth Date: Sat, 25 Apr 2026 11:57:49 +0530 Subject: [PATCH] Fix file path issue --- import-export-cli/impl/importAPIPolicy.go | 4 ++-- import-export-cli/utils/fileIOUtils.go | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/import-export-cli/impl/importAPIPolicy.go b/import-export-cli/impl/importAPIPolicy.go index a78b565b0..3ac2314f5 100644 --- a/import-export-cli/impl/importAPIPolicy.go +++ b/import-export-cli/impl/importAPIPolicy.go @@ -76,8 +76,8 @@ func importAPIPolicy(endpoint string, importPath string, accessToken string, isO return err } - policyPaths := strings.Split(tmpPath, "/") - policyName := policyPaths[len(policyPaths)-1] + // Make the file name platform independent + policyName := filepath.Base(tmpPath) for _, file := range files { originalFilePath := tmpPath + "/" + file.Name() diff --git a/import-export-cli/utils/fileIOUtils.go b/import-export-cli/utils/fileIOUtils.go index 0e63d188e..246678c24 100644 --- a/import-export-cli/utils/fileIOUtils.go +++ b/import-export-cli/utils/fileIOUtils.go @@ -413,24 +413,29 @@ func CreateZipFileFromProject(projectPath string, skipCleanup bool) (string, err if err != nil { return "", err, nil } - Logln(LogPrefixInfo+"Creating the project artifact", tmp.Name()) - err = Zip(projectPath, tmp.Name()) + // Read the filename and close the file to avoid file locking in windows + tmpPath := tmp.Name() + if err := tmp.Close(); err != nil { + return "", err, nil + } + Logln(LogPrefixInfo+"Creating the project artifact", tmpPath) + err = Zip(projectPath, tmpPath) if err != nil { return "", err, nil } //creates a function to cleanup the temporary folders cleanup := func() { if skipCleanup { - Logln(LogPrefixInfo+"Leaving", tmp.Name()) + Logln(LogPrefixInfo+"Leaving", tmpPath) return } - Logln(LogPrefixInfo+"Deleting", tmp.Name()) - err := os.Remove(tmp.Name()) + Logln(LogPrefixInfo+"Deleting", tmpPath) + err := os.Remove(tmpPath) if err != nil { Logln(LogPrefixError + err.Error()) } } - projectPath = tmp.Name() + projectPath = tmpPath return projectPath, nil, cleanup } return projectPath, nil, nil