Skip to content

fix: normalize Windows backslash paths to forward slashes in image upload#362

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/fix-image-upload-path-issue
Draft

fix: normalize Windows backslash paths to forward slashes in image upload#362
Copilot wants to merge 1 commit intomainfrom
copilot/fix-image-upload-path-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Summary

Fixes #361

On Windows, when uploading an image via source_image_path or cd_files, the full Windows path (in 8.3 notation, e.g. C:\USERS\J81BLO~1\image.iso) was appearing as the image name in Prism Central instead of just the filename.

Root cause

There were two related issues in driver.go:

  1. CreateImageURLpath.Split(disk.SourceImageURI) only recognises / as a path separator. Any URI that contains Windows-style backslashes (e.g. file:///C:\path\image.iso) would have the full path returned as the "filename".

  2. CreateImageFilefilepath.Split(filePath) is OS-specific and correctly handles \ on a Windows binary. However, the raw filePath (with backslashes) was then forwarded to the SDK's Images.Upload. The SDK derives the image name internally via filepath.Base(sourcePath). On Linux builds (cross-compiled binaries, WSL, MSYS2, Git Bash), filepath.Base does not recognise \ as a separator and returns the entire path as the filename — causing the full Windows path to become the image name in Prism Central.

Fix

Normalize all backslash separators to forward slashes before any path extraction or SDK call:

  • CreateImageURL: replace path.Split(disk.SourceImageURI) with path.Base(strings.ReplaceAll(…, "\\", "/")).
  • CreateImageFile: compute normalizedPath with strings.ReplaceAll(filePath, "\\", "/"), extract file using path.Base(normalizedPath), and pass normalizedPath to v4Client.Images.Upload so the SDK's internal filepath.Base call also produces the correct basename. Windows accepts / as a path separator in all standard file-open calls, so os.Open continues to work correctly.
  • Remove the now-unused path/filepath import.

Testing

  • go build ./... and go test ./... pass cleanly.
  • The fix is backward-compatible: Linux paths never contain \, so strings.ReplaceAll is a no-op for them.

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.

Name of iso without full path as image name

2 participants