diff --git a/import-export-cli/impl/importAPIPolicy.go b/import-export-cli/impl/importAPIPolicy.go index a78b565b..3ac2314f 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 0e63d188..246678c2 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