Skip to content

[APIM] Fix file path issue#1353

Open
DDH13 wants to merge 1 commit intowso2:masterfrom
DDH13:master.4963
Open

[APIM] Fix file path issue#1353
DDH13 wants to merge 1 commit intowso2:masterfrom
DDH13:master.4963

Conversation

@DDH13
Copy link
Copy Markdown

@DDH13 DDH13 commented Apr 25, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

📝 Walkthrough

Walkthrough

The changes address cross-platform path handling in import-export functionality. In importAPIPolicy.go, the policyName extraction now uses filepath.Base() instead of hardcoded forward-slash splitting. In fileIOUtils.go, CreateZipFileFromProject now explicitly closes the temporary file before zipping and uses the captured tmpPath instead of tmp.Name() for consistency. Both changes improve platform independence and resource management without altering the core import-export workflow.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides only an issue link with minimal context and is missing most required sections from the template (Purpose, Goals, Approach, User stories, Release notes, Documentation, etc.). Expand the description to include Purpose, Goals, and Approach sections that explain the file path issue being fixed and how it was resolved.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title '[APIM] Fix file path issue' is directly related to the changeset, which addresses file path handling in API import functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
import-export-cli/utils/fileIOUtils.go (1)

416-420: Consider removing the temp file if tmp.Close() fails.

ioutil.TempFile has already created the file on disk by the time Close() is called. If Close() returns an error, the function exits without invoking the cleanup path, leaving the temp file behind. A best-effort os.Remove(tmpPath) on the error branch would keep cleanup symmetric.

♻️ Proposed adjustment
 		// Read the filename and close the file to avoid file locking in windows
 		tmpPath := tmp.Name()
 		if err := tmp.Close(); err != nil {
+			_ = os.Remove(tmpPath)
 			return "", err, nil
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@import-export-cli/utils/fileIOUtils.go` around lines 416 - 420, When
tmp.Close() fails after creating the temp file (created via ioutil.TempFile),
ensure the temp file is removed on the error path: call os.Remove(tmpPath)
(best-effort, ignore its error) before returning the close error so the temp
file is not left behind; update the error branch that currently returns "", err,
nil to first attempt os.Remove(tmpPath) and then return the original error.
import-export-cli/impl/importAPIPolicy.go (1)

82-94: Use filepath.Join for originalFilePath to stay consistent with the cross-platform fix.

Line 83 still concatenates with a hardcoded "/". While filepath.Ext happens to tolerate this, the path construction is inconsistent with the platform-independent change just made above and could trip up future readers or any added path operations.

♻️ Proposed adjustment
 	for _, file := range files {
-		originalFilePath := tmpPath + "/" + file.Name()
+		originalFilePath := filepath.Join(tmpPath, file.Name())
 		ext := filepath.Ext(originalFilePath)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@import-export-cli/impl/importAPIPolicy.go` around lines 82 - 94, The path for
originalFilePath is built with string concatenation which is not cross-platform;
in the loop in importAPIPolicy.go (the code that constructs originalFilePath and
computes ext), replace the string join of tmpPath + "/" + file.Name() with
filepath.Join(tmpPath, file.Name()) so path handling is consistent with other
uses of filepath; update any related variable references (originalFilePath and
ext calculation using filepath.Ext(originalFilePath)) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@import-export-cli/impl/importAPIPolicy.go`:
- Around line 82-94: The path for originalFilePath is built with string
concatenation which is not cross-platform; in the loop in importAPIPolicy.go
(the code that constructs originalFilePath and computes ext), replace the string
join of tmpPath + "/" + file.Name() with filepath.Join(tmpPath, file.Name()) so
path handling is consistent with other uses of filepath; update any related
variable references (originalFilePath and ext calculation using
filepath.Ext(originalFilePath)) accordingly.

In `@import-export-cli/utils/fileIOUtils.go`:
- Around line 416-420: When tmp.Close() fails after creating the temp file
(created via ioutil.TempFile), ensure the temp file is removed on the error
path: call os.Remove(tmpPath) (best-effort, ignore its error) before returning
the close error so the temp file is not left behind; update the error branch
that currently returns "", err, nil to first attempt os.Remove(tmpPath) and then
return the original error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44a273d5-1fd8-456d-88f9-a4d763a557d7

📥 Commits

Reviewing files that changed from the base of the PR and between 2bfb9d8 and 1082a8a.

📒 Files selected for processing (2)
  • import-export-cli/impl/importAPIPolicy.go
  • import-export-cli/utils/fileIOUtils.go

@DDH13 DDH13 changed the title [APIM 4.2.0] Fix file path issue [APIM] Fix file path issue Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant