Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions proxmox/resource_storage_iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"os"
"path/filepath"
"strings"

pveSDK "github.com/Telmate/proxmox-api-go/proxmox"
Expand Down Expand Up @@ -71,15 +72,25 @@ func resourceStorageIsoCreate(ctx context.Context, d *schema.ResourceData, meta
node := d.Get("pve_node").(string)

client := pconf.Client
file, err := os.CreateTemp(os.TempDir(), fileName)
if err != nil {
return diag.FromErr(err)
}
err = _downloadFile(url, file)
if err != nil {
return diag.FromErr(err)

var file *os.File
var err error
if filepath.IsAbs(url) {
file, err = os.Open(url)
if err != nil {
return diag.FromErr(err)
}
} else {
Comment on lines +78 to +83
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

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

The logic assumes any absolute path is a local file, but HTTP/HTTPS URLs also contain absolute paths (e.g., 'https://example.com/file.iso'). This will cause HTTP URLs to be treated as local file paths. Consider checking if the URL starts with a scheme like 'http://' or 'https://' instead of using filepath.IsAbs().

Copilot uses AI. Check for mistakes.
file, err = os.CreateTemp(os.TempDir(), fileName)
if err != nil {
return diag.FromErr(err)
}
err = _downloadFile(url, file)
if err != nil {
return diag.FromErr(err)
}
file.Seek(0, 0)
Comment on lines +84 to +92
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

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

The temporary file cleanup logic is missing when _downloadFile fails. If the download fails, the temporary file created by os.CreateTemp will not be cleaned up, potentially leaving orphaned files in the temp directory. Consider adding proper cleanup with defer os.Remove(file.Name()) after successful temp file creation.

Copilot uses AI. Check for mistakes.
}
file.Seek(0, 0)
defer file.Close()
err = client.Upload(ctx, node, storage, isoContentType, fileName, file)
if err != nil {
Expand Down